judges 0.17.0 → 0.18.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6fde2252d089419bf5cb20dabc6368db3b70b7a7e6fb116624b3ec2f04811544
4
- data.tar.gz: 80accd532717b42f176b2bcfc9510610e1dc43d9396ed670196782b923ef2c70
3
+ metadata.gz: 01de840b5ca098985b5b4cbdc1ea16d96237d3bbed4617971662f5628fad46bf
4
+ data.tar.gz: e502a04924b0186921fbbc2026e4f7d78eed0ee47ec2f6cdfcfb01c65e092050
5
5
  SHA512:
6
- metadata.gz: 3bbdd338bea78fe3d8890b7f581d80081828e3391b738fdbf7a507751f5fab1897764e13dea952ecb5fa2c210c2baa577fb72b1b4d5b6e3994aec49d78eea1b4
7
- data.tar.gz: 1e514af2b34b531fbdc70337d3183aeb54d47f8127cda4145ce735724dc7a029e237e09b3c445876c413c1e3c0c660015c648bceef20661fb8b430e00d739692
6
+ metadata.gz: 38e602fda2bc3a1cce738e1633094d7dc0bc8a50fb43ff97e1e28d4da36752bbdb56fac51f98a2cec884b7a3245b701566c7500d817f4a242fbfb0c28cd9b62d
7
+ data.tar.gz: d9d5761f6384e7898da2cbab0b39a659d22f91a1af61a834f52c038f0162b8ebf08f576a8ea846b9a3818fb5f822c6d018552478d979365fa0226955f7cdc5d3
@@ -27,4 +27,4 @@ jobs:
27
27
  runs-on: ubuntu-22.04
28
28
  steps:
29
29
  - uses: actions/checkout@v4
30
- - uses: yegor256/copyrights-action@0.0.4
30
+ - uses: yegor256/copyrights-action@0.0.5
data/.rubocop.yml CHANGED
@@ -28,6 +28,8 @@ AllCops:
28
28
  SuggestExtensions: false
29
29
  NewCops: enable
30
30
 
31
+ Metrics/ParameterLists:
32
+ Enabled: false
31
33
  Style/GlobalVars:
32
34
  Enabled: false
33
35
  Metrics/MethodLength:
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.0)
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
@@ -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.17.0'
29
+ s.version = '0.18.0'
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
@@ -33,9 +33,7 @@ require_relative '../judges/elapsed'
33
33
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
34
34
  # License:: MIT
35
35
  class Judges::Baza
36
- # rubocop:disable Metrics/ParameterLists
37
36
  def initialize(host, port, token, ssl: true, timeout: 30, retries: 3, loog: Loog::NULL)
38
- # rubocop:enable Metrics/ParameterLists
39
37
  @host = host
40
38
  @port = port
41
39
  @ssl = ssl
@@ -225,6 +223,8 @@ class Judges::Baza
225
223
  msg +=
226
224
  ', most probably you are trying to reach a wrong server, which doesn\'t ' \
227
225
  'have the URL that it is expected to have'
226
+ when 0
227
+ msg += ', most likely an internal error'
228
228
  end
229
229
  raise msg
230
230
  end
@@ -49,7 +49,7 @@ class Judges::Pull
49
49
  elapsed(@loog) do
50
50
  if baza.name_exists?(name)
51
51
  baza.lock(name, opts['owner'])
52
- fb.import(baza.pull(wait(baza, baza.recent(name), opts['wait'])))
52
+ fb.import(baza.pull(wait(name, baza, baza.recent(name), opts['wait'])))
53
53
  Judges::Impex.new(@loog, args[1]).export(fb)
54
54
  throw :"Pulled #{fb.size} facts by the name '#{name}'"
55
55
  else
@@ -60,14 +60,15 @@ class Judges::Pull
60
60
 
61
61
  private
62
62
 
63
- def wait(baza, id, limit)
63
+ def wait(name, baza, id, limit)
64
64
  raise 'Waiting time is nil' if limit.nil?
65
65
  start = Time.now
66
66
  loop do
67
67
  break if baza.finished?(id)
68
68
  sleep 1
69
- raise 'Time is over, the job is still not finished' if Time.now - start > limit
70
- @loog.debug("Still waiting for the job ##{id} to finish... (#{format('%.2f', Time.now - start)}s already)")
69
+ raise "Time is over, the job ##{id} ('#{name}') is still not finished" if Time.now - start > limit
70
+ lapsed = Time.now - start
71
+ @loog.debug("Still waiting for the job ##{id} ('#{name}') to finish... (#{format('%.2f', lapsed)}s already)")
71
72
  end
72
73
  id
73
74
  end
@@ -46,18 +46,19 @@ class Judges::Test
46
46
  dir = args[0]
47
47
  @loog.info("Testing judges in #{dir.to_rel}...")
48
48
  errors = []
49
- judges = 0
49
+ tested = 0
50
50
  tests = 0
51
51
  visible = []
52
+ judges = Judges::Judges.new(dir, opts['lib'], @loog)
52
53
  elapsed(@loog) do
53
- Judges::Judges.new(dir, opts['lib'], @loog).each_with_index do |p, i|
54
- visible << p.name
55
- next unless include?(opts, p.name)
56
- @loog.info("\n👉 Testing #{p.script} (##{i}) in #{p.dir.to_rel}...")
57
- p.tests.each do |f|
54
+ judges.each_with_index do |judge, i|
55
+ visible << judge.name
56
+ next unless include?(opts, judge.name)
57
+ @loog.info("\n👉 Testing #{judge.script} (##{i}) in #{judge.dir.to_rel}...")
58
+ judge.tests.each do |f|
58
59
  tname = File.basename(f).gsub(/\.yml$/, '')
59
- visible << " #{p.name}/#{tname}"
60
- next unless include?(opts, p.name, tname)
60
+ visible << " #{judge.name}/#{tname}"
61
+ next unless include?(opts, judge.name, tname)
61
62
  yaml = YAML.load_file(f, permitted_classes: [Time])
62
63
  if yaml['skip']
63
64
  @loog.info("Skippped #{f.to_rel}")
@@ -69,25 +70,31 @@ class Judges::Test
69
70
  end
70
71
  @loog.info("🛠️ Testing #{f.to_rel}:")
71
72
  begin
72
- test_one(opts, p, tname, yaml)
73
+ fb = Factbase.new
74
+ yaml['before']&.each do |n|
75
+ j = judges.get(n)
76
+ @loog.info("Running #{j.script} judge as a pre-condition...")
77
+ test_one(fb, opts, j, n, yaml, assert: false)
78
+ end
79
+ test_one(fb, opts, judge, tname, yaml)
73
80
  tests += 1
74
81
  rescue StandardError => e
75
82
  @loog.warn(Backtrace.new(e))
76
83
  errors << f
77
84
  end
78
85
  end
79
- judges += 1
86
+ tested += 1
80
87
  end
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"
88
+ throw :'👍 No judges tested' if tested.zero?
89
+ throw :"👍 All #{tested} judge(s) but no tests passed" if tests.zero?
90
+ throw :"👍 All #{tested} judge(s) and #{tests} tests passed" if errors.empty?
91
+ throw :"❌ #{tested} judge(s) tested, #{errors.size} of them failed"
85
92
  end
86
93
  unless errors.empty?
87
94
  raise "#{errors.size} tests failed" unless opts['quiet']
88
95
  @loog.debug('Not failing the build with tests failures, due to the --quiet option')
89
96
  end
90
- return unless judges.zero? || tests.zero?
97
+ return unless tested.zero? || tests.zero?
91
98
  if opts['judge'].nil?
92
99
  raise 'There are seems to be no judges' unless opts['quiet']
93
100
  @loog.debug('Not failing the build with no judges tested, due to the --quiet option')
@@ -106,8 +113,7 @@ class Judges::Test
106
113
  judges.any? { |n| n.match?(%r{^#{name}(/#{tre})?$}) }
107
114
  end
108
115
 
109
- def test_one(opts, judge, tname, yaml)
110
- fb = Factbase.new
116
+ def test_one(fb, opts, judge, tname, yaml, assert: true)
111
117
  inputs = yaml['input']
112
118
  inputs&.each do |i|
113
119
  f = fb.insert
@@ -127,6 +133,7 @@ class Judges::Test
127
133
  fbx = fb
128
134
  fbx = Factbase::Looged.new(fb, @loog) if opts['log']
129
135
  judge.run(fbx, {}, {}, options)
136
+ next unless assert
130
137
  assert(judge, tname, fb, yaml) if r == runs || opts['assert_once'].is_a?(FalseClass)
131
138
  end
132
139
  end
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 [Pack]
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 [(Pack, Integer)]
55
+ # @yield [(Judge, Integer)]
48
56
  def each_with_index
49
57
  idx = 0
50
58
  each do |p|
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.17.0'
28
+ VERSION = '0.18.0'
29
29
  end
@@ -88,6 +88,35 @@ 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'), '$fb.insert.foo = 42')
96
+ FileUtils.mkdir_p(File.join(home, 'second'))
97
+ File.write(File.join(d, 'judges/second/the-second.rb'), '$fb.insert.foo = 55')
98
+ File.write(
99
+ File.join(d, 'judges/first/something.yml'),
100
+ <<-YAML
101
+ input: []
102
+ expected:
103
+ - /fb[count(f)=1]
104
+ YAML
105
+ )
106
+ File.write(
107
+ File.join(d, 'judges/second/something.yml'),
108
+ <<-YAML
109
+ input: []
110
+ before:
111
+ - first
112
+ expected:
113
+ - /fb[count(f)=2]
114
+ YAML
115
+ )
116
+ Judges::Test.new(Loog::NULL).run({}, [home])
117
+ end
118
+ end
119
+
91
120
  def test_one_judge_negative
92
121
  Dir.mktmpdir do |d|
93
122
  File.write(File.join(d, 'foo.rb'), '')
data/test/test__helper.rb CHANGED
@@ -29,3 +29,6 @@ require 'simplecov-cobertura'
29
29
  SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
30
30
 
31
31
  require 'minitest/autorun'
32
+
33
+ require 'minitest/reporters'
34
+ Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new]
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 TestPacks < Minitest::Test
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.17.0
4
+ version: 0.18.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-07-12 00:00:00.000000000 Z
11
+ date: 2024-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace