lib/rgot/cli.rb in rgot-1.2.0 vs lib/rgot/cli.rb in rgot-1.3.0
- old
+ new
@@ -50,10 +50,19 @@
require_paths << arg
end
o.on '--load-path [path]', "Specify $LOAD_PATH directory" do |arg|
$LOAD_PATH.unshift(arg)
end
+ o.on '--fuzz [regexp]', "run the fuzz test matching `regexp`" do |arg|
+ unless arg
+ raise Rgot::OptionError, "missing argument for flag --fuzz"
+ end
+ opts.fuzz = arg
+ end
+ o.on '--fuzztime [sec]', "time to spend fuzzing; default is to run indefinitely" do |arg|
+ opts.fuzztime = arg
+ end
end
parser.parse!(@argv)
require_paths.each do |path|
require path
@@ -91,16 +100,22 @@
def child_process(opts, testing_file)
node = RubyVM::AbstractSyntaxTree.parse_file(testing_file).children[2]
test_module_name = find_toplevel_name(node)
+ if opts.fuzz
+ # fuzzing observes changes in coverage.
+ require 'coverage'
+ Coverage.start(oneshot_lines: true)
+ end
load testing_file
test_module = Object.const_get(test_module_name)
tests = []
benchmarks = []
examples = []
+ fuzz_targets = []
main = nil
methods = test_module.public_instance_methods
methods.grep(/\Atest_/).each do |m|
if m == :test_main && main.nil?
main = Rgot::InternalTest.new(test_module, m)
@@ -115,19 +130,28 @@
methods.grep(/\Aexample_?/).each do |m|
examples << Rgot::InternalExample.new(test_module, m)
end
- m = Rgot::M.new(test_module: test_module, tests: tests, benchmarks: benchmarks, examples: examples, opts: opts)
+ methods.grep(/\Afuzz_/).each do |m|
+ fuzz_targets << Rgot::InternalFuzzTarget.new(test_module, m)
+ end
+
+ m = Rgot::M.new(
+ test_module: test_module,
+ tests: tests,
+ benchmarks: benchmarks,
+ examples: examples,
+ fuzz_targets: fuzz_targets,
+ opts: opts
+ )
if main
main.module.extend main.module
main.module.instance_method(:test_main).bind(main.module).call(m)
else
m.run
end
end
-
- private
def find_toplevel_name(node)
case node.type
when :MODULE
find_toplevel_name(node.children.first)