judges 0.6.0 → 0.8.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: 14d7a10c327b1cbd22dcc87773e6c3f218598a5f7d879f6f8c3ff2ddabc9018c
4
- data.tar.gz: '0106468efd8e11754252950a2249ab0f2cbd22a9ed2081867e88e154ae2c0cc0'
3
+ metadata.gz: fe5a5448e7e30ad547e467c6493f793b9148ea9cfea8317406902d53b4f7a270
4
+ data.tar.gz: 36b9e68a0797bb79118c51b68b56a2740b5ace3eaae26ed83af97b38f2f80cbc
5
5
  SHA512:
6
- metadata.gz: 7035bfcbf8e162ef9c4504fdb9953ad275bae7c00123d692bfd8b612bef16745e144b3b51e10560890d79681c48fb37d1f2d3a9030f6caba8896c0a76a6925e6
7
- data.tar.gz: '09533523b712227e1fced16b32a74abd450e9f454d217574c9b35334564718f034283bd9b61cdc39ee1e654798ddb4f439199284d6ed66827024dcb347299c50'
6
+ metadata.gz: 4601b3a1361db40b6b5c4a4d718f47016299583155933ca2168471f0c94de92e81ee9328831b99203b81faa6a872f9ac745bdaaba77ff159513161b32c7a316c
7
+ data.tar.gz: ed839d853ee202832dc23572b52059ea00f1992e148740bc55ade1ec951d4a03759b6f4359e85c1efbb57029a69328f60df5de28d6fed70e548f852586ce88ab
@@ -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.3
30
+ - uses: yegor256/copyrights-action@0.0.4
data/Gemfile CHANGED
@@ -30,7 +30,7 @@ gem 'rake', '13.2.1', require: false
30
30
  gem 'rspec-rails', '6.1.2', require: false
31
31
  gem 'rubocop', '1.64.1', require: false
32
32
  gem 'rubocop-performance', '1.21.0', require: false
33
- gem 'rubocop-rspec', '2.30.0', require: false
33
+ gem 'rubocop-rspec', '2.31.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
@@ -8,8 +8,10 @@ PATH
8
8
  gli (~> 2.21)
9
9
  iri (~> 0.8)
10
10
  loog (~> 0.2)
11
+ moments (~> 0.3)
11
12
  nokogiri (~> 1.10)
12
13
  retries (~> 0.0)
14
+ tago (~> 0.0)
13
15
  typhoeus (~> 1.3)
14
16
 
15
17
  GEM
@@ -85,7 +87,7 @@ GEM
85
87
  erubi (1.12.0)
86
88
  ethon (0.16.0)
87
89
  ffi (>= 1.15.0)
88
- factbase (0.0.44)
90
+ factbase (0.0.48)
89
91
  json (~> 2.7)
90
92
  loog (~> 0.2)
91
93
  nokogiri (~> 1.10)
@@ -114,6 +116,7 @@ GEM
114
116
  loog (0.5.1)
115
117
  mini_mime (1.1.5)
116
118
  minitest (5.23.1)
119
+ moments (0.3.0)
117
120
  multi_test (1.1.0)
118
121
  mutex_m (0.2.0)
119
122
  net-ping (2.0.8)
@@ -131,7 +134,7 @@ GEM
131
134
  racc (~> 1.4)
132
135
  nokogiri (1.16.5-x86_64-linux)
133
136
  racc (~> 1.4)
134
- parallel (1.24.0)
137
+ parallel (1.25.1)
135
138
  parser (3.3.2.0)
136
139
  ast (~> 2.4.1)
137
140
  racc
@@ -139,7 +142,7 @@ GEM
139
142
  stringio
140
143
  public_suffix (5.0.5)
141
144
  racc (1.8.0)
142
- rack (3.0.11)
145
+ rack (3.1.0)
143
146
  rack-session (2.0.0)
144
147
  rack (>= 3.0.0)
145
148
  rack-test (2.1.0)
@@ -170,8 +173,8 @@ GEM
170
173
  reline (0.5.8)
171
174
  io-console (~> 0.5)
172
175
  retries (0.0.5)
173
- rexml (3.2.8)
174
- strscan (>= 3.0.9)
176
+ rexml (3.3.0)
177
+ strscan
175
178
  rspec-core (3.13.0)
176
179
  rspec-support (~> 3.13.0)
177
180
  rspec-expectations (3.13.0)
@@ -202,19 +205,19 @@ GEM
202
205
  unicode-display_width (>= 2.4.0, < 3.0)
203
206
  rubocop-ast (1.31.3)
204
207
  parser (>= 3.3.1.0)
205
- rubocop-capybara (2.20.0)
208
+ rubocop-capybara (2.21.0)
206
209
  rubocop (~> 1.41)
207
- rubocop-factory_bot (2.25.1)
210
+ rubocop-factory_bot (2.26.0)
208
211
  rubocop (~> 1.41)
209
212
  rubocop-performance (1.21.0)
210
213
  rubocop (>= 1.48.1, < 2.0)
211
214
  rubocop-ast (>= 1.31.1, < 2.0)
212
- rubocop-rspec (2.30.0)
215
+ rubocop-rspec (2.31.0)
213
216
  rubocop (~> 1.40)
214
217
  rubocop-capybara (~> 2.17)
215
218
  rubocop-factory_bot (~> 2.22)
216
219
  rubocop-rspec_rails (~> 2.28)
217
- rubocop-rspec_rails (2.28.3)
220
+ rubocop-rspec_rails (2.29.0)
218
221
  rubocop (~> 1.40)
219
222
  ruby-progressbar (1.13.0)
220
223
  simplecov (0.22.0)
@@ -228,8 +231,9 @@ GEM
228
231
  simplecov_json_formatter (0.1.4)
229
232
  stringio (3.1.0)
230
233
  strscan (3.1.0)
231
- sys-uname (1.2.3)
234
+ sys-uname (1.3.0)
232
235
  ffi (~> 1.1)
236
+ tago (0.0.1)
233
237
  thor (1.3.1)
234
238
  typhoeus (1.4.1)
235
239
  ethon (>= 0.9.0)
@@ -263,7 +267,7 @@ DEPENDENCIES
263
267
  rspec-rails (= 6.1.2)
264
268
  rubocop (= 1.64.1)
265
269
  rubocop-performance (= 1.21.0)
266
- rubocop-rspec (= 2.30.0)
270
+ rubocop-rspec (= 2.31.0)
267
271
  simplecov (= 0.22.0)
268
272
  simplecov-cobertura (= 2.1.0)
269
273
  webmock (= 3.23.1)
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
+ category: slow
38
+ runs: 1
37
39
  skip: false
38
40
  input:
39
41
  -
@@ -52,6 +54,12 @@ via the command line `--option` flag of the `update` command; and `expected` is
52
54
  an array of XPath expressions that must be present in the XML of the Factbase
53
55
  when the test is finished.
54
56
 
57
+ The `category` (default: `[]`) may have one or an array of categories,
58
+ which then may be turned on via the `--category` command line flag.
59
+
60
+ The `runs` (default: `1`) is the number of times the `.rb` script should
61
+ be executed. After each execution, all expected XPath expressions are validated.
62
+
55
63
  ## How to contribute
56
64
 
57
65
  Read
data/bin/judges CHANGED
@@ -64,6 +64,8 @@ class App
64
64
  c.flag([:'max-cycles'], default_value: 8, type: Integer)
65
65
  c.desc 'Stay quiet even if some judges fail'
66
66
  c.switch([:q, :quiet], default_value: false)
67
+ c.desc 'Use default logging facility'
68
+ c.switch([:log], default_value: true)
67
69
  c.action do |global, options, args|
68
70
  require_relative '../lib/judges/commands/update'
69
71
  Judges::Update.new(loog).run(options, args)
@@ -47,6 +47,25 @@ Feature: Test
47
47
  Then Stdout contains "All 1 judge(s) and 1 tests passed"
48
48
  And Exit code is zero
49
49
 
50
+ Scenario: Simple test with two runs
51
+ Given I make a temp directory
52
+ Then I have a "foo/simple.rb" file with content:
53
+ """
54
+ n = $fb.insert
55
+ n.foo = $fb.size
56
+ """
57
+ Then I have a "foo/good.yml" file with content:
58
+ """
59
+ ---
60
+ runs: 3
61
+ input: []
62
+ expected:
63
+ - /fb/f[foo=count(/fb/f)]
64
+ """
65
+ Then I run bin/judges with "test ."
66
+ Then Stdout contains "All 1 judge(s) and 1 tests passed"
67
+ And Exit code is zero
68
+
50
69
  Scenario: Enable only one category
51
70
  Given I make a temp directory
52
71
  Then I have a "mine/good/good.rb" file with content:
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.6.0'
29
+ s.version = '0.8.0'
30
30
  s.license = 'MIT'
31
31
  s.summary = 'Command-Line Tool for a Factbase'
32
32
  s.description =
@@ -48,8 +48,10 @@ Gem::Specification.new do |s|
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'
51
+ s.add_runtime_dependency 'moments', '~>0.3'
51
52
  s.add_runtime_dependency 'nokogiri', '~>1.10'
52
53
  s.add_runtime_dependency 'retries', '~>0.0'
54
+ s.add_runtime_dependency 'tago', '~>0.0'
53
55
  s.add_runtime_dependency 'typhoeus', '~>1.3'
54
56
  s.metadata['rubygems_mfa_required'] = 'true'
55
57
  end
@@ -0,0 +1,60 @@
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_relative '../judges'
24
+
25
+ # How many facts were modified.
26
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
27
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
28
+ # License:: MIT
29
+ class Judges::Churn
30
+ attr_reader :added, :removed
31
+
32
+ def initialize(added, removed)
33
+ @added = added
34
+ @removed = removed
35
+ end
36
+
37
+ def to_s
38
+ "#{@added}/#{@removed}"
39
+ end
40
+
41
+ def zero?
42
+ @added.zero? && @removed.zero?
43
+ end
44
+
45
+ def +(other)
46
+ if other.is_a?(Judges::Churn)
47
+ Judges::Churn.new(@added + other.added, @removed + other.removed)
48
+ else
49
+ Judges::Churn.new(@added + other, @removed)
50
+ end
51
+ end
52
+
53
+ def -(other)
54
+ if other.is_a?(Judges::Churn)
55
+ Judges::Churn.new(@added - other.added, @removed - other.removed)
56
+ else
57
+ Judges::Churn.new(@added, @removed + other)
58
+ end
59
+ end
60
+ end
@@ -122,7 +122,7 @@ class Judges::Test
122
122
  end
123
123
  end
124
124
  options = Judges::Options.new(opts['option']) + Judges::Options.new(yaml['options'])
125
- (1..(opts['runs'] || 1)).each do
125
+ (1..(opts['runs'] || yaml['runs'] || 1)).each do
126
126
  judge.run(Factbase::Looged.new(fb, @loog), {}, {}, options)
127
127
  end
128
128
  xpaths = yaml['expected']
@@ -25,6 +25,7 @@ require 'factbase/looged'
25
25
  require_relative '../../judges'
26
26
  require_relative '../../judges/to_rel'
27
27
  require_relative '../../judges/judges'
28
+ require_relative '../../judges/churn'
28
29
  require_relative '../../judges/options'
29
30
  require_relative '../../judges/impex'
30
31
  require_relative '../../judges/elapsed'
@@ -44,7 +45,7 @@ class Judges::Update
44
45
  raise "The directory is absent: #{dir.to_rel}" unless File.exist?(dir)
45
46
  impex = Judges::Impex.new(@loog, args[1])
46
47
  fb = impex.import(strict: false)
47
- fb = Factbase::Looged.new(fb, @loog)
48
+ fb = Factbase::Looged.new(fb, @loog) if opts['log']
48
49
  before = fb.size
49
50
  options = Judges::Options.new(opts['option'])
50
51
  @loog.debug("The following options provided:\n\t#{options.to_s.gsub("\n", "\n\t")}")
@@ -72,42 +73,21 @@ class Judges::Update
72
73
  end
73
74
  end
74
75
 
75
- # How many facts were modified.
76
- class Churn
77
- attr_reader :added, :removed
78
-
79
- def initialize(added, removed)
80
- @added = added
81
- @removed = removed
82
- end
83
-
84
- def to_s
85
- "#{@added}/-#{@removed}"
86
- end
87
-
88
- def zero?
89
- @added.zero? && @removed.zero?
90
- end
91
-
92
- def +(other)
93
- Churn.new(@added + other.added, @removed + other.removed)
94
- end
95
- end
96
-
97
76
  private
98
77
 
99
78
  # Run all judges in a full cycle, one by one.
100
79
  # @return [Churn] How many modifications have been made
101
80
  def cycle(opts, judges, fb, options)
102
81
  errors = []
103
- churn = Churn.new(0, 0)
82
+ churn = Judges::Churn.new(0, 0)
104
83
  global = {}
105
84
  elapsed(@loog) do
106
85
  done = judges.each_with_index do |p, i|
107
- @loog.info("\n👉 Running #{p.name} (##{i}) at #{p.dir.to_rel}...")
86
+ @loog.info("\n\n👉 Running #{p.name} (##{i}) at #{p.dir.to_rel}...")
108
87
  elapsed(@loog) do
109
- churn += one_judge(fb, p, global, options)
110
- throw :"👍 The judge #{p.name} modified #{churn} facts\n"
88
+ c = one_judge(fb, p, global, options)
89
+ churn += c
90
+ throw :"👍 The judge #{p.name} modified #{c.zero? ? 'no' : c} facts"
111
91
  end
112
92
  rescue StandardError, SyntaxError => e
113
93
  @loog.warn(Backtrace.new(e))
@@ -132,9 +112,9 @@ class Judges::Update
132
112
  after = fb.size
133
113
  diff = after - before
134
114
  if diff.positive?
135
- Churn.new(diff, 0)
115
+ Judges::Churn.new(diff, 0)
136
116
  else
137
- Churn.new(0, -diff)
117
+ Judges::Churn.new(0, -diff)
138
118
  end
139
119
  end
140
120
  end
@@ -20,6 +20,8 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  # SOFTWARE.
22
22
 
23
+ require 'tago'
24
+
23
25
  def elapsed(loog)
24
26
  start = Time.now
25
27
  begin
@@ -27,6 +29,6 @@ def elapsed(loog)
27
29
  rescue UncaughtThrowError => e
28
30
  tag = e.tag
29
31
  throw e unless tag.is_a?(Symbol)
30
- loog.info("#{tag} in #{format('%.02f', Time.now - start)}s")
32
+ loog.info("#{tag} in #{start.ago}")
31
33
  end
32
34
  end
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.6.0'
28
+ VERSION = '0.8.0'
29
29
  end
@@ -41,7 +41,7 @@ class TestPrint < Minitest::Test
41
41
  Judges::Print.new(Loog::NULL).run({ format: 'yaml', auto: true }, [f])
42
42
  y = File.join(d, 'base.yaml')
43
43
  assert(File.exist?(y))
44
- assert_equal(1, YAML.load_file(y)['facts'].size)
44
+ assert_equal(1, YAML.load_file(y).size)
45
45
  end
46
46
  end
47
47
 
@@ -0,0 +1,38 @@
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_relative '../lib/judges'
25
+ require_relative '../lib/judges/churn'
26
+
27
+ # Test.
28
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
29
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
30
+ # License:: MIT
31
+ class TestChurn < Minitest::Test
32
+ def test_basic
33
+ churn = Judges::Churn.new(0, 0)
34
+ assert_equal('0/0', churn.to_s)
35
+ assert_equal('42/0', (churn + 42).to_s)
36
+ assert_equal('0/17', (churn - 17).to_s)
37
+ end
38
+ 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.6.0
4
+ version: 0.8.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-06-07 00:00:00.000000000 Z
11
+ date: 2024-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0.2'
97
+ - !ruby/object:Gem::Dependency
98
+ name: moments
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.3'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.3'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: nokogiri
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +136,20 @@ dependencies:
122
136
  - - "~>"
123
137
  - !ruby/object:Gem::Version
124
138
  version: '0.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: tago
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.0'
125
153
  - !ruby/object:Gem::Dependency
126
154
  name: typhoeus
127
155
  requirement: !ruby/object:Gem::Requirement
@@ -190,6 +218,7 @@ files:
190
218
  - lib/judges.rb
191
219
  - lib/judges/baza.rb
192
220
  - lib/judges/categories.rb
221
+ - lib/judges/churn.rb
193
222
  - lib/judges/commands/eval.rb
194
223
  - lib/judges/commands/import.rb
195
224
  - lib/judges/commands/inspect.rb
@@ -220,6 +249,7 @@ files:
220
249
  - test/test__helper.rb
221
250
  - test/test_baza.rb
222
251
  - test/test_categories.rb
252
+ - test/test_churn.rb
223
253
  - test/test_impex.rb
224
254
  - test/test_judge.rb
225
255
  - test/test_judges.rb