Class: TestRunner::Cli::Command
- Inherits:
-
OsCtl::Lib::Cli::Command
- Object
- OsCtl::Lib::Cli::Command
- TestRunner::Cli::Command
- Defined in:
- lib/test-runner/cli/command.rb
Class Method Summary collapse
Instance Method Summary collapse
- #debug ⇒ Object
- #jobs_auto? ⇒ Boolean protected
- #list ⇒ Object
- #load_extensions ⇒ Object protected
- #original_repo_root ⇒ Object protected
- #repo_root ⇒ Object protected
- #select_test_scripts(pattern) ⇒ Array<TestScript> protected
- #state_dir ⇒ Object protected
- #test ⇒ Object
- #test_config_path ⇒ Object protected
- #test_jobs(test_scripts) ⇒ Object protected
- #with_repository_environment(source_path) ⇒ Object protected
- #with_repository_source ⇒ Object protected
Class Method Details
.run(method) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/test-runner/cli/command.rb', line 5 def self.run(method) proc do |global_opts, opts, args| cmd = new(global_opts, opts, args) cmd.send(:with_repository_source) do cmd.send(:load_extensions) cmd.method(method).call end end end |
Instance Method Details
#debug ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/test-runner/cli/command.rb', line 62 def debug require_args!('test') tsl = TestRunner::TestScriptList.new(system: opts['system'], test_config_path:, repo_root:) test_script = tsl.by_path(args[0]) ev = TestRunner::TestEvaluator.new( test_script.test, [test_script], system: opts['system'], test_config_path:, repo_root:, state_dir: File.join(state_dir, "os-test-#{test_script.test.name}"), sock_dir: File.join(state_dir, 'socks'), default_timeout: opts['timeout'], destructive: false ) ev.interactive end |
#jobs_auto? ⇒ Boolean (protected)
93 94 95 |
# File 'lib/test-runner/cli/command.rb', line 93 def jobs_auto? opts['jobs'].to_s == 'auto' end |
#list ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/test-runner/cli/command.rb', line 15 def list test_scripts = select_test_scripts(args[0]) test_scripts.each do |ts| puts ts.path end end |
#load_extensions ⇒ Object (protected)
153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/test-runner/cli/command.rb', line 153 def load_extensions return if @extensions_loaded @extensions_loaded = true ext_dir = File.join(original_repo_root, 'tests', 'runner', 'extensions') return unless Dir.exist?(ext_dir) Dir[File.join(ext_dir, '*.rb')].each do |file| load(file) end end |
#original_repo_root ⇒ Object (protected)
126 127 128 |
# File 'lib/test-runner/cli/command.rb', line 126 def original_repo_root @original_repo_root ||= File.(ENV['TEST_RUNNER_REPO_ROOT'] || Dir.pwd) end |
#repo_root ⇒ Object (protected)
130 131 132 |
# File 'lib/test-runner/cli/command.rb', line 130 def repo_root @repository_source&.path || original_repo_root end |
#select_test_scripts(pattern) ⇒ Array<TestScript> (protected)
98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/test-runner/cli/command.rb', line 98 def select_test_scripts(pattern) tsl = TestRunner::TestScriptList.new(system: opts['system'], test_config_path:, repo_root:) attr_filters = Cli::LabelFilters.new(opts['label']) tag_filters = Cli::TagFilters.new(opts['tag']) expr_filters = Array(opts['filter']).map { |expr| Cli::FilterExpression.new(expr) } tsl.filter do |ts| (pattern.nil? || ts.path_matches?(pattern)) \ && attr_filters.pass?(ts) \ && tag_filters.pass?(ts) \ && expr_filters.all? { |expr| expr.pass?(ts) } end end |
#state_dir ⇒ Object (protected)
113 114 115 |
# File 'lib/test-runner/cli/command.rb', line 113 def state_dir File.join(opts['state-dir'] || File.join(ENV['TMPDIR'] || '/tmp', 'os-test-runner')) end |
#test ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/test-runner/cli/command.rb', line 23 def test test_scripts = select_test_scripts(args[0]) puts 'The following test scripts will be run:' test_scripts.each { |t| puts " #{t.path}" } puts exec = TestRunner::Executor.new( test_scripts, state_dir:, jobs: test_jobs(test_scripts), jobs_auto: jobs_auto?, max_memory_mib: opts['max-memory-mib'], max_shm_mib: opts['max-shm-mib'], max_cpus: opts['max-cpus'], memory_reserve_mib: opts['memory-reserve-mib'], shm_reserve_mib: opts['shm-reserve-mib'], cpu_reserve: opts['cpu-reserve'], memory_overcommit: opts['memory-overcommit'], shm_overcommit: opts['shm-overcommit'], cpu_overcommit: opts['cpu-overcommit'], resource_refresh_interval: opts['resource-refresh-interval'], status_interval: opts['status-interval'], verbose: opts['verbose'], default_timeout: opts['timeout'], stop_on_failure: opts['stop-on-failure'], destructive: opts['destructive'], recreate_disks: opts['fresh'], system: opts['system'], test_config_path:, repo_root: ) results = exec.run return unless results.detect(&:unexpected_result?) raise 'one or more tests did not have expected results' end |
#test_config_path ⇒ Object (protected)
134 135 136 137 138 |
# File 'lib/test-runner/cli/command.rb', line 134 def test_config_path return opts['test-config'] unless @repository_source @repository_source.resolve_path(opts['test-config']) end |
#test_jobs(test_scripts) ⇒ Object (protected)
84 85 86 87 88 89 90 91 |
# File 'lib/test-runner/cli/command.rb', line 84 def test_jobs(test_scripts) return test_scripts.map(&:test).uniq.length if jobs_auto? ret = Integer(opts['jobs']) raise 'jobs must be positive' if ret <= 0 ret end |
#with_repository_environment(source_path) ⇒ Object (protected)
140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/test-runner/cli/command.rb', line 140 def with_repository_environment(source_path) original_env = ENV.fetch('TEST_RUNNER_REPO_ROOT', nil) ENV['TEST_RUNNER_REPO_ROOT'] = source_path yield ensure if original_env.nil? ENV.delete('TEST_RUNNER_REPO_ROOT') else ENV['TEST_RUNNER_REPO_ROOT'] = original_env end end |
#with_repository_source ⇒ Object (protected)
117 118 119 120 121 122 123 124 |
# File 'lib/test-runner/cli/command.rb', line 117 def with_repository_source(&) RepositorySource.open(original_path: original_repo_root) do |source| @repository_source = source with_repository_environment(source.path, &) ensure @repository_source = nil end end |