judges 0.0.37 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e81cc6dc7d8235244b8b4ae58c481e023a7bca24b1867d534182eb271848d96
4
- data.tar.gz: b8c6db7f004f69f6a36a823c84847edc56cc3bbbac182509c313885d25682369
3
+ metadata.gz: f36d80279b095db31b037136ab951bbc395bd5b5d74922149706ab8fe404381b
4
+ data.tar.gz: c0e1c403f0857e5c1764c8a0cf620761c36bf9e92dbcf9f4c4f2dbc420755651
5
5
  SHA512:
6
- metadata.gz: fb9ac6b946a3ebde4df93b170ebc47caccd0d903d38dd48d2825fc625c1d6577300ba3b2d6867485a871820f8e323e1014debe5dca447fe4a1a3a096d53020e4
7
- data.tar.gz: fd0614960a2ce36d0ea2ae84a3dd4c7053f11d06945f712c00400e182dfc322196609b0bd21cfa61eedab7908090686bc1f86ed1cb4aab6cfde6ed534a4cd117
6
+ metadata.gz: d729a939b8a4b5894122d3e899487b8838dc92db04176f7ab3cb843d401b05edfd081744c5979c9169d98f78070ab0637f54b1f6d3623c60086e70b8666398f7
7
+ data.tar.gz: 15246686f5279034d4a57d0050931d93ebe6546c807e30e2d1bc0dd8611b7b8edfe6cd552272db3103f1001947078aa2b49b8a58935b1831fde503e509eef3ec
data/Gemfile CHANGED
@@ -28,9 +28,9 @@ gem 'minitest', '5.23.1', require: false
28
28
  gem 'net-ping', '2.0.8', require: false
29
29
  gem 'rake', '13.2.1', require: false
30
30
  gem 'rspec-rails', '6.1.2', require: false
31
- gem 'rubocop', '1.64.0', require: false
31
+ gem 'rubocop', '1.64.1', require: false
32
32
  gem 'rubocop-performance', '1.21.0', require: false
33
- gem 'rubocop-rspec', '2.29.2', require: false
33
+ gem 'rubocop-rspec', '2.30.0', require: false
34
34
  gem 'simplecov', '0.22.0', require: false
35
35
  gem 'simplecov-cobertura', '2.1.0', require: false
36
36
  gem 'webmock', '3.23.1', require: false
data/Gemfile.lock CHANGED
@@ -4,7 +4,7 @@ PATH
4
4
  judges (0.0.0)
5
5
  backtrace (~> 0.3)
6
6
  concurrent-ruby (= 1.2.3)
7
- factbase (~> 0.0.38)
7
+ factbase (~> 0.0)
8
8
  gli (~> 2.21)
9
9
  iri (~> 0.8)
10
10
  loog (~> 0.2)
@@ -84,13 +84,17 @@ GEM
84
84
  erubi (1.12.0)
85
85
  ethon (0.16.0)
86
86
  ffi (>= 1.15.0)
87
- factbase (0.0.38)
87
+ factbase (0.0.41)
88
88
  json (~> 2.7)
89
89
  loog (~> 0.2)
90
90
  nokogiri (~> 1.10)
91
91
  yaml (~> 0.3)
92
- ffi (1.16.3)
93
- ffi (1.16.3-x64-mingw-ucrt)
92
+ ffi (1.17.0-aarch64-linux-gnu)
93
+ ffi (1.17.0-arm-linux-gnu)
94
+ ffi (1.17.0-arm64-darwin)
95
+ ffi (1.17.0-x86-linux-gnu)
96
+ ffi (1.17.0-x86_64-darwin)
97
+ ffi (1.17.0-x86_64-linux-gnu)
94
98
  gli (2.21.1)
95
99
  hashdiff (1.1.0)
96
100
  i18n (1.14.5)
@@ -111,16 +115,20 @@ GEM
111
115
  multi_test (1.1.0)
112
116
  mutex_m (0.2.0)
113
117
  net-ping (2.0.8)
118
+ nokogiri (1.16.5-aarch64-linux)
119
+ racc (~> 1.4)
120
+ nokogiri (1.16.5-arm-linux)
121
+ racc (~> 1.4)
114
122
  nokogiri (1.16.5-arm64-darwin)
115
123
  racc (~> 1.4)
116
- nokogiri (1.16.5-x64-mingw-ucrt)
124
+ nokogiri (1.16.5-x86-linux)
117
125
  racc (~> 1.4)
118
126
  nokogiri (1.16.5-x86_64-darwin)
119
127
  racc (~> 1.4)
120
128
  nokogiri (1.16.5-x86_64-linux)
121
129
  racc (~> 1.4)
122
130
  parallel (1.24.0)
123
- parser (3.3.1.0)
131
+ parser (3.3.2.0)
124
132
  ast (~> 2.4.1)
125
133
  racc
126
134
  psych (5.1.2)
@@ -176,7 +184,7 @@ GEM
176
184
  rspec-mocks (~> 3.13)
177
185
  rspec-support (~> 3.13)
178
186
  rspec-support (3.13.1)
179
- rubocop (1.64.0)
187
+ rubocop (1.64.1)
180
188
  json (~> 2.3)
181
189
  language_server-protocol (>= 3.17.0)
182
190
  parallel (~> 1.10)
@@ -196,7 +204,7 @@ GEM
196
204
  rubocop-performance (1.21.0)
197
205
  rubocop (>= 1.48.1, < 2.0)
198
206
  rubocop-ast (>= 1.31.1, < 2.0)
199
- rubocop-rspec (2.29.2)
207
+ rubocop-rspec (2.30.0)
200
208
  rubocop (~> 1.40)
201
209
  rubocop-capybara (~> 2.17)
202
210
  rubocop-factory_bot (~> 2.22)
@@ -233,9 +241,11 @@ GEM
233
241
  zeitwerk (2.6.15)
234
242
 
235
243
  PLATFORMS
236
- arm64-darwin-22
237
- x64-mingw-ucrt
238
- x86_64-darwin-20
244
+ aarch64-linux
245
+ arm-linux
246
+ arm64-darwin
247
+ x86-linux
248
+ x86_64-darwin
239
249
  x86_64-linux
240
250
 
241
251
  DEPENDENCIES
@@ -245,13 +255,13 @@ DEPENDENCIES
245
255
  net-ping (= 2.0.8)
246
256
  rake (= 13.2.1)
247
257
  rspec-rails (= 6.1.2)
248
- rubocop (= 1.64.0)
258
+ rubocop (= 1.64.1)
249
259
  rubocop-performance (= 1.21.0)
250
- rubocop-rspec (= 2.29.2)
260
+ rubocop-rspec (= 2.30.0)
251
261
  simplecov (= 0.22.0)
252
262
  simplecov-cobertura (= 2.1.0)
253
263
  webmock (= 3.23.1)
254
264
  yard (= 0.9.36)
255
265
 
256
266
  BUNDLED WITH
257
- 2.4.22
267
+ 2.5.6
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Judges
1
+ # Judges over a Factbase Executor
2
2
 
3
3
  [![DevOps By Rultor.com](http://www.rultor.com/b/yegor256/judges)](http://www.rultor.com/p/yegor256/judges)
4
4
  [![We recommend RubyMine](https://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)
@@ -11,7 +11,7 @@
11
11
  [![Hits-of-Code](https://hitsofcode.com/github/yegor256/judges)](https://hitsofcode.com/view/github/yegor256/judges)
12
12
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/judges/blob/master/LICENSE.txt)
13
13
 
14
- A command line tool and a Ruby gem for running judges agains a
14
+ A command line tool and a Ruby gem for running so called judges against a
15
15
  [factbase](https://github.com/yegor256/factbase).
16
16
 
17
17
  Every "judge" is a directory with a single `.rb` file and a number
@@ -24,19 +24,22 @@ global variables available to it:
24
24
  * `$loog` — an instance
25
25
  of [`Loog`](https://www.rubydoc.info/gems/loog/0.5.1/Loog),
26
26
  where `.info` and `.debug` logs are welcome;
27
- * `$options` — a holder of options coming from `.yml` files;
28
- * `$local` a hash map that is cleaned up when all tests
29
- in the pack are finished;
27
+ * `$options` — a holder of options coming from either the `--option` command
28
+ line flag or the `.yml` file during testing;
29
+ * `$local` — a hash map that is cleaned up when the execution of
30
+ a judge is finished;
30
31
  * `$global` — a hash map that is never cleaned up;
31
- * `$judge` — the name of the directory, where the `.rb` script is located.
32
+ * `$judge` — the basename of the directory, where the `.rb` script is located.
32
33
 
33
34
  Every `.yml` file must be formatted as such:
34
35
 
35
36
  ```yaml
37
+ skip: false
36
38
  input:
37
39
  -
38
40
  foo: 42
39
41
  bar: Hello, world!
42
+ many: [1, 2, -10]
40
43
  options:
41
44
  max: 100
42
45
  expected:
@@ -44,8 +47,8 @@ expected:
44
47
  ```
45
48
 
46
49
  Here, the `input` is an array of facts to be placed into the Factbase before
47
- the test starts; the `options` is a hash map of options to be passed
48
- via command line `--option` of the `update` command; and `expected` is
50
+ the test starts; the `options` is a hash map of options as if they are passed
51
+ via the command line `--option` flag of the `update` command; and `expected` is
49
52
  an array of XPath expressions that must be present in the XML of the Factbase
50
53
  when the test is finished.
51
54
 
@@ -55,7 +58,7 @@ Read
55
58
  [these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
56
59
  Make sure you build is green before you contribute
57
60
  your pull request. You will need to have
58
- [Ruby](https://www.ruby-lang.org/en/) 2.3+ and
61
+ [Ruby](https://www.ruby-lang.org/en/) 3.0+ and
59
62
  [Bundler](https://bundler.io/) installed. Then:
60
63
 
61
64
  ```bash
data/bin/judges CHANGED
@@ -136,8 +136,8 @@ class App
136
136
  c.flag([:disable], multiple: true)
137
137
  c.desc 'Categories of tests to enable'
138
138
  c.flag([:enable], multiple: true)
139
- c.desc 'Name of the test pack to run'
140
- c.flag([:pack], multiple: true)
139
+ c.desc 'Name of the judge to run (directory name)'
140
+ c.flag([:judge], multiple: true)
141
141
  c.desc 'The location of a Ruby library (directory with .rb files to include)'
142
142
  c.flag([:lib])
143
143
  c.desc 'Stay quiet even if some tests fail or simply no tests executed?'
@@ -1,8 +1,8 @@
1
1
  Feature: Gem Package
2
2
  As a source code writer I want to be able to
3
- package the Gem into .gem file
3
+ judgeage the Gem into .gem file
4
4
 
5
- Scenario: Gem can be packaged
5
+ Scenario: Gem can be judgeaged
6
6
  Given I make a temp directory
7
7
  Then I have a "execs.rb" file with content:
8
8
  """
@@ -7,57 +7,73 @@ Feature: Test
7
7
  Then Stdout contains "All 2 judge(s) and 2 tests passed"
8
8
  And Exit code is zero
9
9
 
10
- Scenario: Simple test of just one pack
11
- Given I run bin/judges with "test --pack guess ./fixtures"
10
+ Scenario: Simple test of just one judge
11
+ Given I run bin/judges with "test --judge guess ./fixtures"
12
12
  Then Stdout contains "All 1 judge(s) and 1 tests passed"
13
13
  And Exit code is zero
14
14
 
15
- Scenario: Simple test of no packs
16
- Given I run bin/judges with "test --pack absent_for_sure ./fixtures"
15
+ Scenario: Simple test of no judges
16
+ Given I run bin/judges with "test --judge absent_for_sure ./fixtures"
17
+ Then Exit code is zero
18
+
19
+ Scenario: Simple test of no judges at all
20
+ Given I make a temp directory
21
+ Given I run bin/judges with "test ."
22
+ Then Exit code is not zero
23
+
24
+ Scenario: Simple test of no judges at all
25
+ Given I make a temp directory
26
+ Given I run bin/judges with "test --judge some ."
17
27
  Then Exit code is not zero
18
28
 
19
29
  Scenario: Simple test of a few judges, with a lib
20
30
  Given I make a temp directory
21
- Then I have a "mypacks/mypack/simple_judge.rb" file with content:
31
+ Then I have a "myjudges/myjudge/simple_judge.rb" file with content:
22
32
  """
23
33
  n = $fb.insert
24
34
  n.foo = $foo
25
35
  """
36
+ Then I have a "myjudges/myjudge/good.yml" file with content:
37
+ """
38
+ ---
39
+ category: good
40
+ input: []
41
+ """
26
42
  Then I have a "mylib/foo.rb" file with content:
27
43
  """
28
44
  $foo = 42
29
45
  """
30
- Then I run bin/judges with "test --lib mylib mypacks"
31
- Then Stdout contains "All 1 judge(s) but no tests passed"
46
+ Then I run bin/judges with "test --lib mylib myjudges"
47
+ Then Stdout contains "All 1 judge(s) and 1 tests passed"
32
48
  And Exit code is zero
33
49
 
34
50
  Scenario: Enable only one category
35
51
  Given I make a temp directory
36
- Then I have a "mypacks/good/good.rb" file with content:
52
+ Then I have a "mine/good/good.rb" file with content:
37
53
  """
38
54
  n = $fb.insert
39
55
  """
40
- Then I have a "mypacks/good/good.yml" file with content:
56
+ Then I have a "mine/good/good.yml" file with content:
41
57
  """
42
58
  ---
43
59
  category: good
44
60
  input: []
45
61
  """
46
- Then I have a "mypacks/bad/bad.rb" file with content:
62
+ Then I have a "mine/bad/bad.rb" file with content:
47
63
  """
48
64
  broken$ruby$syntax
49
65
  """
50
- Then I have a "mypacks/bad/bad.yml" file with content:
66
+ Then I have a "mine/bad/bad.yml" file with content:
51
67
  """
52
68
  ---
53
69
  category: bad
54
70
  """
55
- Then I run bin/judges with "test --enable good mypacks"
71
+ Then I run bin/judges with "test --enable good mine"
56
72
  Then Stdout contains "All 2 judge(s) and 1 tests passed"
57
73
  And Exit code is zero
58
- Then I run bin/judges with "test --disable bad mypacks"
74
+ Then I run bin/judges with "test --disable bad mine"
59
75
  Then Stdout contains "All 2 judge(s) and 1 tests passed"
60
76
  And Exit code is zero
61
- Then I run bin/judges with "test --enable bad mypacks"
62
- Then Stdout contains "Testing mypacks/bad/bad.yml"
77
+ Then I run bin/judges with "test --enable bad mine"
78
+ Then Stdout contains "Testing mine/bad/bad.yml"
63
79
  And Exit code is not zero
@@ -12,12 +12,12 @@ Feature: Update
12
12
  Then Stdout contains "foo → "
13
13
  Then Stdout contains "bar → "
14
14
  Then Stdout contains "1 judge(s) processed"
15
- Then Stdout contains "Update finished: 3 cycles"
15
+ Then Stdout contains "Update finished in 3 cycle(s), +3 fact(s)"
16
16
  And Exit code is zero
17
17
 
18
18
  Scenario: Simple run of a few judges, with a lib
19
19
  Given I make a temp directory
20
- Then I have a "mypacks/mypack/simple_judge.rb" file with content:
20
+ Then I have a "mine/judge1/simple_judge.rb" file with content:
21
21
  """
22
22
  n = $fb.insert
23
23
  n.foo = $foo
@@ -26,27 +26,27 @@ Feature: Update
26
26
  """
27
27
  $foo = 42
28
28
  """
29
- Then I run bin/judges with "update --lib mylib --max-cycles 1 mypacks simple.fb"
29
+ Then I run bin/judges with "update --lib mylib --max-cycles 1 mine simple.fb"
30
30
  Then Stdout contains "1 judge(s) processed"
31
- Then Stdout contains "Update finished: 1 cycles"
31
+ Then Stdout contains "Update finished in 1 cycle(s)"
32
32
  And Exit code is zero
33
33
 
34
34
  Scenario: The update fails when a bug in a judge
35
35
  Given I make a temp directory
36
- Then I have a "mypacks/mypack/broken.rb" file with content:
36
+ Then I have a "mine/judge1/broken.rb" file with content:
37
37
  """
38
38
  a < 1
39
39
  """
40
- Then I run bin/judges with "update mypacks simple.fb"
40
+ Then I run bin/judges with "update mine simple.fb"
41
41
  Then Stdout contains "Failed to update correctly"
42
42
  And Exit code is not zero
43
43
 
44
44
  Scenario: The update fails when a broken Ruby syntax in a judge
45
45
  Given I make a temp directory
46
- Then I have a "mypacks/mypack/broken.rb" file with content:
46
+ Then I have a "mine/judge1/broken.rb" file with content:
47
47
  """
48
48
  invalid$ruby$syntax$here
49
49
  """
50
- Then I run bin/judges with "update mypacks simple.fb"
50
+ Then I run bin/judges with "update mine simple.fb"
51
51
  Then Stdout contains "Failed to update correctly"
52
52
  And Exit code is not 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.0.37'
29
+ s.version = '0.2.0'
30
30
  s.license = 'MIT'
31
31
  s.summary = 'Command-Line Tool for a Factbase'
32
32
  s.description =
@@ -44,7 +44,7 @@ Gem::Specification.new do |s|
44
44
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
45
45
  s.add_runtime_dependency 'backtrace', '~> 0.3'
46
46
  s.add_runtime_dependency 'concurrent-ruby', '1.2.3'
47
- s.add_runtime_dependency 'factbase', '~>0.0.38'
47
+ s.add_runtime_dependency 'factbase', '~>0.0'
48
48
  s.add_runtime_dependency 'gli', '~>2.21'
49
49
  s.add_runtime_dependency 'iri', '~>0.8'
50
50
  s.add_runtime_dependency 'loog', '~>0.2'
@@ -27,7 +27,7 @@ require 'factbase/looged'
27
27
  require 'factbase/to_xml'
28
28
  require_relative '../../judges'
29
29
  require_relative '../../judges/to_rel'
30
- require_relative '../../judges/packs'
30
+ require_relative '../../judges/judges'
31
31
  require_relative '../../judges/options'
32
32
  require_relative '../../judges/categories'
33
33
  require_relative '../../judges/elapsed'
@@ -46,13 +46,18 @@ class Judges::Test
46
46
  dir = args[0]
47
47
  @loog.info("Testing judges in #{dir.to_rel}...")
48
48
  errors = []
49
- packs = 0
49
+ judges = 0
50
50
  tests = 0
51
+ visible = []
51
52
  elapsed(@loog) do
52
- Judges::Packs.new(dir, opts['lib'], @loog).each_with_index do |p, i|
53
+ Judges::Judges.new(dir, opts['lib'], @loog).each_with_index do |p, i|
54
+ visible << p.name
53
55
  next unless include?(opts, p.name)
54
56
  @loog.info("\n👉 Testing #{p.script} (##{i}) in #{p.dir.to_rel}...")
55
57
  p.tests.each do |f|
58
+ tname = File.basename(f).gsub(/\.yml$/, '')
59
+ visible << " #{p.name}/#{tname}"
60
+ next unless include?(opts, p.name, tname)
56
61
  yaml = YAML.load_file(f, permitted_classes: [Time])
57
62
  if yaml['skip']
58
63
  @loog.info("Skippped #{f.to_rel}")
@@ -71,31 +76,37 @@ class Judges::Test
71
76
  errors << f
72
77
  end
73
78
  end
74
- packs += 1
79
+ judges += 1
75
80
  end
76
- throw :'👍 No judges tested' if packs.zero?
77
- throw :"👍 All #{packs} judge(s) but no tests passed" if tests.zero?
78
- throw :"👍 All #{packs} judge(s) and #{tests} tests passed" if errors.empty?
79
- throw :"❌ #{packs} judge(s) tested, #{errors.size} of them failed"
81
+ throw :'👍 No judges tested' if judges.zero?
82
+ throw :"👍 All #{judges} judge(s) but no tests passed" if tests.zero?
83
+ throw :"👍 All #{judges} judge(s) and #{tests} tests passed" if errors.empty?
84
+ throw :"❌ #{judges} judge(s) tested, #{errors.size} of them failed"
80
85
  end
81
86
  unless errors.empty?
82
87
  raise "#{errors.size} tests failed" unless opts['quiet']
83
88
  @loog.debug('Not failing the build with tests failures, due to the --quiet option')
84
89
  end
85
- return unless packs.zero?
86
- raise 'No judges tested :(' unless opts['quiet']
87
- @loog.debug('Not failing the build with no judges tested, due to the --quiet option')
90
+ return unless judges.zero? || tests.zero?
91
+ if opts['judge'].nil?
92
+ raise 'There are seems to be no judges' unless opts['quiet']
93
+ @loog.debug('Not failing the build with no judges tested, due to the --quiet option')
94
+ else
95
+ raise 'There are seems to be no judges' if visible.empty?
96
+ @loog.info("The following judges are available to use with the --judge option:\n #{visible.join("\n ")}")
97
+ end
88
98
  end
89
99
 
90
100
  private
91
101
 
92
- def include?(opts, name)
93
- packs = opts['pack'] || []
94
- return true if packs.empty?
95
- packs.include?(name)
102
+ def include?(opts, name, tname = nil)
103
+ judges = opts['judge'] || []
104
+ return true if judges.empty?
105
+ tre = tname.nil? ? '.+' : tname
106
+ judges.any? { |n| n.match?(%r{^#{name}(/#{tre})?$}) }
96
107
  end
97
108
 
98
- def test_one(opts, pack, yaml)
109
+ def test_one(opts, judge, yaml)
99
110
  fb = Factbase.new
100
111
  inputs = yaml['input']
101
112
  inputs&.each do |i|
@@ -111,12 +122,12 @@ class Judges::Test
111
122
  end
112
123
  end
113
124
  options = Judges::Options.new(opts['option']) + Judges::Options.new(yaml['options'])
114
- pack.run(Factbase::Looged.new(fb, @loog), {}, {}, options)
125
+ judge.run(Factbase::Looged.new(fb, @loog), {}, {}, options)
115
126
  xpaths = yaml['expected']
116
127
  return if xpaths.nil?
117
128
  xml = Nokogiri::XML.parse(Factbase::ToXML.new(fb).xml)
118
129
  xpaths.each do |xp|
119
- raise "#{pack.script} doesn't match '#{xp}':\n#{xml}" if xml.xpath(xp).empty?
130
+ raise "#{judge.script} doesn't match '#{xp}':\n#{xml}" if xml.xpath(xp).empty?
120
131
  end
121
132
  end
122
133
  end
@@ -24,7 +24,7 @@ require 'backtrace'
24
24
  require 'factbase/looged'
25
25
  require_relative '../../judges'
26
26
  require_relative '../../judges/to_rel'
27
- require_relative '../../judges/packs'
27
+ require_relative '../../judges/judges'
28
28
  require_relative '../../judges/options'
29
29
  require_relative '../../judges/impex'
30
30
  require_relative '../../judges/elapsed'
@@ -45,9 +45,10 @@ class Judges::Update
45
45
  impex = Judges::Impex.new(@loog, args[1])
46
46
  fb = impex.import(strict: false)
47
47
  fb = Factbase::Looged.new(fb, @loog)
48
+ before = fb.size
48
49
  options = Judges::Options.new(opts['option'])
49
50
  @loog.debug("The following options provided:\n\t#{options.to_s.gsub("\n", "\n\t")}")
50
- packs = Judges::Packs.new(dir, opts['lib'], @loog)
51
+ judges = Judges::Judges.new(dir, opts['lib'], @loog)
51
52
  c = 0
52
53
  elapsed(@loog) do
53
54
  loop do
@@ -55,7 +56,7 @@ class Judges::Update
55
56
  if c > 1
56
57
  @loog.info("\n\nStarting cycle ##{c}#{opts['max-cycles'] ? " (out of #{opts['max-cycles']})" : ''}...")
57
58
  end
58
- diff = cycle(opts, packs, fb, options)
59
+ diff = cycle(opts, judges, fb, options)
59
60
  impex.export(fb)
60
61
  if diff.zero?
61
62
  @loog.info("The update cycle ##{c} has made no changes to the factbase, let's stop")
@@ -66,23 +67,23 @@ class Judges::Update
66
67
  break
67
68
  end
68
69
  @loog.info(
69
- "By #{diff} facts the factbase " \
70
+ "By #{diff.abs} fact(s) the factbase " \
70
71
  "#{diff.positive? ? 'increased' : 'decreased'} " \
71
72
  "its size at the cycle ##{c}"
72
73
  )
73
74
  end
74
- throw :"Update finished: #{c} cycles"
75
+ throw :"Update finished in #{c} cycle(s), #{format('+%d', fb.size - before)} fact(s)"
75
76
  end
76
77
  end
77
78
 
78
79
  private
79
80
 
80
- def cycle(opts, packs, fb, options)
81
+ def cycle(opts, judges, fb, options)
81
82
  errors = []
82
83
  diff = 0
83
84
  global = {}
84
85
  elapsed(@loog) do
85
- done = packs.each_with_index do |p, i|
86
+ done = judges.each_with_index do |p, i|
86
87
  local = {}
87
88
  @loog.info("👉 Running #{p.name} (##{i}) at #{p.dir.to_rel}...")
88
89
  before = fb.size
@@ -26,11 +26,11 @@ require_relative '../judges/elapsed'
26
26
  require_relative '../judges/fb/once'
27
27
  require_relative '../judges/fb/if_absent'
28
28
 
29
- # A single pack.
29
+ # A single judge.
30
30
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
31
31
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
32
32
  # License:: MIT
33
- class Judges::Pack
33
+ class Judges::Judge
34
34
  attr_reader :dir
35
35
 
36
36
  def initialize(dir, lib, loog)
@@ -63,12 +63,12 @@ class Judges::Pack
63
63
  end
64
64
  end
65
65
 
66
- # Get the name of the pack.
66
+ # Get the name of the judge.
67
67
  def name
68
68
  File.basename(@dir)
69
69
  end
70
70
 
71
- # Get the name of the .rb script in the pack.
71
+ # Get the name of the .rb script in the judge.
72
72
  def script
73
73
  s = Dir.glob(File.join(@dir, '*.rb')).first
74
74
  raise "No *.rb scripts in #{@dir.to_rel}" if s.nil?
@@ -21,13 +21,13 @@
21
21
  # SOFTWARE.
22
22
 
23
23
  require_relative '../judges'
24
- require_relative 'pack'
24
+ require_relative 'judge'
25
25
 
26
- # Collection of all packs to run.
26
+ # Collection of all judges to run.
27
27
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
28
28
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
29
29
  # License:: MIT
30
- class Judges::Packs
30
+ class Judges::Judges
31
31
  def initialize(dir, lib, loog)
32
32
  @dir = dir
33
33
  @lib = lib
@@ -39,7 +39,7 @@ class Judges::Packs
39
39
  def each
40
40
  Dir.glob(File.join(@dir, '**/*.rb')).each do |f|
41
41
  d = File.dirname(File.absolute_path(f))
42
- yield Judges::Pack.new(d, @lib, @loog)
42
+ yield Judges::Judge.new(d, @lib, @loog)
43
43
  end
44
44
  end
45
45
 
data/lib/judges.rb CHANGED
@@ -25,5 +25,5 @@
25
25
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
26
26
  # License:: MIT
27
27
  module Judges
28
- VERSION = '0.0.37'
28
+ VERSION = '0.2.0'
29
29
  end
@@ -88,7 +88,7 @@ class TestTest < Minitest::Test
88
88
  end
89
89
  end
90
90
 
91
- def test_one_pack_negative
91
+ def test_one_judge_negative
92
92
  Dir.mktmpdir do |d|
93
93
  File.write(File.join(d, 'foo.rb'), '')
94
94
  File.write(
@@ -100,7 +100,7 @@ class TestTest < Minitest::Test
100
100
  YAML
101
101
  )
102
102
  assert_raises do
103
- Judges::Test.new(Loog::NULL).run({ 'pack' => [File.basename(dir)] }, [d])
103
+ Judges::Test.new(Loog::NULL).run({ 'judge' => [File.basename(dir)] }, [d])
104
104
  end
105
105
  end
106
106
  end
@@ -25,7 +25,7 @@ require 'tmpdir'
25
25
  require 'loog'
26
26
  require 'factbase'
27
27
  require_relative '../lib/judges'
28
- require_relative '../lib/judges/pack'
28
+ require_relative '../lib/judges/judge'
29
29
 
30
30
  # Test.
31
31
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -35,9 +35,9 @@ class TestPack < Minitest::Test
35
35
  def test_basic_run
36
36
  Dir.mktmpdir do |d|
37
37
  File.write(File.join(d, 'foo.rb'), '$fb.insert')
38
- pack = Judges::Pack.new(d, nil, Loog::NULL)
38
+ judge = Judges::Judge.new(d, nil, Loog::NULL)
39
39
  fb = Factbase.new
40
- pack.run(fb, {}, {}, {})
40
+ judge.run(fb, {}, {}, {})
41
41
  assert_equal(1, fb.size)
42
42
  end
43
43
  end
@@ -45,12 +45,12 @@ class TestPack < Minitest::Test
45
45
  def test_run_isolated
46
46
  Dir.mktmpdir do |d|
47
47
  File.write(File.join(d, 'bar.rb'), '$fb.insert')
48
- pack = Judges::Pack.new(d, nil, Loog::NULL)
48
+ judge = Judges::Judge.new(d, nil, Loog::NULL)
49
49
  fb1 = Factbase.new
50
- pack.run(fb1, {}, {}, {})
50
+ judge.run(fb1, {}, {}, {})
51
51
  assert_equal(1, fb1.size)
52
52
  fb2 = Factbase.new
53
- pack.run(fb2, {}, {}, {})
53
+ judge.run(fb2, {}, {}, {})
54
54
  assert_equal(1, fb2.size)
55
55
  end
56
56
  end
@@ -58,8 +58,8 @@ class TestPack < Minitest::Test
58
58
  def test_with_supplemenary_functions
59
59
  Dir.mktmpdir do |d|
60
60
  File.write(File.join(d, 'x.rb'), 'each_once($fb, "(always)").to_a')
61
- pack = Judges::Pack.new(d, nil, Loog::NULL)
62
- pack.run(Factbase.new, {}, {}, {})
61
+ judge = Judges::Judge.new(d, nil, Loog::NULL)
62
+ judge.run(Factbase.new, {}, {}, {})
63
63
  end
64
64
  end
65
65
 
@@ -72,11 +72,11 @@ class TestPack < Minitest::Test
72
72
  $local[:foo] = $local[:foo] + 1
73
73
  '
74
74
  )
75
- pack = Judges::Pack.new(d, nil, Loog::NULL)
75
+ judge = Judges::Judge.new(d, nil, Loog::NULL)
76
76
  local = {}
77
- pack.run(Factbase.new, {}, local, {})
78
- pack.run(Factbase.new, {}, local, {})
79
- pack.run(Factbase.new, {}, local, {})
77
+ judge.run(Factbase.new, {}, local, {})
78
+ judge.run(Factbase.new, {}, local, {})
79
+ judge.run(Factbase.new, {}, local, {})
80
80
  assert_equal(45, local[:foo])
81
81
  end
82
82
  end
@@ -88,22 +88,22 @@ class TestPack < Minitest::Test
88
88
  FileUtils.mkdir(dir)
89
89
  File.write(File.join(dir, 'foo.rb'), '$loog.info("judge=" + $judge)')
90
90
  log = Loog::Buffer.new
91
- Judges::Pack.new(dir, nil, log).run(Factbase.new, {}, {}, {})
91
+ Judges::Judge.new(dir, nil, log).run(Factbase.new, {}, {}, {})
92
92
  assert(log.to_s.include?("judge=#{j}"))
93
93
  end
94
94
  end
95
95
 
96
96
  def test_with_library
97
97
  Dir.mktmpdir do |d|
98
- dir = File.join(d, 'packs')
98
+ dir = File.join(d, 'judges')
99
99
  FileUtils.mkdir_p(dir)
100
100
  File.write(File.join(dir, 'x.rb'), '$fb.insert.bar = $foo; each_once($fb, "(always)").to_a')
101
101
  lib = File.join(d, 'lib')
102
102
  FileUtils.mkdir_p(lib)
103
103
  File.write(File.join(lib, 'y.rb'), '$foo = 42')
104
- pack = Judges::Pack.new(dir, lib, Loog::NULL)
104
+ judge = Judges::Judge.new(dir, lib, Loog::NULL)
105
105
  fb = Factbase.new
106
- pack.run(fb, {}, {}, {})
106
+ judge.run(fb, {}, {}, {})
107
107
  assert_equal(42, fb.query('(always)').each.to_a.first.bar)
108
108
  end
109
109
  end
@@ -111,11 +111,11 @@ class TestPack < Minitest::Test
111
111
  def test_with_broken_ruby_syntax
112
112
  assert_raises do
113
113
  Dir.mktmpdir do |d|
114
- dir = File.join(d, 'packs')
114
+ dir = File.join(d, 'judges')
115
115
  FileUtils.mkdir_p(dir)
116
116
  File.write(File.join(dir, 'x.rb'), 'this$is$broken$syntax')
117
- pack = Judges::Pack.new(dir, lib, Loog::NULL)
118
- pack.run(Factbase.new, {}, {}, {})
117
+ judge = Judges::Judge.new(dir, lib, Loog::NULL)
118
+ judge.run(Factbase.new, {}, {}, {})
119
119
  end
120
120
  end
121
121
  end
@@ -123,11 +123,11 @@ class TestPack < Minitest::Test
123
123
  def test_with_runtime_ruby_error
124
124
  assert_raises do
125
125
  Dir.mktmpdir do |d|
126
- dir = File.join(d, 'packs')
126
+ dir = File.join(d, 'judges')
127
127
  FileUtils.mkdir_p(dir)
128
128
  File.write(File.join(dir, 'x.rb'), 'a < 1')
129
- pack = Judges::Pack.new(dir, lib, Loog::NULL)
130
- pack.run(Factbase.new, {}, {}, {})
129
+ judge = Judges::Judge.new(dir, lib, Loog::NULL)
130
+ judge.run(Factbase.new, {}, {}, {})
131
131
  end
132
132
  end
133
133
  end
data/test/test_judges.rb CHANGED
@@ -21,13 +21,27 @@
21
21
  # SOFTWARE.
22
22
 
23
23
  require 'minitest/autorun'
24
+ require 'tmpdir'
25
+ require 'loog'
26
+ require_relative '../lib/judges'
27
+ require_relative '../lib/judges/judges'
24
28
 
25
29
  # Test.
26
30
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
27
31
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
28
32
  # License:: MIT
29
- class TestJudges < Minitest::Test
33
+ class TestPacks < Minitest::Test
30
34
  def test_basic
31
- # Nothing yet
35
+ Dir.mktmpdir do |d|
36
+ File.write(File.join(d, 'foo.rb'), 'hey')
37
+ File.write(File.join(d, 'something.yml'), "---\nfoo: 42")
38
+ found = 0
39
+ Judges::Judges.new(d, nil, Loog::NULL).each do |p|
40
+ assert_equal('foo.rb', p.script)
41
+ found += 1
42
+ assert_equal('something.yml', File.basename(p.tests.first))
43
+ end
44
+ assert_equal(1, found)
45
+ end
32
46
  end
33
47
  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.0.37
4
+ version: 0.2.0
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-05-30 00:00:00.000000000 Z
11
+ date: 2024-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.0.38
47
+ version: '0.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.0.38
54
+ version: '0.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: gli
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -190,9 +190,9 @@ files:
190
190
  - lib/judges/fb/if_absent.rb
191
191
  - lib/judges/fb/once.rb
192
192
  - lib/judges/impex.rb
193
+ - lib/judges/judge.rb
194
+ - lib/judges/judges.rb
193
195
  - lib/judges/options.rb
194
- - lib/judges/pack.rb
195
- - lib/judges/packs.rb
196
196
  - lib/judges/to_rel.rb
197
197
  - renovate.json
198
198
  - test/commands/test_eval.rb
@@ -211,10 +211,9 @@ files:
211
211
  - test/test_baza.rb
212
212
  - test/test_categories.rb
213
213
  - test/test_impex.rb
214
+ - test/test_judge.rb
214
215
  - test/test_judges.rb
215
216
  - test/test_options.rb
216
- - test/test_pack.rb
217
- - test/test_packs.rb
218
217
  - test/test_to_rel.rb
219
218
  homepage: http://github.com/yegor256/judges
220
219
  licenses:
data/test/test_packs.rb DELETED
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright (c) 2024 Yegor Bugayenko
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the 'Software'), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in all
13
- # copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- # SOFTWARE.
22
-
23
- require 'minitest/autorun'
24
- require 'tmpdir'
25
- require 'loog'
26
- require_relative '../lib/judges'
27
- require_relative '../lib/judges/packs'
28
-
29
- # Test.
30
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
31
- # Copyright:: Copyright (c) 2024 Yegor Bugayenko
32
- # License:: MIT
33
- class TestPacks < Minitest::Test
34
- def test_basic
35
- Dir.mktmpdir do |d|
36
- File.write(File.join(d, 'foo.rb'), 'hey')
37
- File.write(File.join(d, 'something.yml'), "---\nfoo: 42")
38
- found = 0
39
- Judges::Packs.new(d, nil, Loog::NULL).each do |p|
40
- assert_equal('foo.rb', p.script)
41
- found += 1
42
- assert_equal('something.yml', File.basename(p.tests.first))
43
- end
44
- assert_equal(1, found)
45
- end
46
- end
47
- end