README.md in rgot-0.0.5 vs README.md in rgot-0.1.0

- old
+ new

@@ -8,19 +8,21 @@ Rgot is a testing package convert from golang testing. ### Usage test/sample.rb + ```ruby class Sample def sum(i, j) i + j end end ``` test/pass_test.rb + ```ruby module SampleTest class TypeSum < Struct.new(:left, :right, :expect) end @@ -51,11 +53,11 @@ --- PASS: test_pass (0.00003s) PASS ok 0.001s ``` -# Feature +# Features ## Testing I provide a very simple testing feature to you. @@ -83,11 +85,11 @@ end ``` ``` $ rgot foo_test.rb --bench . -benchmark_something 14400000 81.392 ns/op +benchmark_something 14400000 81 ns/op ok FooTest 2.782s ``` `b.n` is automatically adjusted. @@ -176,15 +178,16 @@ ``` $ rgot -h Usage: rgot [options] -v, --verbose log all tests + --version show Rgot version --bench [regexp] benchmark --benchtime [sec] benchmark running time --timeout [sec] set timeout sec to testing - --cpu [count,...] set cpu counts of comma splited - --thread [count,...] set thread counts of comma splited + --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 ``` ## Basic @@ -215,11 +218,11 @@ --- PASS: test_pass (0.00005s) PASS ok 0.001s ``` -Show all log and more detail infomation of testing. +Show all log and more detail information of testing. ## Benchmark ``` $ rgot target_file_test.rb --bench . @@ -233,17 +236,17 @@ ### Parallel benchmark Benchmark for parallel performance. -`--cpu` option set process counts (default 1). +`--cpu` option set process counts (default `Etc.nprocessors`). And `--thread` option set thread counts (default 1). Benchmark fork, run and report each by process counts. -(**process** and **thread** means ruby/linux process) +(**process** and **thread** means ruby/linux native process and thread) ```ruby module FooTest def benchmark_any_func(b) b.run_parallel do |pb| @@ -257,14 +260,14 @@ end ``` ``` $ rgot foo_test.rb --bench . --cpu=2,4 --thread=2,4 -benchmark_any_func-2(2) 40 13363604.899 ns/op -benchmark_any_func-2(4) 160 7125845.113 ns/op -benchmark_any_func-4(2) 160 7224815.534 ns/op -benchmark_any_func-4(4) 320 3652431.962 ns/op +benchmark_any_func-2(2) 40 13363604 ns/op +benchmark_any_func-2(4) 160 7125845 ns/op +benchmark_any_func-4(2) 160 7224815 ns/op +benchmark_any_func-4(4) 320 3652431 ns/op ok FooTest 3.061s ``` ## Timeout @@ -274,12 +277,35 @@ You can set timeout sec for testing (default 0). Fail testing and print raised exception message to STDERR if timeout. -# Rgot::M (Main) +# Methods +## Rgot + +### Rgot.benchmark + +Run benchmark function without framework. + +```ruby +result = Rgot.benchmark do |b| + i = 0 + while i < b.n + some_func() + i += 1 + end +end +puts result #=> 100000 100 ns/op +``` + +### Rgot.verbose? + +Check running with option verbose true/false. + +## Rgot::M (Main) + Main method run first on testing. And this is default virtual main code. ```ruby @@ -309,46 +335,74 @@ exit code end end ``` -# Rgot::Common +## Rgot::Common `Rgot::Common` is inherited to `Rgot::T` and `Rgot::B` `Rgot::Common` have some logging method. -## Rgot::Common#log +### Rgot::Common#log ```ruby -t.log("wooooo") +t.log("wooooo", 1, 2, 3) ``` Write any log message. But this message to show need -v option. -## Rgot::Common#error +### Rgot::Common#logf +Write any log message like sprintf. + ```ruby +t.logf("%d-%s", 10, "foo") +``` + +### Rgot::Common#error + +```ruby t.error("expect #{a} got #{b}") ``` Test fail and show some error message. -## Rgot::Common#skip +### Rgot::Common#errorf +Fail loggin same as logf + +### Rgot::Common#fatal + +Testing stop and fail with log. + ```ruby +t.fatal("fatal error!") +``` + +### Rgot::Common#fatalf + +Fatal logging same as logf + +### Rgot::Common#skip + +```ruby t.skip("this method was skipped") ``` Skip current testing method. And run to next testing method. -# Rgot::T (Testing) +### Rgot::Common#skipf +Skip logging same as logf + +## Rgot::T (Testing) + Testing is a main usage of this package. ```ruby module TestSomeCode def test_some_1(t) @@ -356,17 +410,17 @@ end ``` The `t` variable is instance of `Rgot::T` class means Testing. -# Rgot::B (Benchmark) +## Rgot::B (Benchmark) For Benchmark class. Can use log methods same as `Rgot::T` class -## Rgot::B#n +### Rgot::B#n Automatic number calculated by running time. Recommend to this idiom. @@ -378,11 +432,11 @@ i += 1 end end ``` -## Rgot::B#reset_timer +### Rgot::B#reset_timer Reset benchmark timer ```ruby def benchmark_something(b) @@ -394,28 +448,28 @@ i += 1 end end ``` -## Rgot::B#start_timer +### Rgot::B#start_timer Start benchmark timer -## Rgot::B#stop_timer +### Rgot::B#stop_timer Stop benchmark timer -## Rgot::B#run_parallel +### Rgot::B#run_parallel Start parallel benchmark using `fork` and `Thread.new`. This method should be call with block. The block argument is instance of Rgot::PB. -# Rgot::PB (Parallel Benchmark) +## Rgot::PB (Parallel Benchmark) -## Rgot::PB#next +### Rgot::PB#next Should be call this when parallel benchmark. Repeat while return false.