rgot 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +25 -9
- data/bin/rgot +75 -50
- data/lib/rgot/m.rb +4 -6
- data/lib/rgot/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bd2d7a31146606c28b7b373c1f05632088ba374
|
4
|
+
data.tar.gz: 14a9e7bf677e9eb24ea70d3710a48f6383d8b7ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b912a04b6c18f16b8660d2eefb0a50a0444fd1fd60c7d68292d2fdab77f4bf6de63874f86d05346749bbf5c397a195b5247da17089a71c0558dd2b22ce9dde1b
|
7
|
+
data.tar.gz: cc789d6941cb34fc8b0fc1acb1c5844d3a157c69811b5c08e83c04126cdfd38e563fb8f7a1ebaee0c495aa72c1d4f2dc91b815e4ec695c18a84b07caa130ea39
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
Rgot
|
2
2
|
===
|
3
3
|
|
4
4
|
[](https://travis-ci.org/ksss/rgot)
|
@@ -7,7 +7,7 @@ Ruby + Golang Testing = Rgot
|
|
7
7
|
|
8
8
|
Rgot is a testing package convert from golang testing.
|
9
9
|
|
10
|
-
###
|
10
|
+
### Usage
|
11
11
|
|
12
12
|
test/sample.rb
|
13
13
|
```ruby
|
@@ -20,8 +20,6 @@ end
|
|
20
20
|
|
21
21
|
test/pass_test.rb
|
22
22
|
```ruby
|
23
|
-
require_relative './sample'
|
24
|
-
|
25
23
|
module SampleTest
|
26
24
|
class TypeSum < Struct.new(:left, :right, :expect)
|
27
25
|
end
|
@@ -40,7 +38,7 @@ module SampleTest
|
|
40
38
|
t.error("expect Fixnum got #{sum.class}")
|
41
39
|
end
|
42
40
|
unless sum == ts.expect
|
43
|
-
t.error("expect
|
41
|
+
t.error("expect #{ts.expect} got #{sum}")
|
44
42
|
end
|
45
43
|
end
|
46
44
|
end
|
@@ -48,7 +46,7 @@ end
|
|
48
46
|
```
|
49
47
|
|
50
48
|
```
|
51
|
-
$ rgot -v test/pass_test.rb
|
49
|
+
$ rgot -v --require ./test/sample test/pass_test.rb
|
52
50
|
=== RUN test_pass
|
53
51
|
--- PASS: test_pass (0.00003s)
|
54
52
|
PASS
|
@@ -168,9 +166,11 @@ end
|
|
168
166
|
$ rgot -h
|
169
167
|
Usage: rgot [options]
|
170
168
|
-v, --verbose log all tests
|
171
|
-
|
169
|
+
--bench [regexp] benchmark
|
172
170
|
--benchtime [sec] benchmark running time
|
173
171
|
--timeout [sec] set timeout sec to testing
|
172
|
+
--require [path] load some code before running
|
173
|
+
--load-path [path] Specify $LOAD_PATH directory
|
174
174
|
```
|
175
175
|
|
176
176
|
## Basic
|
@@ -208,7 +208,7 @@ Show all log and more detail infomation of testing.
|
|
208
208
|
## Benchmark
|
209
209
|
|
210
210
|
```
|
211
|
-
$ rgot target_file_test.rb
|
211
|
+
$ rgot target_file_test.rb --bench .
|
212
212
|
```
|
213
213
|
|
214
214
|
Run testing with benchmark.
|
@@ -243,7 +243,7 @@ end
|
|
243
243
|
|
244
244
|
Main method should be set 'test_main' only.
|
245
245
|
|
246
|
-
|
246
|
+
Variable `m` is a instance of `Rgot::M` class means Main.
|
247
247
|
|
248
248
|
`Rgot::M#run` start all testing methods.
|
249
249
|
|
@@ -315,6 +315,22 @@ For Benchmark class.
|
|
315
315
|
|
316
316
|
Can use log methods same as `Rgot::T` class
|
317
317
|
|
318
|
+
## Rgot::B#n
|
319
|
+
|
320
|
+
Automatic number calculated by running time.
|
321
|
+
|
322
|
+
Recommend to this idiom.
|
323
|
+
|
324
|
+
```ruby
|
325
|
+
def benchmark_someone(b)
|
326
|
+
i = 0
|
327
|
+
while i < b.n
|
328
|
+
someone()
|
329
|
+
i += 1
|
330
|
+
end
|
331
|
+
end
|
332
|
+
```
|
333
|
+
|
318
334
|
## Rgot::B#reset_timer
|
319
335
|
|
320
336
|
Reset benchmark timer
|
data/bin/rgot
CHANGED
@@ -2,12 +2,14 @@
|
|
2
2
|
require 'optparse'
|
3
3
|
require 'rgot'
|
4
4
|
|
5
|
-
opts = {
|
5
|
+
opts = {
|
6
|
+
require_paths: []
|
7
|
+
}
|
6
8
|
parser = OptionParser.new do |o|
|
7
9
|
o.on '-v', '--verbose', "log all tests" do |arg|
|
8
10
|
opts[:verbose] = arg
|
9
11
|
end
|
10
|
-
o.on '
|
12
|
+
o.on '--bench [regexp]', "benchmark" do |arg|
|
11
13
|
unless arg
|
12
14
|
raise Rgot::OptionError, "missing argument for flag --bench"
|
13
15
|
end
|
@@ -19,71 +21,94 @@ parser = OptionParser.new do |o|
|
|
19
21
|
o.on '--timeout [sec]', "set timeout sec to testing" do |arg|
|
20
22
|
opts[:timeout] = arg
|
21
23
|
end
|
24
|
+
o.on '--require [path]', "load some code before running" do |arg|
|
25
|
+
opts[:require_paths] << arg
|
26
|
+
end
|
27
|
+
o.on '--load-path [path]', "Specify $LOAD_PATH directory" do |arg|
|
28
|
+
$LOAD_PATH.unshift(arg)
|
29
|
+
end
|
22
30
|
end
|
23
31
|
parser.parse!(ARGV)
|
32
|
+
opts[:require_paths].each do |path|
|
33
|
+
require path
|
34
|
+
end
|
24
35
|
|
25
|
-
|
26
|
-
|
27
|
-
if target
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
36
|
+
ARGV.each do |target|
|
37
|
+
if target
|
38
|
+
if File.file?(target)
|
39
|
+
require File.expand_path(target)
|
40
|
+
elsif File.directory?(target)
|
41
|
+
Dir.glob("./#{target}/*_test.rb") do |i|
|
42
|
+
require i
|
43
|
+
end
|
44
|
+
else
|
45
|
+
puts target
|
33
46
|
end
|
34
47
|
else
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
Dir.glob("./**/*_test.rb") do |i|
|
39
|
-
require i
|
48
|
+
Dir.glob("./**/*_test.rb") do |i|
|
49
|
+
require i
|
50
|
+
end
|
40
51
|
end
|
41
52
|
end
|
42
53
|
|
43
54
|
modules = Object.constants.select { |c|
|
44
55
|
next if c == :FileTest
|
45
56
|
/.*Test\z/ =~ c
|
57
|
+
}.map{ |c|
|
58
|
+
Object.const_get(c)
|
46
59
|
}
|
47
60
|
|
48
|
-
if 1 != modules.length
|
49
|
-
|
50
|
-
|
51
|
-
end
|
61
|
+
# if 1 != modules.length
|
62
|
+
# puts "can not load module. found #{modules.join(', ')}"
|
63
|
+
# exit 1
|
64
|
+
# end
|
52
65
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
66
|
+
code = 0
|
67
|
+
modules.each do |test_module|
|
68
|
+
pid = fork {
|
69
|
+
tests = []
|
70
|
+
benchmarks = []
|
71
|
+
examples = []
|
72
|
+
main = nil
|
73
|
+
methods = test_module.instance_methods.sort
|
74
|
+
methods.grep(/\Atest_/).each do |m|
|
75
|
+
if m == :test_main && main.nil?
|
76
|
+
main = Rgot::InternalTest.new(test_module, m)
|
77
|
+
else
|
78
|
+
tests << Rgot::InternalTest.new(test_module, m)
|
79
|
+
end
|
80
|
+
end
|
58
81
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
if m == :test_main && main.nil?
|
63
|
-
main = Rgot::InternalTest.new(test_module, m)
|
64
|
-
else
|
65
|
-
tests << Rgot::InternalTest.new(test_module, m)
|
66
|
-
end
|
67
|
-
end
|
82
|
+
methods.grep(/\Abenchmark_/).each do |m|
|
83
|
+
benchmarks << Rgot::InternalBenchmark.new(test_module, m)
|
84
|
+
end
|
68
85
|
|
69
|
-
methods.grep(/\
|
70
|
-
|
71
|
-
end
|
86
|
+
methods.grep(/\Aexample_?/).each do |m|
|
87
|
+
examples << Rgot::InternalExample.new(test_module, m)
|
88
|
+
end
|
72
89
|
|
73
|
-
|
74
|
-
|
75
|
-
|
90
|
+
duration = Rgot.now
|
91
|
+
at_exit {
|
92
|
+
template = "%s\t%s\t%.3fs"
|
76
93
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
94
|
+
if $!.kind_of?(SystemExit) && $!.success?
|
95
|
+
puts sprintf(template, "ok", test_module, Rgot.now - duration)
|
96
|
+
else
|
97
|
+
puts sprintf(template, "FAIL", test_module, Rgot.now - duration)
|
98
|
+
end
|
99
|
+
}
|
100
|
+
m = Rgot::M.new(tests: tests, benchmarks: benchmarks, examples: examples, opts: opts)
|
101
|
+
if main
|
102
|
+
main.module.extend main.module
|
103
|
+
main.module.instance_method(main.name).bind(main.module).call(m)
|
104
|
+
else
|
105
|
+
exit m.run
|
106
|
+
end
|
107
|
+
}
|
108
|
+
_, status = Process.waitpid2(pid)
|
109
|
+
unless status.success?
|
110
|
+
code = 1
|
82
111
|
end
|
83
|
-
}
|
84
|
-
if main
|
85
|
-
main.module.extend main.module
|
86
|
-
main.module.instance_method(main.name).bind(main.module).call(m)
|
87
|
-
else
|
88
|
-
exit m.run
|
89
112
|
end
|
113
|
+
|
114
|
+
exit code
|
data/lib/rgot/m.rb
CHANGED
@@ -13,18 +13,18 @@ module Rgot
|
|
13
13
|
def run
|
14
14
|
test_ok = false
|
15
15
|
example_ok = false
|
16
|
+
|
16
17
|
Timeout.timeout(@opts[:timeout].to_f) {
|
17
18
|
test_ok = run_tests
|
18
19
|
example_ok = run_examples
|
19
20
|
}
|
20
21
|
if !test_ok || !example_ok
|
21
22
|
puts "FAIL"
|
22
|
-
1
|
23
|
-
else
|
24
|
-
puts "PASS"
|
25
|
-
0
|
23
|
+
return 1
|
26
24
|
end
|
25
|
+
puts "PASS" if @opts[:verbose]
|
27
26
|
run_benchmarks
|
27
|
+
0
|
28
28
|
end
|
29
29
|
|
30
30
|
private
|
@@ -87,8 +87,6 @@ module Rgot
|
|
87
87
|
ok
|
88
88
|
end
|
89
89
|
|
90
|
-
private
|
91
|
-
|
92
90
|
def capture
|
93
91
|
orig_out, orig_err = $stdout, $stderr
|
94
92
|
out, err = StringIO.new, StringIO.new
|
data/lib/rgot/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rgot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ksss
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|