Class: Megatest::CLI
- Inherits:
-
Object
- Object
- Megatest::CLI
- Defined in:
- lib/megatest/cli.rb
Constant Summary collapse
- InvalidArgument =
Class.new(ArgumentError)
- RUNNERS =
{ "report" => :report, "run" => :run, }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #configure ⇒ Object
-
#initialize(program_name, out, err, argv, env) ⇒ CLI
constructor
A new instance of CLI.
- #report ⇒ Object
- #run ⇒ Object
- #run_tests ⇒ Object
Constructor Details
#initialize(program_name, out, err, argv, env) ⇒ CLI
Returns a new instance of CLI.
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/megatest/cli.rb', line 35 def initialize(program_name, out, err, argv, env) @out = out @err = err @argv = argv.dup @processes = nil @config = Config.new(env) @program_name = @config.program_name = program_name @runner = nil @verbose = false @junit = false end |
Class Method Details
.run! ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/megatest/cli.rb', line 12 def run! program_name = $PROGRAM_NAME if paths = ENV["PATH"] paths.split(":").each do |path| if program_name.start_with?(path) program_name = program_name.delete_prefix(path) program_name = program_name.delete_prefix("/") break end end end exit(new(program_name, $stdout, $stderr, ARGV, ENV).run) end |
Instance Method Details
#configure ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/megatest/cli.rb', line 68 def configure if @runner = RUNNERS[@argv.first] @argv.shift end Megatest.config = @config @parser = build_parser(@runner) @parser.parse!(@argv) @argv.shift if @argv.first == "--" @config end |
#report ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/megatest/cli.rb', line 107 def report queue = @config.build_queue raise InvalidArgument, "Only distributed queues can be summarized" unless queue.distributed? raise InvalidArgument, "Distributed queues require a build-id" unless @config.build_id raise InvalidArgument, @argv.join(" ") unless @argv.empty? Megatest.load_config(@argv) QueueReporter.new(@config, queue, @out).run(default_reporters) ? 0 : 1 end |
#run ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/megatest/cli.rb', line 47 def run configure case @runner when :report report when nil, :run run_tests else raise InvalidArgument, "Parsing failure" end rescue InvalidArgument, OptionParser::ParseError => error if error.is_a?(InvalidArgument) @err.puts "invalid arguments: #{error.}" else @err.puts error. end @err.puts @err.puts @parser 1 end |
#run_tests ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/megatest/cli.rb', line 80 def run_tests queue = @config.build_queue if queue.distributed? raise InvalidArgument, "Distributed queues require a build-id" unless @config.build_id raise InvalidArgument, "Distributed queues require a worker-id" unless @config.worker_id elsif queue.sharded? unless @config.valid_worker_index? raise InvalidArgument, "Splitting the queue requires a worker-id lower than workers-count, got: #{@config.worker_id.inspect}" end end @config.selectors = Selector.parse(@argv) Megatest.load_config(@config) Megatest.init(@config) test_cases = Megatest.load_tests(@config) if test_cases.empty? @err.puts "No tests to run" return 1 end queue.populate(test_cases) executor.run(queue, default_reporters) queue.success? ? 0 : 1 end |