judges 0.17.0 → 0.18.1
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/.github/workflows/copyrights.yml +1 -1
- data/.rubocop.yml +2 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +8 -1
- data/README.md +5 -0
- data/features/test.feature +23 -0
- data/judges.gemspec +1 -1
- data/lib/judges/baza.rb +28 -3
- data/lib/judges/commands/eval.rb +5 -1
- data/lib/judges/commands/import.rb +5 -1
- data/lib/judges/commands/inspect.rb +5 -1
- data/lib/judges/commands/join.rb +5 -1
- data/lib/judges/commands/print.rb +5 -1
- data/lib/judges/commands/pull.rb +10 -5
- data/lib/judges/commands/push.rb +5 -1
- data/lib/judges/commands/test.rb +33 -18
- data/lib/judges/commands/trim.rb +5 -1
- data/lib/judges/commands/update.rb +5 -1
- data/lib/judges/judges.rb +10 -2
- data/lib/judges.rb +1 -1
- data/test/commands/test_test.rb +26 -0
- data/test/test__helper.rb +3 -0
- data/test/test_judges.rb +11 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8830243b63e62d966d91e5d59b768039df5da4441d83b1ba0c89fb920a782d36
|
|
4
|
+
data.tar.gz: 9f4fbc2cbe61760e6931f193cb92dd2fd764953ed7598c004476ed29de0e2e94
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1843faa46e6a55657226e8a34d32242e069bff03325330ca48ec6026ecefe792781f2647dce0c1fe3c0f21e9e139f23e32d0402ddc8a9b2045b12e8edac0c570
|
|
7
|
+
data.tar.gz: e94b241263ce9b6fd1891312b38359481567ea9568fe76c0143d6680a8f4cab231ee46adc0ebca0c0b2a193c01a38991a74c874cab0798c47b5d38b23ada96b7
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
|
@@ -25,6 +25,7 @@ gemspec
|
|
|
25
25
|
|
|
26
26
|
gem 'cucumber', '9.2.0', require: false
|
|
27
27
|
gem 'minitest', '5.24.1', require: false
|
|
28
|
+
gem 'minitest-reporters', '1.7.1', require: false
|
|
28
29
|
gem 'net-ping', '2.0.8', require: false
|
|
29
30
|
gem 'rake', '13.2.1', require: false
|
|
30
31
|
gem 'random-port', '~>0.0', require: false
|
data/Gemfile.lock
CHANGED
|
@@ -46,6 +46,7 @@ GEM
|
|
|
46
46
|
tzinfo (~> 2.0)
|
|
47
47
|
addressable (2.8.7)
|
|
48
48
|
public_suffix (>= 2.0.2, < 7.0)
|
|
49
|
+
ansi (1.5.0)
|
|
49
50
|
ast (2.4.2)
|
|
50
51
|
backtrace (0.4.0)
|
|
51
52
|
base64 (0.2.0)
|
|
@@ -122,6 +123,11 @@ GEM
|
|
|
122
123
|
loog (0.5.2)
|
|
123
124
|
mini_mime (1.1.5)
|
|
124
125
|
minitest (5.24.1)
|
|
126
|
+
minitest-reporters (1.7.1)
|
|
127
|
+
ansi
|
|
128
|
+
builder
|
|
129
|
+
minitest (>= 5.0)
|
|
130
|
+
ruby-progressbar
|
|
125
131
|
moments (0.3.0)
|
|
126
132
|
multi_test (1.1.0)
|
|
127
133
|
mutex_m (0.2.0)
|
|
@@ -174,7 +180,7 @@ GEM
|
|
|
174
180
|
zeitwerk (~> 2.6)
|
|
175
181
|
rainbow (3.1.1)
|
|
176
182
|
rake (13.2.1)
|
|
177
|
-
random-port (0.7.
|
|
183
|
+
random-port (0.7.1)
|
|
178
184
|
rdoc (6.7.0)
|
|
179
185
|
psych (>= 4.0.0)
|
|
180
186
|
regexp_parser (2.9.2)
|
|
@@ -261,6 +267,7 @@ DEPENDENCIES
|
|
|
261
267
|
cucumber (= 9.2.0)
|
|
262
268
|
judges!
|
|
263
269
|
minitest (= 5.24.1)
|
|
270
|
+
minitest-reporters (= 1.7.1)
|
|
264
271
|
net-ping (= 2.0.8)
|
|
265
272
|
rake (= 13.2.1)
|
|
266
273
|
random-port (~> 0.0)
|
data/README.md
CHANGED
|
@@ -34,6 +34,8 @@ global variables available to it:
|
|
|
34
34
|
Every `.yml` file must be formatted as such:
|
|
35
35
|
|
|
36
36
|
```yaml
|
|
37
|
+
before:
|
|
38
|
+
- abc
|
|
37
39
|
category: slow
|
|
38
40
|
runs: 1
|
|
39
41
|
skip: false
|
|
@@ -60,6 +62,9 @@ which then may be turned on via the `--category` command line flag.
|
|
|
60
62
|
The `runs` (default: `1`) is the number of times the `.rb` script should
|
|
61
63
|
be executed. After each execution, all expected XPath expressions are validated.
|
|
62
64
|
|
|
65
|
+
The `before` (default: `[]`) is a list of judges that must be executed before
|
|
66
|
+
the current one.
|
|
67
|
+
|
|
63
68
|
## How to contribute
|
|
64
69
|
|
|
65
70
|
Read
|
data/features/test.feature
CHANGED
|
@@ -118,3 +118,26 @@ Feature: Test
|
|
|
118
118
|
Then I run bin/judges with "test --enable bad mine"
|
|
119
119
|
Then Stdout contains "Testing mine/bad/bad.yml"
|
|
120
120
|
And Exit code is not zero
|
|
121
|
+
|
|
122
|
+
Scenario: Test with a pre-condition
|
|
123
|
+
Given I make a temp directory
|
|
124
|
+
Then I have a "mine/first/first.rb" file with content:
|
|
125
|
+
"""
|
|
126
|
+
n = $fb.insert
|
|
127
|
+
n.foo = 42
|
|
128
|
+
"""
|
|
129
|
+
Then I have a "mine/second/second.rb" file with content:
|
|
130
|
+
"""
|
|
131
|
+
n = $fb.insert
|
|
132
|
+
n.foo = 55
|
|
133
|
+
"""
|
|
134
|
+
Then I have a "mine/second/second.yml" file with content:
|
|
135
|
+
"""
|
|
136
|
+
---
|
|
137
|
+
before:
|
|
138
|
+
- first
|
|
139
|
+
expected:
|
|
140
|
+
- /fb[count(f)=2]
|
|
141
|
+
"""
|
|
142
|
+
Then I run bin/judges with "test mine"
|
|
143
|
+
And Exit code is zero
|
data/judges.gemspec
CHANGED
|
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
|
|
|
26
26
|
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
|
27
27
|
s.required_ruby_version = '>=3.2'
|
|
28
28
|
s.name = 'judges'
|
|
29
|
-
s.version = '0.
|
|
29
|
+
s.version = '0.18.1'
|
|
30
30
|
s.license = 'MIT'
|
|
31
31
|
s.summary = 'Command-Line Tool for a Factbase'
|
|
32
32
|
s.description =
|
data/lib/judges/baza.rb
CHANGED
|
@@ -28,14 +28,17 @@ require 'base64'
|
|
|
28
28
|
require_relative '../judges'
|
|
29
29
|
require_relative '../judges/elapsed'
|
|
30
30
|
|
|
31
|
-
#
|
|
31
|
+
# Interface to the API of zerocracy.com.
|
|
32
|
+
#
|
|
33
|
+
# You make an instance of this class and then call one of its methods.
|
|
34
|
+
# The object will make HTTP request to www.zerocracy.com and interpret the
|
|
35
|
+
# results returned.
|
|
36
|
+
#
|
|
32
37
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
33
38
|
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
|
34
39
|
# License:: MIT
|
|
35
40
|
class Judges::Baza
|
|
36
|
-
# rubocop:disable Metrics/ParameterLists
|
|
37
41
|
def initialize(host, port, token, ssl: true, timeout: 30, retries: 3, loog: Loog::NULL)
|
|
38
|
-
# rubocop:enable Metrics/ParameterLists
|
|
39
42
|
@host = host
|
|
40
43
|
@port = port
|
|
41
44
|
@ssl = ssl
|
|
@@ -45,6 +48,11 @@ class Judges::Baza
|
|
|
45
48
|
@retries = retries
|
|
46
49
|
end
|
|
47
50
|
|
|
51
|
+
# Push factbase to the server.
|
|
52
|
+
# @param [String] name The name of the job on the server
|
|
53
|
+
# @param [Bytes] data The data to push to the server (binary)
|
|
54
|
+
# @param [Array<String>] meta List of metas, possibly empty
|
|
55
|
+
# @return [Integer] Job ID on the server
|
|
48
56
|
def push(name, data, meta)
|
|
49
57
|
id = 0
|
|
50
58
|
hdrs = headers.merge(
|
|
@@ -72,6 +80,9 @@ class Judges::Baza
|
|
|
72
80
|
id
|
|
73
81
|
end
|
|
74
82
|
|
|
83
|
+
# Pull factbase from the server.
|
|
84
|
+
# @param [Integer] id The ID of the job on the server
|
|
85
|
+
# @return [Bytes] Binary data pulled
|
|
75
86
|
def pull(id)
|
|
76
87
|
data = 0
|
|
77
88
|
elapsed(@loog) do
|
|
@@ -101,6 +112,8 @@ class Judges::Baza
|
|
|
101
112
|
end
|
|
102
113
|
|
|
103
114
|
# The job with this ID is finished already?
|
|
115
|
+
# @param [Integer] id The ID of the job on the server
|
|
116
|
+
# @return [Boolean] TRUE if the job is already finished
|
|
104
117
|
def finished?(id)
|
|
105
118
|
finished = false
|
|
106
119
|
elapsed(@loog) do
|
|
@@ -119,6 +132,8 @@ class Judges::Baza
|
|
|
119
132
|
end
|
|
120
133
|
|
|
121
134
|
# Lock the name.
|
|
135
|
+
# @param [String] name The name of the job on the server
|
|
136
|
+
# @param [String] owner The owner of the lock (any string)
|
|
122
137
|
def lock(name, owner)
|
|
123
138
|
elapsed(@loog) do
|
|
124
139
|
with_retries(max_tries: @retries) do
|
|
@@ -134,6 +149,8 @@ class Judges::Baza
|
|
|
134
149
|
end
|
|
135
150
|
|
|
136
151
|
# Unlock the name.
|
|
152
|
+
# @param [String] name The name of the job on the server
|
|
153
|
+
# @param [String] owner The owner of the lock (any string)
|
|
137
154
|
def unlock(name, owner)
|
|
138
155
|
elapsed(@loog) do
|
|
139
156
|
with_retries(max_tries: @retries) do
|
|
@@ -148,6 +165,9 @@ class Judges::Baza
|
|
|
148
165
|
end
|
|
149
166
|
end
|
|
150
167
|
|
|
168
|
+
# Get the ID of the job by the name.
|
|
169
|
+
# @param [String] name The name of the job on the server
|
|
170
|
+
# @return [Integer] The ID of the job on the server
|
|
151
171
|
def recent(name)
|
|
152
172
|
job = 0
|
|
153
173
|
elapsed(@loog) do
|
|
@@ -165,6 +185,9 @@ class Judges::Baza
|
|
|
165
185
|
job
|
|
166
186
|
end
|
|
167
187
|
|
|
188
|
+
# Check whether the name of the job exists on the server.
|
|
189
|
+
# @param [String] name The name of the job on the server
|
|
190
|
+
# @return [Boolean] TRUE if such name exists
|
|
168
191
|
def name_exists?(name)
|
|
169
192
|
exists = 0
|
|
170
193
|
elapsed(@loog) do
|
|
@@ -225,6 +248,8 @@ class Judges::Baza
|
|
|
225
248
|
msg +=
|
|
226
249
|
', most probably you are trying to reach a wrong server, which doesn\'t ' \
|
|
227
250
|
'have the URL that it is expected to have'
|
|
251
|
+
when 0
|
|
252
|
+
msg += ', most likely an internal error'
|
|
228
253
|
end
|
|
229
254
|
raise msg
|
|
230
255
|
end
|
data/lib/judges/commands/eval.rb
CHANGED
|
@@ -25,7 +25,11 @@ require_relative '../../judges'
|
|
|
25
25
|
require_relative '../../judges/impex'
|
|
26
26
|
require_relative '../../judges/elapsed'
|
|
27
27
|
|
|
28
|
-
#
|
|
28
|
+
# The +eval+ command.
|
|
29
|
+
#
|
|
30
|
+
# This class is instantiated by the +bin/judge+ command line interface. You
|
|
31
|
+
# are not supposed to instantiate it yourself.
|
|
32
|
+
#
|
|
29
33
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
30
34
|
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
|
31
35
|
# License:: MIT
|
|
@@ -27,7 +27,11 @@ require_relative '../../judges/impex'
|
|
|
27
27
|
require_relative '../../judges/to_rel'
|
|
28
28
|
require_relative '../../judges/elapsed'
|
|
29
29
|
|
|
30
|
-
#
|
|
30
|
+
# The +import+ command.
|
|
31
|
+
#
|
|
32
|
+
# This class is instantiated by the +bin/judge+ command line interface. You
|
|
33
|
+
# are not supposed to instantiate it yourself.
|
|
34
|
+
#
|
|
31
35
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
32
36
|
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
|
33
37
|
# License:: MIT
|
|
@@ -23,7 +23,11 @@
|
|
|
23
23
|
require_relative '../../judges'
|
|
24
24
|
require_relative '../../judges/impex'
|
|
25
25
|
|
|
26
|
-
#
|
|
26
|
+
# The +inspect+ command.
|
|
27
|
+
#
|
|
28
|
+
# This class is instantiated by the +bin/judge+ command line interface. You
|
|
29
|
+
# are not supposed to instantiate it yourself.
|
|
30
|
+
#
|
|
27
31
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
28
32
|
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
|
29
33
|
# License:: MIT
|
data/lib/judges/commands/join.rb
CHANGED
|
@@ -24,7 +24,11 @@ require_relative '../../judges'
|
|
|
24
24
|
require_relative '../../judges/impex'
|
|
25
25
|
require_relative '../../judges/elapsed'
|
|
26
26
|
|
|
27
|
-
#
|
|
27
|
+
# The +join+ command.
|
|
28
|
+
#
|
|
29
|
+
# This class is instantiated by the +bin/judge+ command line interface. You
|
|
30
|
+
# are not supposed to instantiate it yourself.
|
|
31
|
+
#
|
|
28
32
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
29
33
|
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
|
30
34
|
# License:: MIT
|
|
@@ -28,7 +28,11 @@ require_relative '../../judges'
|
|
|
28
28
|
require_relative '../../judges/impex'
|
|
29
29
|
require_relative '../../judges/elapsed'
|
|
30
30
|
|
|
31
|
-
#
|
|
31
|
+
# The +print+ command.
|
|
32
|
+
#
|
|
33
|
+
# This class is instantiated by the +bin/judge+ command line interface. You
|
|
34
|
+
# are not supposed to instantiate it yourself.
|
|
35
|
+
#
|
|
32
36
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
33
37
|
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
|
34
38
|
# License:: MIT
|
data/lib/judges/commands/pull.rb
CHANGED
|
@@ -26,7 +26,11 @@ require_relative '../../judges'
|
|
|
26
26
|
require_relative '../../judges/impex'
|
|
27
27
|
require_relative '../../judges/baza'
|
|
28
28
|
|
|
29
|
-
#
|
|
29
|
+
# The +pull+ command.
|
|
30
|
+
#
|
|
31
|
+
# This class is instantiated by the +bin/judge+ command line interface. You
|
|
32
|
+
# are not supposed to instantiate it yourself.
|
|
33
|
+
#
|
|
30
34
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
31
35
|
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
|
32
36
|
# License:: MIT
|
|
@@ -49,7 +53,7 @@ class Judges::Pull
|
|
|
49
53
|
elapsed(@loog) do
|
|
50
54
|
if baza.name_exists?(name)
|
|
51
55
|
baza.lock(name, opts['owner'])
|
|
52
|
-
fb.import(baza.pull(wait(baza, baza.recent(name), opts['wait'])))
|
|
56
|
+
fb.import(baza.pull(wait(name, baza, baza.recent(name), opts['wait'])))
|
|
53
57
|
Judges::Impex.new(@loog, args[1]).export(fb)
|
|
54
58
|
throw :"Pulled #{fb.size} facts by the name '#{name}'"
|
|
55
59
|
else
|
|
@@ -60,14 +64,15 @@ class Judges::Pull
|
|
|
60
64
|
|
|
61
65
|
private
|
|
62
66
|
|
|
63
|
-
def wait(baza, id, limit)
|
|
67
|
+
def wait(name, baza, id, limit)
|
|
64
68
|
raise 'Waiting time is nil' if limit.nil?
|
|
65
69
|
start = Time.now
|
|
66
70
|
loop do
|
|
67
71
|
break if baza.finished?(id)
|
|
68
72
|
sleep 1
|
|
69
|
-
raise
|
|
70
|
-
|
|
73
|
+
raise "Time is over, the job ##{id} ('#{name}') is still not finished" if Time.now - start > limit
|
|
74
|
+
lapsed = Time.now - start
|
|
75
|
+
@loog.debug("Still waiting for the job ##{id} ('#{name}') to finish... (#{format('%.2f', lapsed)}s already)")
|
|
71
76
|
end
|
|
72
77
|
id
|
|
73
78
|
end
|
data/lib/judges/commands/push.rb
CHANGED
|
@@ -26,7 +26,11 @@ require_relative '../../judges'
|
|
|
26
26
|
require_relative '../../judges/impex'
|
|
27
27
|
require_relative '../../judges/baza'
|
|
28
28
|
|
|
29
|
-
#
|
|
29
|
+
# The +push+ command.
|
|
30
|
+
#
|
|
31
|
+
# This class is instantiated by the +bin/judge+ command line interface. You
|
|
32
|
+
# are not supposed to instantiate it yourself.
|
|
33
|
+
#
|
|
30
34
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
31
35
|
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
|
32
36
|
# License:: MIT
|
data/lib/judges/commands/test.rb
CHANGED
|
@@ -32,7 +32,11 @@ require_relative '../../judges/options'
|
|
|
32
32
|
require_relative '../../judges/categories'
|
|
33
33
|
require_relative '../../judges/elapsed'
|
|
34
34
|
|
|
35
|
-
#
|
|
35
|
+
# The +test+ command.
|
|
36
|
+
#
|
|
37
|
+
# This class is instantiated by the +bin/judge+ command line interface. You
|
|
38
|
+
# are not supposed to instantiate it yourself.
|
|
39
|
+
#
|
|
36
40
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
37
41
|
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
|
38
42
|
# License:: MIT
|
|
@@ -46,18 +50,19 @@ class Judges::Test
|
|
|
46
50
|
dir = args[0]
|
|
47
51
|
@loog.info("Testing judges in #{dir.to_rel}...")
|
|
48
52
|
errors = []
|
|
49
|
-
|
|
53
|
+
tested = 0
|
|
50
54
|
tests = 0
|
|
51
55
|
visible = []
|
|
56
|
+
judges = Judges::Judges.new(dir, opts['lib'], @loog)
|
|
52
57
|
elapsed(@loog) do
|
|
53
|
-
|
|
54
|
-
visible <<
|
|
55
|
-
next unless include?(opts,
|
|
56
|
-
@loog.info("\n👉 Testing #{
|
|
57
|
-
|
|
58
|
+
judges.each_with_index do |judge, i|
|
|
59
|
+
visible << judge.name
|
|
60
|
+
next unless include?(opts, judge.name)
|
|
61
|
+
@loog.info("\n👉 Testing #{judge.script} (##{i}) in #{judge.dir.to_rel}...")
|
|
62
|
+
judge.tests.each do |f|
|
|
58
63
|
tname = File.basename(f).gsub(/\.yml$/, '')
|
|
59
|
-
visible << " #{
|
|
60
|
-
next unless include?(opts,
|
|
64
|
+
visible << " #{judge.name}/#{tname}"
|
|
65
|
+
next unless include?(opts, judge.name, tname)
|
|
61
66
|
yaml = YAML.load_file(f, permitted_classes: [Time])
|
|
62
67
|
if yaml['skip']
|
|
63
68
|
@loog.info("Skippped #{f.to_rel}")
|
|
@@ -69,25 +74,32 @@ class Judges::Test
|
|
|
69
74
|
end
|
|
70
75
|
@loog.info("🛠️ Testing #{f.to_rel}:")
|
|
71
76
|
begin
|
|
72
|
-
|
|
77
|
+
fb = Factbase.new
|
|
78
|
+
prepare(fb, yaml)
|
|
79
|
+
yaml['before']&.each do |n|
|
|
80
|
+
j = judges.get(n)
|
|
81
|
+
@loog.info("Running #{j.script} judge as a pre-condition...")
|
|
82
|
+
test_one(fb, opts, j, n, yaml, assert: false)
|
|
83
|
+
end
|
|
84
|
+
test_one(fb, opts, judge, tname, yaml)
|
|
73
85
|
tests += 1
|
|
74
86
|
rescue StandardError => e
|
|
75
87
|
@loog.warn(Backtrace.new(e))
|
|
76
88
|
errors << f
|
|
77
89
|
end
|
|
78
90
|
end
|
|
79
|
-
|
|
91
|
+
tested += 1
|
|
80
92
|
end
|
|
81
|
-
throw :'👍 No judges tested' if
|
|
82
|
-
throw :"👍 All #{
|
|
83
|
-
throw :"👍 All #{
|
|
84
|
-
throw :"❌ #{
|
|
93
|
+
throw :'👍 No judges tested' if tested.zero?
|
|
94
|
+
throw :"👍 All #{tested} judge(s) but no tests passed" if tests.zero?
|
|
95
|
+
throw :"👍 All #{tested} judge(s) and #{tests} tests passed" if errors.empty?
|
|
96
|
+
throw :"❌ #{tested} judge(s) tested, #{errors.size} of them failed"
|
|
85
97
|
end
|
|
86
98
|
unless errors.empty?
|
|
87
99
|
raise "#{errors.size} tests failed" unless opts['quiet']
|
|
88
100
|
@loog.debug('Not failing the build with tests failures, due to the --quiet option')
|
|
89
101
|
end
|
|
90
|
-
return unless
|
|
102
|
+
return unless tested.zero? || tests.zero?
|
|
91
103
|
if opts['judge'].nil?
|
|
92
104
|
raise 'There are seems to be no judges' unless opts['quiet']
|
|
93
105
|
@loog.debug('Not failing the build with no judges tested, due to the --quiet option')
|
|
@@ -106,8 +118,7 @@ class Judges::Test
|
|
|
106
118
|
judges.any? { |n| n.match?(%r{^#{name}(/#{tre})?$}) }
|
|
107
119
|
end
|
|
108
120
|
|
|
109
|
-
def
|
|
110
|
-
fb = Factbase.new
|
|
121
|
+
def prepare(fb, yaml)
|
|
111
122
|
inputs = yaml['input']
|
|
112
123
|
inputs&.each do |i|
|
|
113
124
|
f = fb.insert
|
|
@@ -121,12 +132,16 @@ class Judges::Test
|
|
|
121
132
|
end
|
|
122
133
|
end
|
|
123
134
|
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def test_one(fb, opts, judge, tname, yaml, assert: true)
|
|
124
138
|
options = Judges::Options.new(opts['option']) + Judges::Options.new(yaml['options'])
|
|
125
139
|
runs = opts['runs'] || yaml['runs'] || 1
|
|
126
140
|
(1..runs).each do |r|
|
|
127
141
|
fbx = fb
|
|
128
142
|
fbx = Factbase::Looged.new(fb, @loog) if opts['log']
|
|
129
143
|
judge.run(fbx, {}, {}, options)
|
|
144
|
+
next unless assert
|
|
130
145
|
assert(judge, tname, fb, yaml) if r == runs || opts['assert_once'].is_a?(FalseClass)
|
|
131
146
|
end
|
|
132
147
|
end
|
data/lib/judges/commands/trim.rb
CHANGED
|
@@ -25,7 +25,11 @@ require_relative '../../judges'
|
|
|
25
25
|
require_relative '../../judges/impex'
|
|
26
26
|
require_relative '../../judges/elapsed'
|
|
27
27
|
|
|
28
|
-
#
|
|
28
|
+
# The +trim+ command.
|
|
29
|
+
#
|
|
30
|
+
# This class is instantiated by the +bin/judge+ command line interface. You
|
|
31
|
+
# are not supposed to instantiate it yourself.
|
|
32
|
+
#
|
|
29
33
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
30
34
|
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
|
31
35
|
# License:: MIT
|
|
@@ -30,7 +30,11 @@ require_relative '../../judges/options'
|
|
|
30
30
|
require_relative '../../judges/impex'
|
|
31
31
|
require_relative '../../judges/elapsed'
|
|
32
32
|
|
|
33
|
-
#
|
|
33
|
+
# The +update+ command.
|
|
34
|
+
#
|
|
35
|
+
# This class is instantiated by the +bin/judge+ command line interface. You
|
|
36
|
+
# are not supposed to instantiate it yourself.
|
|
37
|
+
#
|
|
34
38
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
35
39
|
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
|
36
40
|
# License:: MIT
|
data/lib/judges/judges.rb
CHANGED
|
@@ -34,8 +34,16 @@ class Judges::Judges
|
|
|
34
34
|
@loog = loog
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
+
# Get one judge by name.
|
|
38
|
+
# @return [Judge]
|
|
39
|
+
def get(name)
|
|
40
|
+
d = File.absolute_path(File.join(@dir, name))
|
|
41
|
+
raise "Judge #{name} doesn't exist in #{@dir}" unless File.exist?(d)
|
|
42
|
+
Judges::Judge.new(d, @lib, @loog)
|
|
43
|
+
end
|
|
44
|
+
|
|
37
45
|
# Iterate over them all.
|
|
38
|
-
# @yield [
|
|
46
|
+
# @yield [Judge]
|
|
39
47
|
def each
|
|
40
48
|
Dir.glob(File.join(@dir, '**/*.rb')).each do |f|
|
|
41
49
|
d = File.dirname(File.absolute_path(f))
|
|
@@ -44,7 +52,7 @@ class Judges::Judges
|
|
|
44
52
|
end
|
|
45
53
|
|
|
46
54
|
# Iterate over them all.
|
|
47
|
-
# @yield [(
|
|
55
|
+
# @yield [(Judge, Integer)]
|
|
48
56
|
def each_with_index
|
|
49
57
|
idx = 0
|
|
50
58
|
each do |p|
|
data/lib/judges.rb
CHANGED
data/test/commands/test_test.rb
CHANGED
|
@@ -88,6 +88,32 @@ class TestTest < Minitest::Test
|
|
|
88
88
|
end
|
|
89
89
|
end
|
|
90
90
|
|
|
91
|
+
def test_with_before
|
|
92
|
+
Dir.mktmpdir do |d|
|
|
93
|
+
home = File.join(d, 'judges')
|
|
94
|
+
FileUtils.mkdir_p(File.join(home, 'first'))
|
|
95
|
+
File.write(File.join(d, 'judges/first/the-first.rb'), 'x = $fb.size; $fb.insert.foo = x')
|
|
96
|
+
FileUtils.mkdir_p(File.join(home, 'second'))
|
|
97
|
+
File.write(File.join(d, 'judges/second/the-second.rb'), '$fb.insert.bar = 55')
|
|
98
|
+
File.write(
|
|
99
|
+
File.join(d, 'judges/second/something.yml'),
|
|
100
|
+
<<-YAML
|
|
101
|
+
input:
|
|
102
|
+
-
|
|
103
|
+
hi: 42
|
|
104
|
+
before:
|
|
105
|
+
- first
|
|
106
|
+
expected:
|
|
107
|
+
- /fb[count(f)=3]
|
|
108
|
+
- /fb/f[hi=42]
|
|
109
|
+
- /fb/f[foo=1]
|
|
110
|
+
- /fb/f[bar=55]
|
|
111
|
+
YAML
|
|
112
|
+
)
|
|
113
|
+
Judges::Test.new(Loog::NULL).run({}, [home])
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
91
117
|
def test_one_judge_negative
|
|
92
118
|
Dir.mktmpdir do |d|
|
|
93
119
|
File.write(File.join(d, 'foo.rb'), '')
|
data/test/test__helper.rb
CHANGED
data/test/test_judges.rb
CHANGED
|
@@ -30,7 +30,7 @@ require_relative '../lib/judges/judges'
|
|
|
30
30
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
|
31
31
|
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
|
32
32
|
# License:: MIT
|
|
33
|
-
class
|
|
33
|
+
class TestJudges < Minitest::Test
|
|
34
34
|
def test_basic
|
|
35
35
|
Dir.mktmpdir do |d|
|
|
36
36
|
File.write(File.join(d, 'foo.rb'), 'hey')
|
|
@@ -44,4 +44,14 @@ class TestPacks < Minitest::Test
|
|
|
44
44
|
assert_equal(1, found)
|
|
45
45
|
end
|
|
46
46
|
end
|
|
47
|
+
|
|
48
|
+
def test_get_one
|
|
49
|
+
Dir.mktmpdir do |d|
|
|
50
|
+
f = File.join(d, 'boo/foo.rb')
|
|
51
|
+
FileUtils.mkdir_p(File.dirname(f))
|
|
52
|
+
File.write(f, 'hey')
|
|
53
|
+
j = Judges::Judges.new(d, nil, Loog::NULL).get('boo')
|
|
54
|
+
assert_equal('foo.rb', j.script)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
47
57
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: judges
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.18.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yegor Bugayenko
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2024-07-
|
|
11
|
+
date: 2024-07-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: backtrace
|