judges 0.5.0 → 0.7.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: 8eed10a2293bdfe6ddfc33e7623d7eb8f905428f60fd002c55e7eb75afdcd96f
4
- data.tar.gz: df6b6941021d0c4fbcdb22d4608d41365ca7e537104eda09909f56cb4dd8dd3d
3
+ metadata.gz: c525e90c9ec78d8d7b745c026e07d033427b6193e185bd28d2edc153f254c863
4
+ data.tar.gz: bff22a2e3f8d9813261f76df90a7087454e393e66f997822717422d4ddfdc084
5
5
  SHA512:
6
- metadata.gz: 07a943829af24cf0388303f9804f8b476449e3feea10ec3fa3703278ffb96e3b8c7a342d06e611e99168a8711397c380fdb70e8504fecaa22be48a6db0627550
7
- data.tar.gz: 605f4d9c1598a4950098837ae6d8a8a432b882d1d4da75f93df78e530a584101642fbed0eb76d3df728f7dae4adbe30fb86c517ded6c16ff13f907b89ee4f797
6
+ metadata.gz: 7a490f1f175fdf0e663ae3f104c2901b86eed9e6d9b16192e59829802a821ae0cec67dc9a72400d7d40f2be228e3c8323508c8e7a210c1f562db0055d4e1a762
7
+ data.tar.gz: 3ec540d2d05fae0b620a3ee89ac4c1dad8d06cd3387cca7a4076490b9710bedcece3a373500208517ac47f0d14469444c60c783f810227045e7ae831a404aaa5
@@ -18,40 +18,13 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
19
  # SOFTWARE.
20
20
  ---
21
- name: license
21
+ name: copyrights
22
22
  'on':
23
23
  push:
24
- branches:
25
- - master
26
24
  pull_request:
27
- branches:
28
- - master
29
25
  jobs:
30
- license:
26
+ copyrights:
31
27
  runs-on: ubuntu-22.04
32
28
  steps:
33
29
  - uses: actions/checkout@v4
34
- - shell: bash
35
- run: |
36
- header="Copyright (c) $(date +%Y) Yegor Bugayenko"
37
- failed="false"
38
- while IFS= read -r file; do
39
- if ! grep -q "${header}" "${file}"; then
40
- failed="true"
41
- echo "⚠️ Copyright header is not found in: ${file}"
42
- else
43
- echo "File looks good: ${file}"
44
- fi
45
- done < <(find . -type f \( \
46
- -name "Dockerfile" -o \
47
- -name "LICENSE.txt" -o \
48
- -name "Makefile" -o \
49
- -name "Rakefile" -o \
50
- -name "*.sh" -o \
51
- -name "*.rb" -o \
52
- -name "*.fe" -o \
53
- -name "*.yml" \
54
- \) -print)
55
- if [ "${failed}" = "true" ]; then
56
- exit 1
57
- fi
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
@@ -47,7 +47,7 @@ GEM
47
47
  backtrace (0.4.0)
48
48
  base64 (0.2.0)
49
49
  bigdecimal (3.1.8)
50
- builder (3.2.4)
50
+ builder (3.3.0)
51
51
  concurrent-ruby (1.2.3)
52
52
  connection_pool (2.4.1)
53
53
  crack (1.0.0)
@@ -85,7 +85,7 @@ GEM
85
85
  erubi (1.12.0)
86
86
  ethon (0.16.0)
87
87
  ffi (>= 1.15.0)
88
- factbase (0.0.42)
88
+ factbase (0.0.44)
89
89
  json (~> 2.7)
90
90
  loog (~> 0.2)
91
91
  nokogiri (~> 1.10)
@@ -209,7 +209,7 @@ GEM
209
209
  rubocop-performance (1.21.0)
210
210
  rubocop (>= 1.48.1, < 2.0)
211
211
  rubocop-ast (>= 1.31.1, < 2.0)
212
- rubocop-rspec (2.30.0)
212
+ rubocop-rspec (2.31.0)
213
213
  rubocop (~> 1.40)
214
214
  rubocop-capybara (~> 2.17)
215
215
  rubocop-factory_bot (~> 2.22)
@@ -263,7 +263,7 @@ DEPENDENCIES
263
263
  rspec-rails (= 6.1.2)
264
264
  rubocop (= 1.64.1)
265
265
  rubocop-performance (= 1.21.0)
266
- rubocop-rspec (= 2.30.0)
266
+ rubocop-rspec (= 2.31.0)
267
267
  simplecov (= 0.22.0)
268
268
  simplecov-cobertura (= 2.1.0)
269
269
  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
@@ -138,6 +138,8 @@ class App
138
138
  c.flag([:enable], multiple: true)
139
139
  c.desc 'Name of the judge to run (directory name)'
140
140
  c.flag([:judge], multiple: true)
141
+ c.desc 'How many times to run?'
142
+ c.flag([:runs], type: Integer, default_value: 1)
141
143
  c.desc 'The location of a Ruby library (directory with .rb files to include)'
142
144
  c.flag([:lib])
143
145
  c.desc 'Stay quiet even if some tests fail or simply no tests executed?'
@@ -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.5.0'
29
+ s.version = '0.7.0'
30
30
  s.license = 'MIT'
31
31
  s.summary = 'Command-Line Tool for a Factbase'
32
32
  s.description =
@@ -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,9 @@ class Judges::Test
122
122
  end
123
123
  end
124
124
  options = Judges::Options.new(opts['option']) + Judges::Options.new(yaml['options'])
125
- judge.run(Factbase::Looged.new(fb, @loog), {}, {}, options)
125
+ (1..(opts['runs'] || yaml['runs'] || 1)).each do
126
+ judge.run(Factbase::Looged.new(fb, @loog), {}, {}, options)
127
+ end
126
128
  xpaths = yaml['expected']
127
129
  return if xpaths.nil?
128
130
  xml = Nokogiri::XML.parse(Factbase::ToXML.new(fb).xml)
@@ -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'
@@ -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} 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
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.5.0'
28
+ VERSION = '0.7.0'
29
29
  end
@@ -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.5.0
4
+ version: 0.7.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-06 00:00:00.000000000 Z
11
+ date: 2024-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace
@@ -151,7 +151,7 @@ files:
151
151
  - ".gitattributes"
152
152
  - ".github/workflows/actionlint.yml"
153
153
  - ".github/workflows/codecov.yml"
154
- - ".github/workflows/license.yml"
154
+ - ".github/workflows/copyrights.yml"
155
155
  - ".github/workflows/markdown-lint.yml"
156
156
  - ".github/workflows/pdd.yml"
157
157
  - ".github/workflows/rake.yml"
@@ -190,6 +190,7 @@ files:
190
190
  - lib/judges.rb
191
191
  - lib/judges/baza.rb
192
192
  - lib/judges/categories.rb
193
+ - lib/judges/churn.rb
193
194
  - lib/judges/commands/eval.rb
194
195
  - lib/judges/commands/import.rb
195
196
  - lib/judges/commands/inspect.rb
@@ -220,6 +221,7 @@ files:
220
221
  - test/test__helper.rb
221
222
  - test/test_baza.rb
222
223
  - test/test_categories.rb
224
+ - test/test_churn.rb
223
225
  - test/test_impex.rb
224
226
  - test/test_judge.rb
225
227
  - test/test_judges.rb