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
- #select_test_scripts(pattern) ⇒ Array<TestScript> protected
- #state_dir ⇒ Object protected
- #test ⇒ Object
- #test_jobs(test_scripts) ⇒ Object protected
Class Method Details
.run(method) ⇒ Object
5 6 7 8 9 10 11 |
# 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(:load_extensions) cmd.method(method).call end end |
Instance Method Details
#debug ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/test-runner/cli/command.rb', line 57 def debug require_args!('test') tsl = TestRunner::TestScriptList.new(system: opts['system'], test_config_path: opts['test-config']) test_script = tsl.by_path(args[0]) ev = TestRunner::TestEvaluator.new( test_script.test, [test_script], system: opts['system'], test_config_path: opts['test-config'], 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)
87 88 89 |
# File 'lib/test-runner/cli/command.rb', line 87 def jobs_auto? opts['jobs'].to_s == 'auto' end |
#list ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/test-runner/cli/command.rb', line 13 def list test_scripts = select_test_scripts(args[0]) test_scripts.each do |ts| puts ts.path end end |
#load_extensions ⇒ Object (protected)
111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/test-runner/cli/command.rb', line 111 def load_extensions return if @extensions_loaded @extensions_loaded = true ext_dir = File.(File.join('tests', 'runner', 'extensions'), Dir.pwd) return unless Dir.exist?(ext_dir) Dir[File.join(ext_dir, '*.rb')].each do |file| load(file) end end |
#select_test_scripts(pattern) ⇒ Array<TestScript> (protected)
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/test-runner/cli/command.rb', line 92 def select_test_scripts(pattern) tsl = TestRunner::TestScriptList.new(system: opts['system'], test_config_path: opts['test-config']) 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)
107 108 109 |
# File 'lib/test-runner/cli/command.rb', line 107 def state_dir File.join(opts['state-dir'] || File.join(ENV['TMPDIR'] || '/tmp', 'os-test-runner')) end |
#test ⇒ Object
21 22 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 |
# File 'lib/test-runner/cli/command.rb', line 21 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'], default_timeout: opts['timeout'], stop_on_failure: opts['stop-on-failure'], destructive: opts['destructive'], recreate_disks: opts['fresh'], system: opts['system'], test_config_path: opts['test-config'] ) results = exec.run return unless results.detect(&:unexpected_result?) raise 'one or more tests did not have expected results' end |
#test_jobs(test_scripts) ⇒ Object (protected)
78 79 80 81 82 83 84 85 |
# File 'lib/test-runner/cli/command.rb', line 78 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 |