README.md in rgot-1.2.0 vs README.md in rgot-1.3.0

- old
+ new

@@ -91,10 +91,37 @@ ok FooTest 2.782s ``` `b.n` is automatically adjusted. +## Fuzzing + +``` +$ rgot target_file_test.rb --fuzz . --fuzztime 1 +``` + +Fuzzing tests are also supported. +Please refer to the gloang documentation for details. + +https://go.dev/security/fuzz/ + +```ruby +module FooTest + # To enable fuzzing, the method name + # should be prefixed with `fuzz`. + def fuzz_any_func(f) + f.add(5, "hello") + f.fuzz do |t, i, s| + out, err = foo(i, s) + if err != nil && out != "" + t.errorf("%s, %s", out, err) + end + end + end +end +``` + ## Example Rgot's example feature is the best and if you want to write the sample code of your library. While presenting the sample code, it will be able to test whether the display results match at the same time. @@ -187,20 +214,25 @@ Method name should be set `test_*` for testing. And benchmark method should be set `benchmark_*`. +And fuzz method should be set `fuzz_*`. + And example method should be set `example_*`. ```ruby module XxxTest def test_any_name(t) end def benchmark_any_name(b) end + def fuzz_any_name(f) + end + def example_any_name end end ``` @@ -216,10 +248,12 @@ --timeout [sec] set timeout sec to testing --cpu [count,...] set cpu counts of comma split --thread [count,...] set thread counts of comma split --require [path] load some code before running --load-path [path] Specify $LOAD_PATH directory + --fuzz [regexp] run the fuzz test matching `regexp` + --fuzztime [sec] time to spend fuzzing; default is to run indefinitely ``` ## Basic ``` @@ -513,5 +547,41 @@ some_func() end end end ``` + +## Rgot::F (Fuzzing) + +### Rgot::F#add + +Set the sample value with `#add`. This value is also used as a test. It guesses the type from the value and generates a random value. + +### Rgot::F#fuzz + +Generate the random value generated by `#fuzz` and execute the code. +The `t` becomes an instance of `Rgot::T` and the test can be run as usual. + +```ruby +def fuzz_foo(f) + f.add(100, "hello") + f.fuzz do |t, i, s| + i #=> 100, 84, 17, 9, 66, ... + s #=> "hello", "Y\xD5\xAB\xBA\x8E", "r\x95D\xA5\xF7", "\xCEj=\x9C\xBD", ... + if !foo(i, s) + t.error("fail with i=#{i}, s=#{s}") + end + end +end +``` + +# TODO + +- [ ] Support to save and load fuzzing data + +## v2 + +- [ ] Support sub testing +- [ ] Fix duration argument unit +- [ ] Refactoring + - [ ] Fix M#initialize argument + - [ ] Fix internal class API