rgot 0.2.0 → 1.2.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 +29 -0
- data/.gitignore +0 -1
- data/Gemfile.lock +20 -0
- data/README.md +35 -5
- data/Rakefile +7 -2
- data/bin/rgot +2 -136
- data/lib/rgot/b.rb +2 -0
- data/lib/rgot/benchmark_result.rb +2 -0
- data/lib/rgot/cli.rb +157 -0
- data/lib/rgot/common.rb +5 -2
- data/lib/rgot/example_parser.rb +3 -1
- data/lib/rgot/m.rb +51 -19
- data/lib/rgot/pb.rb +2 -0
- data/lib/rgot/t.rb +8 -4
- data/lib/rgot/version.rb +3 -1
- data/lib/rgot.rb +10 -8
- data/rgot.gemspec +1 -1
- metadata +9 -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: 368b98f9969eee4d2608df53e668eaaed9f06320ecd5b26096ff05c0f81dc16e
|
4
|
+
data.tar.gz: b045a87ffcb3f18338ce0286e2f22b71921b5bab011e4049c203164b9ab7a077
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a3d443886aa26702be0720d8bdf8abf38dd938e3707d595ac1bf21b1edd0f3cb52f64f29e4ca11996357d8671bfaaa4edc94500560510b67c393244202a2db3
|
7
|
+
data.tar.gz: 13d8fcdf048c4c82da186f96dc7bfef3eb78a35fb5df04a2f6f17badda63100587df8cd175dc0618d823d613526b9e60aeec8e18cc09075c8bf3c8c218d58841
|
@@ -0,0 +1,29 @@
|
|
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.7.7'
|
18
|
+
- '3.0.5'
|
19
|
+
- '3.1.3'
|
20
|
+
|
21
|
+
steps:
|
22
|
+
- uses: actions/checkout@v3
|
23
|
+
- name: Set up Ruby
|
24
|
+
uses: ruby/setup-ruby@v1
|
25
|
+
with:
|
26
|
+
ruby-version: ${{ matrix.ruby }}
|
27
|
+
bundler-cache: true
|
28
|
+
- name: Run the default task
|
29
|
+
run: bundle exec rake
|
data/.gitignore
CHANGED
data/Gemfile.lock
ADDED
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
|
@@ -311,7 +341,7 @@ And this is default virtual main code.
|
|
311
341
|
```ruby
|
312
342
|
module TestSomeCode
|
313
343
|
def test_main(m)
|
314
|
-
|
344
|
+
m.run
|
315
345
|
end
|
316
346
|
end
|
317
347
|
```
|
@@ -332,7 +362,7 @@ module TestSomeCode
|
|
332
362
|
the_before_running_some_code
|
333
363
|
code = m.run
|
334
364
|
the_after_running_some_code
|
335
|
-
|
365
|
+
code
|
336
366
|
end
|
337
367
|
end
|
338
368
|
```
|
data/Rakefile
CHANGED
@@ -2,8 +2,13 @@ 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
|
+
"test/rgot_benchmark_test.rb",
|
9
|
+
"test/rgot_example_test.rb",
|
10
|
+
]
|
11
|
+
ruby "bin/rgot -v #{targets.join(' ')}"
|
7
12
|
end
|
8
13
|
|
9
14
|
task :default => [:test]
|
data/bin/rgot
CHANGED
@@ -1,138 +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 #{Rgot::VERSION} (ruby #{RUBY_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
|
-
testing_files = []
|
46
|
-
|
47
|
-
if ARGV.empty?
|
48
|
-
Dir.glob("./**/*_test.rb") do |i|
|
49
|
-
testing_files << i
|
50
|
-
end
|
51
|
-
else
|
52
|
-
ARGV.each do |target|
|
53
|
-
if File.file?(target)
|
54
|
-
testing_files << File.expand_path(target)
|
55
|
-
elsif File.directory?(target)
|
56
|
-
Dir.glob("./#{target}/**/*_test.rb") do |i|
|
57
|
-
testing_files << i
|
58
|
-
end
|
59
|
-
else
|
60
|
-
puts target
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
code = 0
|
66
|
-
testing_files.each do |testing_file|
|
67
|
-
begin
|
68
|
-
pid = fork do
|
69
|
-
require testing_file
|
70
|
-
|
71
|
-
modules = Object.constants.select { |c|
|
72
|
-
next if c == :FileTest
|
73
|
-
/.*Test\z/ =~ c
|
74
|
-
}.map { |c|
|
75
|
-
Object.const_get(c)
|
76
|
-
}
|
77
|
-
|
78
|
-
modules.each do |test_module|
|
79
|
-
tests = []
|
80
|
-
benchmarks = []
|
81
|
-
examples = []
|
82
|
-
main = nil
|
83
|
-
methods = test_module.instance_methods
|
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 do
|
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 "exit status #{$!.status}"
|
112
|
-
puts sprintf(template, "FAIL", test_module, Rgot.now - duration)
|
113
|
-
end
|
114
|
-
when NilClass
|
115
|
-
# not raise, not exit
|
116
|
-
else
|
117
|
-
# any exception
|
118
|
-
puts sprintf(template, "FAIL", test_module, Rgot.now - duration)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
m = Rgot::M.new(tests: tests, benchmarks: benchmarks, examples: examples, opts: opts)
|
122
|
-
if main
|
123
|
-
main.module.extend main.module
|
124
|
-
main.module.instance_method(main.name).bind(main.module).call(m)
|
125
|
-
else
|
126
|
-
exit m.run
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
ensure
|
131
|
-
_, status = Process.waitpid2(pid)
|
132
|
-
unless status.success?
|
133
|
-
code = 1
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
exit code
|
4
|
+
exit Rgot::Cli.new(ARGV).run
|
data/lib/rgot/b.rb
CHANGED
data/lib/rgot/cli.rb
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
require_relative '../rgot'
|
6
|
+
|
7
|
+
module Rgot
|
8
|
+
class Cli
|
9
|
+
def initialize(argv)
|
10
|
+
@argv = argv
|
11
|
+
end
|
12
|
+
|
13
|
+
def run
|
14
|
+
opts = Rgot::M::Options.new
|
15
|
+
parse_option(opts)
|
16
|
+
main_process(opts)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def parse_option(opts)
|
22
|
+
require_paths = []
|
23
|
+
parser = OptionParser.new do |o|
|
24
|
+
o.on '-v', '--verbose', "log all tests" do |arg|
|
25
|
+
Rgot.class_eval { @chatty = arg }
|
26
|
+
end
|
27
|
+
o.on '--version', "show Rgot version" do |arg|
|
28
|
+
puts "rgot #{Rgot::VERSION} (ruby #{RUBY_VERSION})"
|
29
|
+
exit 0
|
30
|
+
end
|
31
|
+
o.on '--bench [regexp]', "benchmark" do |arg|
|
32
|
+
unless arg
|
33
|
+
raise Rgot::OptionError, "missing argument for flag --bench"
|
34
|
+
end
|
35
|
+
opts.bench = arg
|
36
|
+
end
|
37
|
+
o.on '--benchtime [sec]', "benchmark running time" do |arg|
|
38
|
+
opts.benchtime = arg
|
39
|
+
end
|
40
|
+
o.on '--timeout [sec]', "set timeout sec to testing" do |arg|
|
41
|
+
opts.timeout = arg
|
42
|
+
end
|
43
|
+
o.on '--cpu [count,...]', "set cpu counts of comma split" do |arg|
|
44
|
+
opts.cpu = arg
|
45
|
+
end
|
46
|
+
o.on '--thread [count,...]', "set thread counts of comma split" do |arg|
|
47
|
+
opts.thread = arg
|
48
|
+
end
|
49
|
+
o.on '--require [path]', "load some code before running" do |arg|
|
50
|
+
require_paths << arg
|
51
|
+
end
|
52
|
+
o.on '--load-path [path]', "Specify $LOAD_PATH directory" do |arg|
|
53
|
+
$LOAD_PATH.unshift(arg)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
parser.parse!(@argv)
|
57
|
+
|
58
|
+
require_paths.each do |path|
|
59
|
+
require path
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def testing_files
|
64
|
+
if @argv.empty?
|
65
|
+
Dir.glob("./**/*_test.rb")
|
66
|
+
else
|
67
|
+
@argv.flat_map do |target|
|
68
|
+
if File.file?(target)
|
69
|
+
File.expand_path(target)
|
70
|
+
elsif File.directory?(target)
|
71
|
+
Dir.glob("./#{target}/**/*_test.rb")
|
72
|
+
else
|
73
|
+
warn "#{target} is not file or directory"
|
74
|
+
end
|
75
|
+
end.compact
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def main_process(opts)
|
80
|
+
code = 0
|
81
|
+
|
82
|
+
testing_files.each do |testing_file|
|
83
|
+
result = child_process(opts, testing_file)
|
84
|
+
unless result == 0
|
85
|
+
code = 1
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
code
|
90
|
+
end
|
91
|
+
|
92
|
+
def child_process(opts, testing_file)
|
93
|
+
node = RubyVM::AbstractSyntaxTree.parse_file(testing_file).children[2]
|
94
|
+
test_module_name = find_toplevel_name(node)
|
95
|
+
|
96
|
+
load testing_file
|
97
|
+
|
98
|
+
test_module = Object.const_get(test_module_name)
|
99
|
+
tests = []
|
100
|
+
benchmarks = []
|
101
|
+
examples = []
|
102
|
+
main = nil
|
103
|
+
methods = test_module.public_instance_methods
|
104
|
+
methods.grep(/\Atest_/).each do |m|
|
105
|
+
if m == :test_main && main.nil?
|
106
|
+
main = Rgot::InternalTest.new(test_module, m)
|
107
|
+
else
|
108
|
+
tests << Rgot::InternalTest.new(test_module, m)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
methods.grep(/\Abenchmark_/).each do |m|
|
113
|
+
benchmarks << Rgot::InternalBenchmark.new(test_module, m)
|
114
|
+
end
|
115
|
+
|
116
|
+
methods.grep(/\Aexample_?/).each do |m|
|
117
|
+
examples << Rgot::InternalExample.new(test_module, m)
|
118
|
+
end
|
119
|
+
|
120
|
+
m = Rgot::M.new(test_module: test_module, tests: tests, benchmarks: benchmarks, examples: examples, opts: opts)
|
121
|
+
if main
|
122
|
+
main.module.extend main.module
|
123
|
+
main.module.instance_method(:test_main).bind(main.module).call(m)
|
124
|
+
else
|
125
|
+
m.run
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
private
|
130
|
+
|
131
|
+
def find_toplevel_name(node)
|
132
|
+
case node.type
|
133
|
+
when :MODULE
|
134
|
+
find_toplevel_name(node.children.first)
|
135
|
+
when :CONST, :COLON3
|
136
|
+
node.children.first
|
137
|
+
when :COLON2
|
138
|
+
case node.children
|
139
|
+
in [nil, sym]
|
140
|
+
# module Foo
|
141
|
+
sym
|
142
|
+
in [namespace, sym]
|
143
|
+
# module Foo::Bar
|
144
|
+
find_toplevel_name(namespace)
|
145
|
+
end
|
146
|
+
when :BLOCK
|
147
|
+
module_node = node.children.find { |c| c.type == :MODULE }
|
148
|
+
unless module_node
|
149
|
+
raise "no module found"
|
150
|
+
end
|
151
|
+
find_toplevel_name(module_node)
|
152
|
+
else
|
153
|
+
raise node.type.to_s
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
data/lib/rgot/common.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'thread'
|
2
4
|
require 'pathname'
|
3
5
|
|
@@ -6,7 +8,7 @@ module Rgot
|
|
6
8
|
attr_accessor :output
|
7
9
|
|
8
10
|
def initialize
|
9
|
-
@output = ""
|
11
|
+
@output = "".dup
|
10
12
|
@failed = false
|
11
13
|
@skipped = false
|
12
14
|
@finished = false
|
@@ -100,7 +102,8 @@ module Rgot
|
|
100
102
|
path = c.sub(/:.*/, '')
|
101
103
|
line = c.match(/:(\d+?):/)[1]
|
102
104
|
relative_path = Pathname.new(path).relative_path_from(Pathname.new(Dir.pwd)).to_s
|
103
|
-
|
105
|
+
# Every line is indented at least 4 spaces.
|
106
|
+
" #{relative_path}:#{line}: #{str}\n"
|
104
107
|
end
|
105
108
|
|
106
109
|
def internal_log(msg)
|
data/lib/rgot/example_parser.rb
CHANGED
data/lib/rgot/m.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'stringio'
|
2
4
|
require 'etc'
|
3
5
|
require 'timeout'
|
@@ -12,43 +14,74 @@ module Rgot
|
|
12
14
|
:thread,
|
13
15
|
); end
|
14
16
|
|
15
|
-
def initialize(tests:, benchmarks:, examples:, opts: Options.new)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
}
|
22
|
-
@thread_list = (opts.thread || "1").split(',').map { |i|
|
23
|
-
j = i.to_i
|
24
|
-
raise Rgot::OptionError, "invalid value #{i.inspect} for --thread" unless 0 < j
|
25
|
-
j
|
26
|
-
}
|
17
|
+
def initialize(tests:, benchmarks:, examples:, test_module: nil, opts: Options.new)
|
18
|
+
unless test_module
|
19
|
+
raise "Require `test_module` keyword" if Gem::Version.new("2.0") <= Gem::Version.new(Rgot::VERSION)
|
20
|
+
warn "`Rgot::M#initialize` will require the `test_module` keyword in the next major version."
|
21
|
+
end
|
22
|
+
|
27
23
|
@tests = tests
|
28
24
|
@benchmarks = benchmarks
|
29
25
|
@examples = examples
|
26
|
+
@test_module = test_module
|
30
27
|
@opts = opts
|
28
|
+
@cpu_list = nil
|
29
|
+
@thread_list = nil
|
31
30
|
end
|
32
31
|
|
33
32
|
def run
|
33
|
+
duration = Rgot.now
|
34
34
|
test_ok = false
|
35
35
|
example_ok = false
|
36
36
|
|
37
|
+
if @tests.empty? && @benchmarks.empty? && @examples.empty?
|
38
|
+
warn "rgot: warning: no tests to run"
|
39
|
+
end
|
40
|
+
|
41
|
+
begin
|
42
|
+
parse_option
|
43
|
+
rescue Rgot::OptionError
|
44
|
+
puts sprintf("%s\t%s\t%.3fs", "FAIL", @test_module, Rgot.now - duration)
|
45
|
+
raise
|
46
|
+
end
|
47
|
+
|
37
48
|
Timeout.timeout(@opts.timeout.to_f) do
|
38
49
|
test_ok = run_tests
|
39
50
|
example_ok = run_examples
|
40
51
|
end
|
52
|
+
|
41
53
|
if !test_ok || !example_ok
|
42
54
|
puts "FAIL"
|
43
|
-
|
55
|
+
puts "exit status 1"
|
56
|
+
puts sprintf("%s\t%s\t%.3fs", "FAIL", @test_module, Rgot.now - duration)
|
57
|
+
|
58
|
+
1
|
59
|
+
else
|
60
|
+
puts "PASS"
|
61
|
+
run_benchmarks
|
62
|
+
puts sprintf("%s\t%s\t%.3fs", "ok ", @test_module, Rgot.now - duration)
|
63
|
+
|
64
|
+
0
|
44
65
|
end
|
45
|
-
puts "PASS"
|
46
|
-
run_benchmarks
|
47
|
-
0
|
48
66
|
end
|
49
67
|
|
50
68
|
private
|
51
69
|
|
70
|
+
def parse_option
|
71
|
+
cpu = @opts.cpu || (Etc.respond_to?(:nprocessors) ? Etc.nprocessors : '1').to_s
|
72
|
+
@cpu_list = cpu.split(',').map { |i|
|
73
|
+
j = i.to_i
|
74
|
+
raise Rgot::OptionError, "invalid value #{i.inspect} for --cpu" unless 0 < j
|
75
|
+
j
|
76
|
+
}
|
77
|
+
|
78
|
+
@thread_list = (@opts.thread || "1").split(',').map { |i|
|
79
|
+
j = i.to_i
|
80
|
+
raise Rgot::OptionError, "invalid value #{i.inspect} for --thread" unless 0 < j
|
81
|
+
j
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
52
85
|
def run_tests
|
53
86
|
ok = true
|
54
87
|
@tests.each do |test|
|
@@ -57,7 +90,6 @@ module Rgot
|
|
57
90
|
puts "=== RUN #{test.name}"
|
58
91
|
end
|
59
92
|
t.run
|
60
|
-
t.report
|
61
93
|
if t.failed?
|
62
94
|
ok = false
|
63
95
|
end
|
@@ -108,13 +140,13 @@ module Rgot
|
|
108
140
|
start = Rgot.now
|
109
141
|
example.module.extend(example.module)
|
110
142
|
method = example.module.instance_method(example.name).bind(example.module)
|
111
|
-
out,
|
143
|
+
out, _ = capture do
|
112
144
|
method.call
|
113
145
|
end
|
114
146
|
file = method.source_location[0]
|
115
147
|
r = ExampleParser.new(File.read(file))
|
116
148
|
r.parse
|
117
|
-
e = r.examples.find { |
|
149
|
+
e = r.examples.find { |re| re.name == example.name }
|
118
150
|
|
119
151
|
duration = Rgot.now - start
|
120
152
|
if e && e.output.strip != out.strip
|
data/lib/rgot/pb.rb
CHANGED
data/lib/rgot/t.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Rgot
|
2
4
|
class T < Common
|
3
5
|
def initialize(test_module, name)
|
@@ -10,6 +12,7 @@ module Rgot
|
|
10
12
|
def run
|
11
13
|
catch(:skip) { call }
|
12
14
|
finish!
|
15
|
+
report
|
13
16
|
rescue => e
|
14
17
|
fail!
|
15
18
|
report
|
@@ -17,15 +20,16 @@ module Rgot
|
|
17
20
|
end
|
18
21
|
|
19
22
|
def report
|
23
|
+
puts @output if Rgot.verbose? && !@output.empty?
|
20
24
|
duration = Rgot.now - @start
|
21
|
-
template = "--- %s: %s (%.2fs)\n
|
25
|
+
template = "--- \e[%sm%s\e[m: %s (%.2fs)\n"
|
22
26
|
if failed?
|
23
|
-
printf template, "FAIL", @name, duration
|
27
|
+
printf template, [41, 1].join(';'), "FAIL", @name, duration
|
24
28
|
elsif Rgot.verbose?
|
25
29
|
if skipped?
|
26
|
-
printf template, "SKIP", @name, duration
|
30
|
+
printf template, [44, 1].join(';'), "SKIP", @name, duration
|
27
31
|
else
|
28
|
-
printf template, "PASS", @name, duration
|
32
|
+
printf template, [42, 1].join(';'), "PASS", @name, duration
|
29
33
|
end
|
30
34
|
end
|
31
35
|
end
|
data/lib/rgot/version.rb
CHANGED
data/lib/rgot.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Rgot
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
autoload :VERSION, 'rgot/version'
|
5
|
+
autoload :Common, 'rgot/common'
|
6
|
+
autoload :M, 'rgot/m'
|
7
|
+
autoload :T, 'rgot/t'
|
8
|
+
autoload :B, 'rgot/b'
|
9
|
+
autoload :PB, 'rgot/pb'
|
10
|
+
autoload :BenchmarkResult, 'rgot/benchmark_result'
|
11
|
+
autoload :ExampleParser, 'rgot/example_parser'
|
10
12
|
|
11
13
|
OptionError = Class.new(StandardError)
|
12
14
|
InternalTest = Struct.new(:module, :name)
|
data/rgot.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.homepage = "https://github.com/ksss/rgot"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|go)/}) }
|
18
18
|
spec.bindir = "bin"
|
19
19
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
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.2.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-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -46,9 +46,10 @@ 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
|
+
- Gemfile.lock
|
52
53
|
- LICENSE.txt
|
53
54
|
- README.md
|
54
55
|
- Rakefile
|
@@ -56,6 +57,7 @@ files:
|
|
56
57
|
- lib/rgot.rb
|
57
58
|
- lib/rgot/b.rb
|
58
59
|
- lib/rgot/benchmark_result.rb
|
60
|
+
- lib/rgot/cli.rb
|
59
61
|
- lib/rgot/common.rb
|
60
62
|
- lib/rgot/example_parser.rb
|
61
63
|
- lib/rgot/m.rb
|
@@ -67,7 +69,7 @@ homepage: https://github.com/ksss/rgot
|
|
67
69
|
licenses:
|
68
70
|
- MIT
|
69
71
|
metadata: {}
|
70
|
-
post_install_message:
|
72
|
+
post_install_message:
|
71
73
|
rdoc_options: []
|
72
74
|
require_paths:
|
73
75
|
- lib
|
@@ -82,9 +84,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
84
|
- !ruby/object:Gem::Version
|
83
85
|
version: '0'
|
84
86
|
requirements: []
|
85
|
-
|
86
|
-
|
87
|
-
signing_key:
|
87
|
+
rubygems_version: 3.3.26
|
88
|
+
signing_key:
|
88
89
|
specification_version: 4
|
89
90
|
summary: Ruby + Golang Testing = Rgot
|
90
91
|
test_files: []
|