Class: TurboTests::CLI
- Inherits:
-
Object
- Object
- TurboTests::CLI
- Defined in:
- lib/turbo_tests/cli.rb
Instance Method Summary collapse
-
#initialize(argv) ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
Constructor Details
#initialize(argv) ⇒ CLI
Returns a new instance of CLI.
7 8 9 |
# File 'lib/turbo_tests/cli.rb', line 7 def initialize(argv) @argv = argv end |
Instance Method Details
#run ⇒ Object
11 12 13 14 15 16 17 18 19 20 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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/turbo_tests/cli.rb', line 11 def run handle_shim_command if shim_command? handle_fan_command if fan_command? requires = [] formatters = [] = [] count = nil runtime_log = nil example_status_log = nil verbose = false fail_fast = nil seed = nil order = nil print_failed_group = false create = false nice = false worker_output = nil = {} cli_args, parallel_args = split_parallel_args(@argv) OptionParser.new do |opts| opts. = <<~BANNER Run RSpec files in parallel, giving each process ENV['TEST_ENV_NUMBER'] ('1', '2', '3', ...). Uses `parallel_tests` to split files into groups, then reports RSpec results incrementally. Source code of `turbo_tests2` gem is based on Discourse and RubyGems work in this area (see README file of the source repository). Usage: turbo_tests2 [options] [optional] Only selected files & folders: turbo_tests2 spec/bar spec/baz/xxx_spec.rb Options: BANNER opts.on( "-n [PROCESSES]", "--count [PROCESSES]", Integer, "How many processes to use, default: available CPUs" ) do |n| count = n end opts.on("-w [PROCESSES]", "--workers [PROCESSES]", Integer, "Alias for -n, --count") do |n| count = n end opts.on("-r", "--require PATH", "Require a file.") do |filename| requires << filename end opts.on( "-f", "--format FORMATTER", "Choose a formatter. Available formatters: progress (p), documentation (d). Default: progress" ) do |name| formatters << { name: name, outputs: [] } end opts.on("-t", "--tag TAG", "Run examples with the specified tag.") do |tag| << tag end opts.on("-o", "--out FILE", "Write output to a file instead of $stdout") do |filename| if formatters.empty? formatters << { name: "progress", outputs: [] } end formatters.last[:outputs] << filename end opts.on("--runtime-log FILE", "Location of previously recorded test runtimes") do |filename| runtime_log = filename end opts.on("--example-status-log FILE", "Use RSpec example status persistence timings for grouping") do |filename| example_status_log = filename end opts.on("--pattern PATTERN", "Run spec files matching this regex pattern") do |pattern| [:pattern] = compile_pattern(pattern) end opts.on("--exclude-pattern PATTERN", "Exclude spec files matching this regex pattern") do |pattern| [:exclude_pattern] = compile_pattern(pattern) end opts.on("--only-group GROUP_INDEX[,GROUP_INDEX]", "Run only the selected 1-based parallel_tests group index(es)") do |groups| [:only_group] = parse_only_groups(groups) end opts.on("--group-by MODE", "Group files by runtime, filesize, or found order") do |mode| [:group_by] = parse_group_by(mode) end opts.on("--allowed-missing PERCENT", Integer, "Allowed percentage of missing runtimes for runtime grouping") do |percent| [:allowed_missing_percent] = parse_allowed_missing(percent) end opts.on("--unknown-runtime SECONDS", Float, "Runtime in seconds to assign files missing runtime history") do |seconds| [:unknown_runtime] = parse_unknown_runtime(seconds) end opts.on("-v", "--verbose", "More output") do verbose = true end opts.on( "--worker-output MODE", "Raw worker output mode: warnings, stream, buffered, or quiet; env: TURBO_TESTS2_WORKER_OUTPUT" ) do |mode| worker_output = mode end opts.on("--fail-fast=[N]") do |n| n = begin Integer(n) rescue nil end fail_fast = (n.nil? || n < 1) ? 1 : n end opts.on("--seed SEED", "Seed for RSpec") do |s| seed = s end opts.on("--order ORDER", "RSpec example order: random (default) or defined") do |value| order = value end opts.on("--no-random", "Run examples in defined order without passing a seed") do order = "defined" end opts.on("--create", "Create databases") do create = true end opts.on("--print_failed_group", "Prints group that had failures in it") do print_failed_group = true end opts.on("--nice", "execute test commands with low priority") do nice = true end end.parse!(cli_args) parse_parallel_args(parallel_args, ) unless parallel_args.empty? if create return TurboTests::Runner.create(count) end requires.each { |f| require(f) } if formatters.empty? formatters << { name: "progress", outputs: [] } end formatters.each do |formatter| formatter[:outputs] << "-" if formatter[:outputs].empty? end load_rake invoke_rake_hook("setup") files = cli_args.empty? ? nil : cli_args exitstatus = TurboTests::Runner.run( formatters: formatters, tags: , files: files, runtime_log: runtime_log, example_status_log: example_status_log, verbose: verbose, fail_fast: fail_fast, count: count, seed: seed, order: order, nice: nice, print_failed_group: print_failed_group, worker_output: worker_output, parallel_options: ) invoke_rake_hook("cleanup") # From https://github.com/galtzo-floss/turbo_tests2/pull/20/ exit(exitstatus) end |