1 2 3 4 5 6 7 8 9 10 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
|
#!/usr/bin/env ruby
=begin
A simplified test runner; it runs all tests by default.
It assumes that "bundle exec rake compile" has been run.
It can also be passed a glob or test file names. If multiple test file names
are used, separate them by the File::PATH_SEPARATOR character with no spaces.
The file extension is optional.
If arguments are used that take values (eg seed), use the 'no space' version,
like -s33388 or --seed=33388
'-w' is an additional option, it will switch $VERBOSE to true before the
test files are loaded.
'-z' is an additional option, it will switch $VERBOSE to true and cancel the tests.
Finally, to keep the code simple, if you pass an invalid argument for file
filtering it will either error or run minitest with no tests loaded
Examples, run from the top Puma repo folder:
test/runner
test/runner -v
test/runner -v test_puma_server
test/runner --verbose test_puma_server*
test/runner --verbose test_integration_cluster:test_integration_single
test/runner --verbose test*ssl*
Note that on macOS, globs (using '*') need to be quoted, as in:
test/runner -v 'test_integration_*.rb'
=end
require 'bundler/setup'
require 'stringio'
if ARGV.delete '-z'
show_warnings = true
no_tests = true
elsif ARGV.delete '-w'
show_warnings = true
elsif ARGV.delete('-wv') || ARGV.delete('-vw')
show_warnings = true
ARGV.unshift '-v'
else
show_warnings = nil
end
if show_warnings
stderr, $stderr = STDERR, StringIO.new
$VERBOSE = true
end
if ARGV.empty? || ARGV.last.start_with?('-')
if RUBY_VERSION >= '2.5'
Dir['test_*.rb', base: __dir__].sort.each { |tf| require_relative tf }
else
Dir["#{__dir__}/test_*.rb"].sort.each { |tf| require tf }
end
else
file_arg = ARGV.pop.sub(/\.rb\z/, '')
if file_arg.include? File::PATH_SEPARATOR
file_args = file_arg.split(File::PATH_SEPARATOR).map { |fn| fn.sub(/\.rb\z/, '') }
file_args.each { |tf| require_relative "#{tf}.rb" }
elsif file_arg.include? '*'
if RUBY_VERSION >= '2.5'
Dir["#{file_arg}.rb", base: __dir__].sort.each { |tf| require_relative tf }
else
Dir["#{__dir__}/#{file_arg}.rb"].sort.each { |tf| require tf }
end
else
require_relative "#{file_arg}.rb"
end
end
if show_warnings
warnings = $stderr.string&.strip
$stderr = stderr
if warnings && !warnings.empty?
warnings = warnings.gsub("#{__dir__}/", '')
.split("\n")
.sort
.join("\n")
STDERR.write "#{warnings}\n\n"
end
end
exit 1 if no_tests
require 'minitest'
STDOUT.write "Minitest version: #{Minitest::VERSION}\n\n"
|