rgot 0.1.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/main.yml +30 -0
- data/README.md +33 -3
- data/Rakefile +5 -2
- data/bin/rgot +2 -134
- data/lib/rgot/b.rb +16 -10
- data/lib/rgot/benchmark_result.rb +1 -4
- data/lib/rgot/cli.rb +154 -0
- data/lib/rgot/common.rb +1 -0
- data/lib/rgot/m.rb +17 -13
- data/lib/rgot/pb.rb +1 -3
- data/lib/rgot/t.rb +8 -10
- data/lib/rgot/version.rb +1 -1
- data/lib/rgot.rb +8 -23
- metadata +8 -8
- data/.travis.yml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: edabddcdf99d28070fbe94f391d49d7c034cb1b6d467629c76fc671f7d27956b
|
4
|
+
data.tar.gz: 642606670788ef496178d91b9450f6c08bb97e8e4f9e14442e0868ddf0c2acbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb8824c1730be5395ffb22b3c075239b612a987db000367c804201394305b080834bb246c7c198da556e26090ae7a8424830b6253f7c10fd0183662ff6d490d0
|
7
|
+
data.tar.gz: 4064bdb31930c1cc0a072ab6c7113f93f66ce8cd3bafd4208824c36a5c591685a0e82f7e09758ff32a4d342eefee64efeb92910e8b45c75a48175571f84e03f7
|
@@ -0,0 +1,30 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- main
|
7
|
+
|
8
|
+
pull_request:
|
9
|
+
|
10
|
+
jobs:
|
11
|
+
build:
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
name: Ruby ${{ matrix.ruby }}
|
14
|
+
strategy:
|
15
|
+
matrix:
|
16
|
+
ruby:
|
17
|
+
- '2.6.10'
|
18
|
+
- '2.7.6'
|
19
|
+
- '3.0.4'
|
20
|
+
- '3.1.2'
|
21
|
+
|
22
|
+
steps:
|
23
|
+
- uses: actions/checkout@v2
|
24
|
+
- name: Set up Ruby
|
25
|
+
uses: ruby/setup-ruby@v1
|
26
|
+
with:
|
27
|
+
ruby-version: ${{ matrix.ruby }}
|
28
|
+
bundler-cache: true
|
29
|
+
- name: Run the default task
|
30
|
+
run: bundle exec rake
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Rgot
|
2
2
|
===
|
3
3
|
|
4
|
-
[![
|
4
|
+
[![Ruby](https://github.com/ksss/rgot/actions/workflows/main.yml/badge.svg)](https://github.com/ksss/rgot/actions/workflows/main.yml)
|
5
5
|
|
6
6
|
Ruby + Golang Testing = Rgot
|
7
7
|
|
@@ -36,8 +36,8 @@ module SampleTest
|
|
36
36
|
s = Sample.new
|
37
37
|
DATA.each do |ts|
|
38
38
|
sum = s.sum(ts.left, ts.right)
|
39
|
-
unless sum.kind_of?(
|
40
|
-
t.error("expect
|
39
|
+
unless sum.kind_of?(Integer)
|
40
|
+
t.error("expect Integer got #{sum.class}")
|
41
41
|
end
|
42
42
|
unless sum == ts.expect
|
43
43
|
t.error("expect #{ts.expect} got #{sum}")
|
@@ -131,6 +131,36 @@ end
|
|
131
131
|
|
132
132
|
So, you can notice that the sample code is wrong.
|
133
133
|
|
134
|
+
# Table Driven Tests
|
135
|
+
|
136
|
+
```rb
|
137
|
+
FLAGTESTS = [
|
138
|
+
["%a", "[%a]"],
|
139
|
+
["%-a", "[%-a]"],
|
140
|
+
["%+a", "[%+a]"],
|
141
|
+
["%#a", "[%#a]"],
|
142
|
+
["% a", "[% a]"],
|
143
|
+
["%0a", "[%0a]"],
|
144
|
+
["%1.2a", "[%1.2a]"],
|
145
|
+
["%-1.2a", "[%-1.2a]"],
|
146
|
+
["%+1.2a", "[%+1.2a]"],
|
147
|
+
["%-+1.2a", "[%+-1.2a]"],
|
148
|
+
["%-+1.2abc", "[%+-1.2a]bc"],
|
149
|
+
["%-1.2abc", "[%-1.2a]bc"],
|
150
|
+
]
|
151
|
+
|
152
|
+
def test_flag_parser(t)
|
153
|
+
FLAGTESTS.each do |input, output|
|
154
|
+
s = Flag.print(input)
|
155
|
+
unless s == output
|
156
|
+
t.errorf("Flag.print(%p) => %p, want %p", input, s, output)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
```
|
161
|
+
|
162
|
+
see https://github.com/golang/go/wiki/TableDrivenTests
|
163
|
+
|
134
164
|
# Naming convention
|
135
165
|
|
136
166
|
## Filename
|
data/Rakefile
CHANGED
@@ -2,8 +2,11 @@ require "bundler/gem_tasks"
|
|
2
2
|
|
3
3
|
desc "test to rgot"
|
4
4
|
task :test do |t|
|
5
|
-
|
6
|
-
|
5
|
+
targets = [
|
6
|
+
"test/rgot_common_test.rb",
|
7
|
+
"test/rgot_test.rb",
|
8
|
+
]
|
9
|
+
ruby "bin/rgot -v #{targets.join(' ')}"
|
7
10
|
end
|
8
11
|
|
9
12
|
task :default => [:test]
|
data/bin/rgot
CHANGED
@@ -1,136 +1,4 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
|
-
require '
|
3
|
-
require 'rgot'
|
2
|
+
require 'rgot/cli'
|
4
3
|
|
5
|
-
|
6
|
-
require_paths = []
|
7
|
-
parser = OptionParser.new do |o|
|
8
|
-
o.on '-v', '--verbose', "log all tests" do |arg|
|
9
|
-
Rgot.class_eval{ @chatty = arg }
|
10
|
-
end
|
11
|
-
o.on '--version', "show Rgot version" do |arg|
|
12
|
-
puts "Rgot v#{Rgot::VERSION}"
|
13
|
-
exit 0
|
14
|
-
end
|
15
|
-
o.on '--bench [regexp]', "benchmark" do |arg|
|
16
|
-
unless arg
|
17
|
-
raise Rgot::OptionError, "missing argument for flag --bench"
|
18
|
-
end
|
19
|
-
opts.bench = arg
|
20
|
-
end
|
21
|
-
o.on '--benchtime [sec]', "benchmark running time" do |arg|
|
22
|
-
opts.benchtime = arg
|
23
|
-
end
|
24
|
-
o.on '--timeout [sec]', "set timeout sec to testing" do |arg|
|
25
|
-
opts.timeout = arg
|
26
|
-
end
|
27
|
-
o.on '--cpu [count,...]', "set cpu counts of comma split" do |arg|
|
28
|
-
opts.cpu = arg
|
29
|
-
end
|
30
|
-
o.on '--thread [count,...]', "set thread counts of comma split" do |arg|
|
31
|
-
opts.thread = arg
|
32
|
-
end
|
33
|
-
o.on '--require [path]', "load some code before running" do |arg|
|
34
|
-
require_paths << arg
|
35
|
-
end
|
36
|
-
o.on '--load-path [path]', "Specify $LOAD_PATH directory" do |arg|
|
37
|
-
$LOAD_PATH.unshift(arg)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
parser.parse!(ARGV)
|
41
|
-
require_paths.each do |path|
|
42
|
-
require path
|
43
|
-
end
|
44
|
-
|
45
|
-
ARGV.each do |target|
|
46
|
-
if target
|
47
|
-
if File.file?(target)
|
48
|
-
require File.expand_path(target)
|
49
|
-
elsif File.directory?(target)
|
50
|
-
Dir.glob("./#{target}/**/*_test.rb") do |i|
|
51
|
-
require i
|
52
|
-
end
|
53
|
-
else
|
54
|
-
puts target
|
55
|
-
end
|
56
|
-
else
|
57
|
-
Dir.glob("./**/*_test.rb") do |i|
|
58
|
-
require i
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
modules = Object.constants.select { |c|
|
64
|
-
next if c == :FileTest
|
65
|
-
/.*Test\z/ =~ c
|
66
|
-
}.map{ |c|
|
67
|
-
Object.const_get(c)
|
68
|
-
}
|
69
|
-
|
70
|
-
# if 1 != modules.length
|
71
|
-
# puts "can not load module. found #{modules.join(', ')}"
|
72
|
-
# exit 1
|
73
|
-
# end
|
74
|
-
|
75
|
-
code = 0
|
76
|
-
modules.each do |test_module|
|
77
|
-
begin
|
78
|
-
pid = fork {
|
79
|
-
tests = []
|
80
|
-
benchmarks = []
|
81
|
-
examples = []
|
82
|
-
main = nil
|
83
|
-
methods = test_module.instance_methods.sort
|
84
|
-
methods.grep(/\Atest_/).each do |m|
|
85
|
-
if m == :test_main && main.nil?
|
86
|
-
main = Rgot::InternalTest.new(test_module, m)
|
87
|
-
else
|
88
|
-
tests << Rgot::InternalTest.new(test_module, m)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
methods.grep(/\Abenchmark_/).each do |m|
|
93
|
-
benchmarks << Rgot::InternalBenchmark.new(test_module, m)
|
94
|
-
end
|
95
|
-
|
96
|
-
methods.grep(/\Aexample_?/).each do |m|
|
97
|
-
examples << Rgot::InternalExample.new(test_module, m)
|
98
|
-
end
|
99
|
-
|
100
|
-
duration = Rgot.now
|
101
|
-
at_exit {
|
102
|
-
template = "%s\t%s\t%.3fs"
|
103
|
-
|
104
|
-
case $!
|
105
|
-
when SystemExit
|
106
|
-
if $!.success?
|
107
|
-
# exit 0
|
108
|
-
puts sprintf(template, "ok", test_module, Rgot.now - duration)
|
109
|
-
else
|
110
|
-
# exit 1
|
111
|
-
puts sprintf(template, "FAIL", test_module, Rgot.now - duration)
|
112
|
-
end
|
113
|
-
when NilClass
|
114
|
-
# not raise, not exit
|
115
|
-
else
|
116
|
-
# any exception
|
117
|
-
puts sprintf(template, "FAIL", test_module, Rgot.now - duration)
|
118
|
-
end
|
119
|
-
}
|
120
|
-
m = Rgot::M.new(tests: tests, benchmarks: benchmarks, examples: examples, opts: opts)
|
121
|
-
if main
|
122
|
-
main.module.extend main.module
|
123
|
-
main.module.instance_method(main.name).bind(main.module).call(m)
|
124
|
-
else
|
125
|
-
exit m.run
|
126
|
-
end
|
127
|
-
}
|
128
|
-
ensure
|
129
|
-
_, status = Process.waitpid2(pid)
|
130
|
-
unless status.success?
|
131
|
-
code = 1
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
exit code
|
4
|
+
Rgot::Cli.new(ARGV).run
|
data/lib/rgot/b.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module Rgot
|
2
2
|
class B < Common
|
3
|
-
|
3
|
+
Options = Struct.new(
|
4
4
|
:procs,
|
5
5
|
:threads,
|
6
|
-
:benchtime
|
7
|
-
)
|
6
|
+
:benchtime,
|
7
|
+
)
|
8
8
|
|
9
9
|
attr_accessor :n
|
10
|
-
def initialize(benchmark_module, name, opts=Options.new)
|
10
|
+
def initialize(benchmark_module, name, opts = Options.new)
|
11
11
|
super()
|
12
12
|
@n = 1
|
13
13
|
@module = benchmark_module
|
@@ -42,7 +42,7 @@ module Rgot
|
|
42
42
|
def run(&block)
|
43
43
|
n = 1
|
44
44
|
benchtime = (@opts.benchtime || 1).to_f
|
45
|
-
catch(:skip)
|
45
|
+
catch(:skip) do
|
46
46
|
run_n(n.to_i, block)
|
47
47
|
while !failed? && @duration < benchtime && @n < 1e9
|
48
48
|
if @duration < (benchtime / 100.0)
|
@@ -61,7 +61,7 @@ module Rgot
|
|
61
61
|
end
|
62
62
|
run_n(@n.to_i, block)
|
63
63
|
end
|
64
|
-
|
64
|
+
end
|
65
65
|
|
66
66
|
BenchmarkResult.new(n: @n, t: @duration)
|
67
67
|
end
|
@@ -73,13 +73,13 @@ module Rgot
|
|
73
73
|
threads = (@opts.threads || 1)
|
74
74
|
|
75
75
|
procs.times do
|
76
|
-
fork
|
76
|
+
fork do
|
77
77
|
Array.new(threads) {
|
78
78
|
Thread.new {
|
79
79
|
yield PB.new(bn: @n)
|
80
80
|
}.tap { |t| t.abort_on_exception = true }
|
81
81
|
}.each(&:join)
|
82
|
-
|
82
|
+
end
|
83
83
|
end
|
84
84
|
@n *= procs * threads
|
85
85
|
Process.waitall
|
@@ -87,7 +87,7 @@ module Rgot
|
|
87
87
|
|
88
88
|
private
|
89
89
|
|
90
|
-
def run_n(n, block=nil)
|
90
|
+
def run_n(n, block = nil)
|
91
91
|
GC.start
|
92
92
|
@n = n
|
93
93
|
reset_timer
|
@@ -95,7 +95,13 @@ module Rgot
|
|
95
95
|
if block
|
96
96
|
block.call(self)
|
97
97
|
else
|
98
|
-
@module.instance_method(@name).bind(@module)
|
98
|
+
bench_method = @module.instance_method(@name).bind(@module)
|
99
|
+
if bench_method.arity == 0
|
100
|
+
path, line = bench_method.source_location
|
101
|
+
skip "#{path}:#{line} `#{bench_method.name}' is not running. It's a benchmark method name, But not have argument"
|
102
|
+
else
|
103
|
+
bench_method.call(self)
|
104
|
+
end
|
99
105
|
end
|
100
106
|
stop_timer
|
101
107
|
end
|
@@ -1,9 +1,6 @@
|
|
1
1
|
module Rgot
|
2
2
|
class BenchmarkResult
|
3
|
-
|
4
|
-
def initialize(n: nil, t: nil)
|
5
|
-
raise ArgumentError, "missing keyword: n" unless n
|
6
|
-
raise ArgumentError, "missing keyword: t" unless t
|
3
|
+
def initialize(n:, t:)
|
7
4
|
@n = n
|
8
5
|
@t = t
|
9
6
|
end
|
data/lib/rgot/cli.rb
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
require_relative '../rgot'
|
4
|
+
|
5
|
+
module Rgot
|
6
|
+
class Cli
|
7
|
+
def initialize(argv)
|
8
|
+
@argv = argv
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
opts = Rgot::M::Options.new
|
13
|
+
parse_option(opts)
|
14
|
+
process_start(opts)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def parse_option(opts)
|
20
|
+
require_paths = []
|
21
|
+
parser = OptionParser.new do |o|
|
22
|
+
o.on '-v', '--verbose', "log all tests" do |arg|
|
23
|
+
Rgot.class_eval { @chatty = arg }
|
24
|
+
end
|
25
|
+
o.on '--version', "show Rgot version" do |arg|
|
26
|
+
puts "rgot #{Rgot::VERSION} (ruby #{RUBY_VERSION})"
|
27
|
+
exit 0
|
28
|
+
end
|
29
|
+
o.on '--bench [regexp]', "benchmark" do |arg|
|
30
|
+
unless arg
|
31
|
+
raise Rgot::OptionError, "missing argument for flag --bench"
|
32
|
+
end
|
33
|
+
opts.bench = arg
|
34
|
+
end
|
35
|
+
o.on '--benchtime [sec]', "benchmark running time" do |arg|
|
36
|
+
opts.benchtime = arg
|
37
|
+
end
|
38
|
+
o.on '--timeout [sec]', "set timeout sec to testing" do |arg|
|
39
|
+
opts.timeout = arg
|
40
|
+
end
|
41
|
+
o.on '--cpu [count,...]', "set cpu counts of comma split" do |arg|
|
42
|
+
opts.cpu = arg
|
43
|
+
end
|
44
|
+
o.on '--thread [count,...]', "set thread counts of comma split" do |arg|
|
45
|
+
opts.thread = arg
|
46
|
+
end
|
47
|
+
o.on '--require [path]', "load some code before running" do |arg|
|
48
|
+
require_paths << arg
|
49
|
+
end
|
50
|
+
o.on '--load-path [path]', "Specify $LOAD_PATH directory" do |arg|
|
51
|
+
$LOAD_PATH.unshift(arg)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
parser.parse!(@argv)
|
55
|
+
|
56
|
+
require_paths.each do |path|
|
57
|
+
require path
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def testing_files
|
62
|
+
if @argv.empty?
|
63
|
+
Dir.glob("./**/*_test.rb")
|
64
|
+
else
|
65
|
+
@argv.flat_map do |target|
|
66
|
+
if File.file?(target)
|
67
|
+
File.expand_path(target)
|
68
|
+
elsif File.directory?(target)
|
69
|
+
Dir.glob("./#{target}/**/*_test.rb")
|
70
|
+
else
|
71
|
+
warn "#{target} is not file or directory"
|
72
|
+
end
|
73
|
+
end.compact
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def process_start(opts)
|
78
|
+
code = 0
|
79
|
+
testing_files.map do |testing_file|
|
80
|
+
begin
|
81
|
+
pid = fork do
|
82
|
+
require testing_file
|
83
|
+
|
84
|
+
modules = Object.constants.select { |c|
|
85
|
+
next if c == :FileTest
|
86
|
+
/.*Test\z/ =~ c
|
87
|
+
}.map { |c|
|
88
|
+
Object.const_get(c)
|
89
|
+
}
|
90
|
+
|
91
|
+
modules.each do |test_module|
|
92
|
+
tests = []
|
93
|
+
benchmarks = []
|
94
|
+
examples = []
|
95
|
+
main = nil
|
96
|
+
methods = test_module.instance_methods
|
97
|
+
methods.grep(/\Atest_/).each do |m|
|
98
|
+
if m == :test_main && main.nil?
|
99
|
+
main = Rgot::InternalTest.new(test_module, m)
|
100
|
+
else
|
101
|
+
tests << Rgot::InternalTest.new(test_module, m)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
methods.grep(/\Abenchmark_/).each do |m|
|
106
|
+
benchmarks << Rgot::InternalBenchmark.new(test_module, m)
|
107
|
+
end
|
108
|
+
|
109
|
+
methods.grep(/\Aexample_?/).each do |m|
|
110
|
+
examples << Rgot::InternalExample.new(test_module, m)
|
111
|
+
end
|
112
|
+
|
113
|
+
duration = Rgot.now
|
114
|
+
at_exit do
|
115
|
+
template = "%s\t%s\t%.3fs"
|
116
|
+
|
117
|
+
case $!
|
118
|
+
when SystemExit
|
119
|
+
if $!.success?
|
120
|
+
# exit 0
|
121
|
+
puts sprintf(template, "ok ", test_module, Rgot.now - duration)
|
122
|
+
else
|
123
|
+
# exit 1
|
124
|
+
puts "exit status #{$!.status}"
|
125
|
+
puts sprintf(template, "FAIL", test_module, Rgot.now - duration)
|
126
|
+
end
|
127
|
+
when NilClass
|
128
|
+
# not raise, not exit
|
129
|
+
else
|
130
|
+
# any exception
|
131
|
+
puts sprintf(template, "FAIL", test_module, Rgot.now - duration)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
m = Rgot::M.new(tests: tests, benchmarks: benchmarks, examples: examples, opts: opts)
|
135
|
+
if main
|
136
|
+
main.module.extend main.module
|
137
|
+
main.module.instance_method(main.name).bind(main.module).call(m)
|
138
|
+
else
|
139
|
+
exit m.run
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
ensure
|
144
|
+
_, status = Process.waitpid2(pid)
|
145
|
+
unless status.success?
|
146
|
+
code = 1
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
exit code
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
data/lib/rgot/common.rb
CHANGED
data/lib/rgot/m.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'stringio'
|
2
2
|
require 'etc'
|
3
|
+
require 'timeout'
|
3
4
|
|
4
5
|
module Rgot
|
5
6
|
class M
|
@@ -11,12 +12,8 @@ module Rgot
|
|
11
12
|
:thread,
|
12
13
|
); end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
raise ArgumentError, "missing keyword: tests" unless tests
|
17
|
-
raise ArgumentError, "missing keyword: benchmarks" unless benchmarks
|
18
|
-
raise ArgumentError, "missing keyword: examples" unless examples
|
19
|
-
cpu = opts.cpu || "#{Etc.respond_to?(:nprocessors) ? Etc.nprocessors : "1"}"
|
15
|
+
def initialize(tests:, benchmarks:, examples:, opts: Options.new)
|
16
|
+
cpu = opts.cpu || (Etc.respond_to?(:nprocessors) ? Etc.nprocessors : '1').to_s
|
20
17
|
@cpu_list = cpu.split(',').map { |i|
|
21
18
|
j = i.to_i
|
22
19
|
raise Rgot::OptionError, "invalid value #{i.inspect} for --cpu" unless 0 < j
|
@@ -37,15 +34,15 @@ module Rgot
|
|
37
34
|
test_ok = false
|
38
35
|
example_ok = false
|
39
36
|
|
40
|
-
Timeout.timeout(@opts.timeout.to_f)
|
37
|
+
Timeout.timeout(@opts.timeout.to_f) do
|
41
38
|
test_ok = run_tests
|
42
39
|
example_ok = run_examples
|
43
|
-
|
40
|
+
end
|
44
41
|
if !test_ok || !example_ok
|
45
42
|
puts "FAIL"
|
46
43
|
return 1
|
47
44
|
end
|
48
|
-
puts "PASS"
|
45
|
+
puts "PASS"
|
49
46
|
run_benchmarks
|
50
47
|
0
|
51
48
|
end
|
@@ -57,7 +54,7 @@ module Rgot
|
|
57
54
|
@tests.each do |test|
|
58
55
|
t = T.new(test.module, test.name.to_sym)
|
59
56
|
if Rgot.verbose?
|
60
|
-
puts "=== RUN
|
57
|
+
puts "=== RUN #{test.name}"
|
61
58
|
end
|
62
59
|
t.run
|
63
60
|
t.report
|
@@ -105,23 +102,30 @@ module Rgot
|
|
105
102
|
ok = true
|
106
103
|
@examples.each do |example|
|
107
104
|
if Rgot.verbose?
|
108
|
-
puts "=== RUN
|
105
|
+
puts "=== RUN #{example.name}"
|
109
106
|
end
|
107
|
+
|
108
|
+
start = Rgot.now
|
110
109
|
example.module.extend(example.module)
|
111
110
|
method = example.module.instance_method(example.name).bind(example.module)
|
112
|
-
out,
|
111
|
+
out, _ = capture do
|
113
112
|
method.call
|
114
113
|
end
|
115
114
|
file = method.source_location[0]
|
116
115
|
r = ExampleParser.new(File.read(file))
|
117
116
|
r.parse
|
118
|
-
e = r.examples.find{|
|
117
|
+
e = r.examples.find { |re| re.name == example.name }
|
118
|
+
|
119
|
+
duration = Rgot.now - start
|
119
120
|
if e && e.output.strip != out.strip
|
121
|
+
printf("--- FAIL: %s (%.2fs)\n", e.name, duration)
|
120
122
|
ok = false
|
121
123
|
puts "got:"
|
122
124
|
puts out.strip
|
123
125
|
puts "want:"
|
124
126
|
puts e.output.strip
|
127
|
+
elsif Rgot.verbose?
|
128
|
+
printf("--- PASS: %s (%.2fs)\n", e.name, duration)
|
125
129
|
end
|
126
130
|
end
|
127
131
|
ok
|
data/lib/rgot/pb.rb
CHANGED
data/lib/rgot/t.rb
CHANGED
@@ -8,19 +8,17 @@ module Rgot
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def run
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
raise e
|
18
|
-
end
|
11
|
+
catch(:skip) { call }
|
12
|
+
finish!
|
13
|
+
rescue => e
|
14
|
+
fail!
|
15
|
+
report
|
16
|
+
raise e
|
19
17
|
end
|
20
18
|
|
21
19
|
def report
|
22
20
|
duration = Rgot.now - @start
|
23
|
-
template = "--- %s: %s (%.
|
21
|
+
template = "--- %s: %s (%.2fs)\n%s"
|
24
22
|
if failed?
|
25
23
|
printf template, "FAIL", @name, duration, @output
|
26
24
|
elsif Rgot.verbose?
|
@@ -34,7 +32,7 @@ module Rgot
|
|
34
32
|
|
35
33
|
def call
|
36
34
|
test_method = @module.instance_method(@name).bind(@module)
|
37
|
-
if test_method.arity
|
35
|
+
if test_method.arity == 0
|
38
36
|
path, line = test_method.source_location
|
39
37
|
warn "#{path}:#{line} `#{test_method.name}' is not running. It's a testing method name, But not have argument"
|
40
38
|
else
|
data/lib/rgot/version.rb
CHANGED
data/lib/rgot.rb
CHANGED
@@ -8,33 +8,18 @@ module Rgot
|
|
8
8
|
require 'rgot/benchmark_result'
|
9
9
|
require 'rgot/example_parser'
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
class InternalBenchmark < Struct.new(:module, :name)
|
18
|
-
end
|
19
|
-
|
20
|
-
class InternalExample < Struct.new(:module, :name)
|
21
|
-
end
|
22
|
-
|
23
|
-
class ExampleOutput < Struct.new(:name, :output)
|
24
|
-
end
|
11
|
+
OptionError = Class.new(StandardError)
|
12
|
+
InternalTest = Struct.new(:module, :name)
|
13
|
+
InternalBenchmark = Struct.new(:module, :name)
|
14
|
+
InternalExample = Struct.new(:module, :name)
|
15
|
+
ExampleOutput = Struct.new(:name, :output)
|
25
16
|
|
26
17
|
class << self
|
27
|
-
|
28
|
-
|
29
|
-
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
30
|
-
end
|
31
|
-
else
|
32
|
-
def now
|
33
|
-
Time.now
|
34
|
-
end
|
18
|
+
def now
|
19
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
35
20
|
end
|
36
21
|
|
37
|
-
def benchmark(opts_hash={}, &block)
|
22
|
+
def benchmark(opts_hash = {}, &block)
|
38
23
|
opts = B::Options.new
|
39
24
|
opts_hash.each do |k, v|
|
40
25
|
opts[k] = v
|
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:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ksss
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -46,8 +46,8 @@ executables:
|
|
46
46
|
extensions: []
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
|
+
- ".github/workflows/main.yml"
|
49
50
|
- ".gitignore"
|
50
|
-
- ".travis.yml"
|
51
51
|
- Gemfile
|
52
52
|
- LICENSE.txt
|
53
53
|
- README.md
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- lib/rgot.rb
|
57
57
|
- lib/rgot/b.rb
|
58
58
|
- lib/rgot/benchmark_result.rb
|
59
|
+
- lib/rgot/cli.rb
|
59
60
|
- lib/rgot/common.rb
|
60
61
|
- lib/rgot/example_parser.rb
|
61
62
|
- lib/rgot/m.rb
|
@@ -67,7 +68,7 @@ homepage: https://github.com/ksss/rgot
|
|
67
68
|
licenses:
|
68
69
|
- MIT
|
69
70
|
metadata: {}
|
70
|
-
post_install_message:
|
71
|
+
post_install_message:
|
71
72
|
rdoc_options: []
|
72
73
|
require_paths:
|
73
74
|
- lib
|
@@ -82,9 +83,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
83
|
- !ruby/object:Gem::Version
|
83
84
|
version: '0'
|
84
85
|
requirements: []
|
85
|
-
|
86
|
-
|
87
|
-
signing_key:
|
86
|
+
rubygems_version: 3.4.0.dev
|
87
|
+
signing_key:
|
88
88
|
specification_version: 4
|
89
89
|
summary: Ruby + Golang Testing = Rgot
|
90
90
|
test_files: []
|