judges 0.0.23 → 0.0.25

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: 15c96f4af35d626de3ae2f9de6d510550b2307a014b0a76148219f8a04091907
4
- data.tar.gz: 19e2b425671a4a711b1c0ebf62b1ad17c25d13c355aeef050a48c030b22a47a0
3
+ metadata.gz: 2326cabc04af248b0125f37645bd07fce0d9f19633f6ebaa10fdcf134da35b73
4
+ data.tar.gz: ede2d649e85f3d5f637daaa963bf56887b2150345ede96bb7fd4c53f7e5f1400
5
5
  SHA512:
6
- metadata.gz: fe53d0e31dcd30a125d8130fbb46ed1f13709a13f642c8e19db9ae74ef4aeb1485ea374ede9f1abe1f0f1308331fc98f507c532a97803a75b96c8fbf4a6f79b3
7
- data.tar.gz: 36a8369665200eb177572803b555c4948ccfe1f96cc2ed695c9c104bcb8cf89ca11204224ddf2549ad5fa5f7ff7082069edd87e1aa94ac1acca7be22df54f1a7
6
+ metadata.gz: 5ed7d4a0d763cd9f1a5a565033cd42e69e8d52b113f8b117832861ad8d9c22194667ef6759aa8c4c8806cc754435a3cb9583c9951183eba01c7cb3f4aa83f03e
7
+ data.tar.gz: f3bfaee1fe32ff3315a533dc67019edc9e6c7fbb22db758917a17c0a643dc0a60a69e2e3641d9a954c426e39c928bef098ff1309dad18ce14bd69cf77aa061b0
@@ -19,7 +19,7 @@
19
19
  # SOFTWARE.
20
20
  ---
21
21
  name: codecov
22
- on:
22
+ 'on':
23
23
  push:
24
24
  branches:
25
25
  - master
@@ -31,7 +31,8 @@ jobs:
31
31
  - uses: ruby/setup-ruby@v1
32
32
  with:
33
33
  ruby-version: 3.2
34
- - run: bundle update
34
+ bundler-cache: true
35
+ - run: bundle install
35
36
  - run: bundle exec rake
36
37
  - uses: codecov/codecov-action@v4.0.0-beta.3
37
38
  with:
@@ -31,7 +31,7 @@ jobs:
31
31
  name: test
32
32
  strategy:
33
33
  matrix:
34
- os: [ubuntu-20.04, macos-12]
34
+ os: [ubuntu-20.04, macos-12, windows-2022]
35
35
  ruby: [3.2]
36
36
  runs-on: ${{ matrix.os }}
37
37
  steps:
@@ -39,5 +39,6 @@ jobs:
39
39
  - uses: ruby/setup-ruby@v1
40
40
  with:
41
41
  ruby-version: ${{ matrix.ruby }}
42
- - run: bundle update
42
+ bundler-cache: true
43
+ - run: bundle install
43
44
  - run: bundle exec rake
data/.gitignore CHANGED
@@ -1,5 +1,4 @@
1
1
  coverage/
2
- Gemfile.lock
3
2
  .idea/
4
3
  *.gem
5
4
  .bundle/
data/.rubocop.yml CHANGED
@@ -22,6 +22,7 @@ AllCops:
22
22
  Exclude:
23
23
  - 'bin/**/*'
24
24
  - 'assets/**/*'
25
+ - 'vendor/**/*'
25
26
  DisplayCopNames: true
26
27
  TargetRubyVersion: 3.2
27
28
  SuggestExtensions: false
@@ -51,3 +52,5 @@ Layout/CaseIndentation:
51
52
  Enabled: false
52
53
  Naming/MethodParameterName:
53
54
  MinNameLength: 2
55
+ Layout/EndOfLine:
56
+ EnforcedStyle: lf
data/Gemfile CHANGED
@@ -24,10 +24,11 @@ source 'https://rubygems.org'
24
24
  gemspec
25
25
 
26
26
  gem 'cucumber', '9.2.0', require: false
27
- gem 'minitest', '5.22.3', require: false
27
+ gem 'minitest', '5.23.0', require: false
28
28
  gem 'rake', '13.2.1', require: false
29
29
  gem 'rspec-rails', '6.1.2', require: false
30
30
  gem 'rubocop', '1.63.5', require: false
31
+ gem 'rubocop-performance', '1.21.0', require: false
31
32
  gem 'rubocop-rspec', '2.29.2', require: false
32
33
  gem 'simplecov', '0.22.0', require: false
33
34
  gem 'simplecov-cobertura', '2.1.0', require: false
data/Gemfile.lock ADDED
@@ -0,0 +1,235 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ judges (0.0.0)
5
+ backtrace (~> 0.3)
6
+ factbase (~> 0.0.22)
7
+ gli (~> 2.21)
8
+ loog (~> 0.2)
9
+ nokogiri (~> 1.10)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ actionpack (7.1.3.3)
15
+ actionview (= 7.1.3.3)
16
+ activesupport (= 7.1.3.3)
17
+ nokogiri (>= 1.8.5)
18
+ racc
19
+ rack (>= 2.2.4)
20
+ rack-session (>= 1.0.1)
21
+ rack-test (>= 0.6.3)
22
+ rails-dom-testing (~> 2.2)
23
+ rails-html-sanitizer (~> 1.6)
24
+ actionview (7.1.3.3)
25
+ activesupport (= 7.1.3.3)
26
+ builder (~> 3.1)
27
+ erubi (~> 1.11)
28
+ rails-dom-testing (~> 2.2)
29
+ rails-html-sanitizer (~> 1.6)
30
+ activesupport (7.1.3.3)
31
+ base64
32
+ bigdecimal
33
+ concurrent-ruby (~> 1.0, >= 1.0.2)
34
+ connection_pool (>= 2.2.5)
35
+ drb
36
+ i18n (>= 1.6, < 2)
37
+ minitest (>= 5.1)
38
+ mutex_m
39
+ tzinfo (~> 2.0)
40
+ ast (2.4.2)
41
+ backtrace (0.4.0)
42
+ base64 (0.2.0)
43
+ bigdecimal (3.1.8)
44
+ builder (3.2.4)
45
+ concurrent-ruby (1.2.3)
46
+ connection_pool (2.4.1)
47
+ crass (1.0.6)
48
+ cucumber (9.2.0)
49
+ builder (~> 3.2)
50
+ cucumber-ci-environment (> 9, < 11)
51
+ cucumber-core (> 13, < 14)
52
+ cucumber-cucumber-expressions (~> 17.0)
53
+ cucumber-gherkin (> 24, < 28)
54
+ cucumber-html-formatter (> 20.3, < 22)
55
+ cucumber-messages (> 19, < 25)
56
+ diff-lcs (~> 1.5)
57
+ mini_mime (~> 1.1)
58
+ multi_test (~> 1.1)
59
+ sys-uname (~> 1.2)
60
+ cucumber-ci-environment (10.0.1)
61
+ cucumber-core (13.0.2)
62
+ cucumber-gherkin (>= 27, < 28)
63
+ cucumber-messages (>= 20, < 23)
64
+ cucumber-tag-expressions (> 5, < 7)
65
+ cucumber-cucumber-expressions (17.1.0)
66
+ bigdecimal
67
+ cucumber-gherkin (27.0.0)
68
+ cucumber-messages (>= 19.1.4, < 23)
69
+ cucumber-html-formatter (21.3.1)
70
+ cucumber-messages (> 19, < 25)
71
+ cucumber-messages (22.0.0)
72
+ cucumber-tag-expressions (6.1.0)
73
+ diff-lcs (1.5.1)
74
+ docile (1.4.0)
75
+ drb (2.2.1)
76
+ erubi (1.12.0)
77
+ factbase (0.0.22)
78
+ json (~> 2.7)
79
+ loog (~> 0.2)
80
+ nokogiri (~> 1.10)
81
+ yaml (~> 0.3)
82
+ ffi (1.16.3)
83
+ ffi (1.16.3-x64-mingw-ucrt)
84
+ gli (2.21.1)
85
+ i18n (1.14.5)
86
+ concurrent-ruby (~> 1.0)
87
+ io-console (0.7.2)
88
+ irb (1.13.1)
89
+ rdoc (>= 4.0.0)
90
+ reline (>= 0.4.2)
91
+ json (2.7.2)
92
+ language_server-protocol (3.17.0.3)
93
+ loofah (2.22.0)
94
+ crass (~> 1.0.2)
95
+ nokogiri (>= 1.12.0)
96
+ loog (0.5.1)
97
+ mini_mime (1.1.5)
98
+ minitest (5.23.0)
99
+ multi_test (1.1.0)
100
+ mutex_m (0.2.0)
101
+ nokogiri (1.16.5-arm64-darwin)
102
+ racc (~> 1.4)
103
+ nokogiri (1.16.5-x64-mingw-ucrt)
104
+ racc (~> 1.4)
105
+ nokogiri (1.16.5-x86_64-darwin)
106
+ racc (~> 1.4)
107
+ nokogiri (1.16.5-x86_64-linux)
108
+ racc (~> 1.4)
109
+ parallel (1.24.0)
110
+ parser (3.3.1.0)
111
+ ast (~> 2.4.1)
112
+ racc
113
+ psych (5.1.2)
114
+ stringio
115
+ racc (1.7.3)
116
+ rack (3.0.11)
117
+ rack-session (2.0.0)
118
+ rack (>= 3.0.0)
119
+ rack-test (2.1.0)
120
+ rack (>= 1.3)
121
+ rackup (2.1.0)
122
+ rack (>= 3)
123
+ webrick (~> 1.8)
124
+ rails-dom-testing (2.2.0)
125
+ activesupport (>= 5.0.0)
126
+ minitest
127
+ nokogiri (>= 1.6)
128
+ rails-html-sanitizer (1.6.0)
129
+ loofah (~> 2.21)
130
+ nokogiri (~> 1.14)
131
+ railties (7.1.3.3)
132
+ actionpack (= 7.1.3.3)
133
+ activesupport (= 7.1.3.3)
134
+ irb
135
+ rackup (>= 1.0.0)
136
+ rake (>= 12.2)
137
+ thor (~> 1.0, >= 1.2.2)
138
+ zeitwerk (~> 2.6)
139
+ rainbow (3.1.1)
140
+ rake (13.2.1)
141
+ rdoc (6.6.3.1)
142
+ psych (>= 4.0.0)
143
+ regexp_parser (2.9.2)
144
+ reline (0.5.7)
145
+ io-console (~> 0.5)
146
+ rexml (3.2.8)
147
+ strscan (>= 3.0.9)
148
+ rspec-core (3.13.0)
149
+ rspec-support (~> 3.13.0)
150
+ rspec-expectations (3.13.0)
151
+ diff-lcs (>= 1.2.0, < 2.0)
152
+ rspec-support (~> 3.13.0)
153
+ rspec-mocks (3.13.1)
154
+ diff-lcs (>= 1.2.0, < 2.0)
155
+ rspec-support (~> 3.13.0)
156
+ rspec-rails (6.1.2)
157
+ actionpack (>= 6.1)
158
+ activesupport (>= 6.1)
159
+ railties (>= 6.1)
160
+ rspec-core (~> 3.13)
161
+ rspec-expectations (~> 3.13)
162
+ rspec-mocks (~> 3.13)
163
+ rspec-support (~> 3.13)
164
+ rspec-support (3.13.1)
165
+ rubocop (1.63.5)
166
+ json (~> 2.3)
167
+ language_server-protocol (>= 3.17.0)
168
+ parallel (~> 1.10)
169
+ parser (>= 3.3.0.2)
170
+ rainbow (>= 2.2.2, < 4.0)
171
+ regexp_parser (>= 1.8, < 3.0)
172
+ rexml (>= 3.2.5, < 4.0)
173
+ rubocop-ast (>= 1.31.1, < 2.0)
174
+ ruby-progressbar (~> 1.7)
175
+ unicode-display_width (>= 2.4.0, < 3.0)
176
+ rubocop-ast (1.31.3)
177
+ parser (>= 3.3.1.0)
178
+ rubocop-capybara (2.20.0)
179
+ rubocop (~> 1.41)
180
+ rubocop-factory_bot (2.25.1)
181
+ rubocop (~> 1.41)
182
+ rubocop-performance (1.21.0)
183
+ rubocop (>= 1.48.1, < 2.0)
184
+ rubocop-ast (>= 1.31.1, < 2.0)
185
+ rubocop-rspec (2.29.2)
186
+ rubocop (~> 1.40)
187
+ rubocop-capybara (~> 2.17)
188
+ rubocop-factory_bot (~> 2.22)
189
+ rubocop-rspec_rails (~> 2.28)
190
+ rubocop-rspec_rails (2.28.3)
191
+ rubocop (~> 1.40)
192
+ ruby-progressbar (1.13.0)
193
+ simplecov (0.22.0)
194
+ docile (~> 1.1)
195
+ simplecov-html (~> 0.11)
196
+ simplecov_json_formatter (~> 0.1)
197
+ simplecov-cobertura (2.1.0)
198
+ rexml
199
+ simplecov (~> 0.19)
200
+ simplecov-html (0.12.3)
201
+ simplecov_json_formatter (0.1.4)
202
+ stringio (3.1.0)
203
+ strscan (3.1.0)
204
+ sys-uname (1.2.3)
205
+ ffi (~> 1.1)
206
+ thor (1.3.1)
207
+ tzinfo (2.0.6)
208
+ concurrent-ruby (~> 1.0)
209
+ unicode-display_width (2.5.0)
210
+ webrick (1.8.1)
211
+ yaml (0.3.0)
212
+ yard (0.9.36)
213
+ zeitwerk (2.6.14)
214
+
215
+ PLATFORMS
216
+ arm64-darwin-22
217
+ x64-mingw-ucrt
218
+ x86_64-darwin-20
219
+ x86_64-linux
220
+
221
+ DEPENDENCIES
222
+ cucumber (= 9.2.0)
223
+ judges!
224
+ minitest (= 5.23.0)
225
+ rake (= 13.2.1)
226
+ rspec-rails (= 6.1.2)
227
+ rubocop (= 1.63.5)
228
+ rubocop-performance (= 1.21.0)
229
+ rubocop-rspec (= 2.29.2)
230
+ simplecov (= 0.22.0)
231
+ simplecov-cobertura (= 2.1.0)
232
+ yard (= 0.9.36)
233
+
234
+ BUNDLED WITH
235
+ 2.4.22
data/README.md CHANGED
@@ -14,6 +14,41 @@
14
14
  A command line tool and a Ruby gem for running judges agains a
15
15
  [factbase](https://github.com/yegor256/factbase).
16
16
 
17
+ Every "judge" is a directory with a single `.rb` file and a number
18
+ of `.yml` files. A script in the Ruby file is executed with the following
19
+ global variables available to it:
20
+
21
+ * `$fb` — an instance
22
+ of [`Factbase`](https://www.rubydoc.info/gems/factbase/0.0.22/Factbase),
23
+ where facts may be added/updated;
24
+ * `$loog` — an instance
25
+ of [`Loog`](https://www.rubydoc.info/gems/loog/0.5.1/Loog),
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;
30
+ * `$global` — a hash map that is never cleaned up;
31
+ * `$judge` — the name of the directory, where the `.rb` script is located.
32
+
33
+ Every `.yml` file must be formatted as such:
34
+
35
+ ```yaml
36
+ input:
37
+ -
38
+ foo: 42
39
+ bar: Hello, world!
40
+ options:
41
+ max: 100
42
+ expected:
43
+ - /fb[count(f)=1]
44
+ ```
45
+
46
+ 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
49
+ an array of XPath expressions that must be present in the XML of the Factbase
50
+ when the test is finished.
51
+
17
52
  ## How to contribute
18
53
 
19
54
  Read
data/bin/judges CHANGED
@@ -32,7 +32,7 @@ Encoding.default_internal = Encoding::UTF_8
32
32
  class App
33
33
  extend GLI::App
34
34
 
35
- ver = '0.0.23'
35
+ ver = '0.0.25'
36
36
 
37
37
  loog = Loog::REGULAR
38
38
 
@@ -59,6 +59,8 @@ class App
59
59
  command :update do |c|
60
60
  c.desc 'Options to pass to every judge'
61
61
  c.flag([:o, :option], multiple: true, arg_name: '<key=value>')
62
+ c.desc 'The location of a Ruby library (directory with .rb files to include)'
63
+ c.flag([:lib])
62
64
  c.desc 'Maximum number of update cycles to run'
63
65
  c.flag([:'max-cycles'], default_value: 8, type: Integer)
64
66
  c.desc 'Stay quiet even if some judges fail'
@@ -111,6 +113,8 @@ class App
111
113
  command :test do |c|
112
114
  c.desc 'Name of the test pack to run'
113
115
  c.flag([:pack], multiple: true)
116
+ c.desc 'The location of a Ruby library (directory with .rb files to include)'
117
+ c.flag([:lib])
114
118
  c.desc 'Stay quiet even if some tests fail or simply no tests executed?'
115
119
  c.switch([:quiet], default_value: false)
116
120
  c.action do |global, options, args|
@@ -0,0 +1,16 @@
1
+ Feature: Inspect
2
+ I want to inspect a factbase
3
+
4
+ Scenario: Simple inspect of a small factbase
5
+ Given I make a temp directory
6
+ Then I have a "simple/simple_judge.rb" file with content:
7
+ """
8
+ return if $fb.size > 2
9
+ n = $fb.insert
10
+ n.kind = 'yes!'
11
+ """
12
+ Then I run bin/judges with "update . simple.fb"
13
+ Then I run bin/judges with "inspect simple.fb"
14
+ Then Stdout contains "Facts: 3"
15
+ And Exit code is zero
16
+
@@ -0,0 +1,11 @@
1
+ Feature: Misc
2
+ I want to get some meta info
3
+
4
+ Scenario: Help can be printed
5
+ When I run bin/judges with "-h"
6
+ Then Exit code is zero
7
+ And Stdout contains "--help"
8
+
9
+ Scenario: Version can be printed
10
+ When I run bin/judges with "--version"
11
+ Then Exit code is zero
@@ -0,0 +1,41 @@
1
+ Feature: Print
2
+ I want to print a factbase
3
+
4
+ Scenario: Simple print of a small factbase, to YAML
5
+ Given I make a temp directory
6
+ Then I have a "simple/simple_judge.rb" file with content:
7
+ """
8
+ return if $fb.size > 2
9
+ n = $fb.insert
10
+ n.kind = 'yes!'
11
+ """
12
+ Then I run bin/judges with "update . simple.fb"
13
+ Then I run bin/judges with "print --format=yaml simple.fb simple.yml"
14
+ Then Stdout contains "printed"
15
+ And Exit code is zero
16
+
17
+ Scenario: Simple print of a small factbase, to JSON
18
+ Given I make a temp directory
19
+ Then I have a "simple/simple_judge.rb" file with content:
20
+ """
21
+ return if $fb.size > 2
22
+ n = $fb.insert
23
+ n.kind = 'yes!'
24
+ """
25
+ Then I run bin/judges with "update . simple.fb"
26
+ Then I run bin/judges with "print --format=json simple.fb simple.json"
27
+ Then Stdout contains "printed"
28
+ And Exit code is zero
29
+
30
+ Scenario: Simple print of a small factbase, to XML
31
+ Given I make a temp directory
32
+ Then I have a "simple/simple_judge.rb" file with content:
33
+ """
34
+ return if $fb.size > 2
35
+ n = $fb.insert
36
+ n.kind = 'yes!'
37
+ """
38
+ Then I run bin/judges with "update . simple.fb"
39
+ Then I run bin/judges with "print --format=xml --auto simple.fb"
40
+ Then Stdout contains "printed"
41
+ And Exit code is zero
@@ -47,7 +47,9 @@ end
47
47
 
48
48
  When(%r{^I run bin/judges with "([^"]*)"$}) do |arg|
49
49
  home = File.join(File.dirname(__FILE__), '../..')
50
- @stdout = `GLI_DEBUG=true ruby -I#{home}/lib #{home}/bin/judges #{arg}`
50
+ cmd = "ruby -I#{home}/lib #{home}/bin/judges #{arg}"
51
+ cmd = "GLI_DEBUG=true #{cmd}" unless Gem.win_platform?
52
+ @stdout = `#{cmd}`
51
53
  @exitstatus = $CHILD_STATUS.exitstatus
52
54
  end
53
55
 
@@ -0,0 +1,32 @@
1
+ Feature: Test
2
+ I want to test a few judges
3
+
4
+ Scenario: Simple test of a few judges
5
+ Given I run bin/judges with "test ./fixtures"
6
+ Then Stdout contains "👉 Testing"
7
+ Then Stdout contains "judge(s) tested successfully"
8
+ And Exit code is zero
9
+
10
+ Scenario: Simple test of just one pack
11
+ Given I run bin/judges with "test --pack reward_for_good_bug ./fixtures"
12
+ Then Stdout contains "judge(s) tested successfully"
13
+ And Exit code is zero
14
+
15
+ Scenario: Simple test of no packs
16
+ Given I run bin/judges with "test --pack absent_for_sure ./fixtures"
17
+ Then Exit code is not zero
18
+
19
+ Scenario: Simple test of a few judges, with a lib
20
+ Given I make a temp directory
21
+ Then I have a "mypacks/mypack/simple_judge.rb" file with content:
22
+ """
23
+ n = $fb.insert
24
+ n.foo = $foo
25
+ """
26
+ Then I have a "mylib/foo.rb" file with content:
27
+ """
28
+ $foo = 42
29
+ """
30
+ Then I run bin/judges with "test --lib mylib mypacks"
31
+ Then Stdout contains "All 1 judge(s) tested successfully"
32
+ And Exit code is zero
@@ -0,0 +1,14 @@
1
+ Feature: Trim
2
+ I want to trim a factbase
3
+
4
+ Scenario: Simple trimming of a factbase
5
+ Given I make a temp directory
6
+ Then I have a "simple/simple_judge.rb" file with content:
7
+ """
8
+ return if $fb.size > 2
9
+ $fb.insert.time = Time.now - 100 * 60 * 60 * 24
10
+ """
11
+ Then I run bin/judges with "--verbose update . simple.fb"
12
+ Given I run bin/judges with "trim --days 5 simple.fb"
13
+ Then Stdout contains "3 fact(s) deleted"
14
+ And Exit code is zero
@@ -0,0 +1,32 @@
1
+ Feature: Update
2
+ I want to run a few judges over a factbase
3
+
4
+ Scenario: Simple run of a few judges
5
+ Given I make a temp directory
6
+ Then I have a "simple/simple_judge.rb" file with content:
7
+ """
8
+ n = $fb.insert
9
+ n.kind = 'yes!'
10
+ """
11
+ Then I run bin/judges with "--verbose update --quiet -o foo=1 -o bar=2 --max-cycles 3 . simple.fb"
12
+ Then Stdout contains "foo → "
13
+ Then Stdout contains "bar → "
14
+ Then Stdout contains "1 judge(s) processed"
15
+ Then Stdout contains "Update finished in 3 cycles"
16
+ And Exit code is zero
17
+
18
+ Scenario: Simple run of a few judges, with a lib
19
+ Given I make a temp directory
20
+ Then I have a "mypacks/mypack/simple_judge.rb" file with content:
21
+ """
22
+ n = $fb.insert
23
+ n.foo = $foo
24
+ """
25
+ Then I have a "mylib/foo.rb" file with content:
26
+ """
27
+ $foo = 42
28
+ """
29
+ Then I run bin/judges with "update --lib mylib --max-cycles 1 mypacks simple.fb"
30
+ Then Stdout contains "1 judge(s) processed"
31
+ Then Stdout contains "Update finished in 1 cycles"
32
+ 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.0.23'
29
+ s.version = '0.0.25'
30
30
  s.license = 'MIT'
31
31
  s.summary = 'Command-Line Tool for a Factbase'
32
32
  s.description = '
@@ -42,7 +42,7 @@ Gem::Specification.new do |s|
42
42
  s.rdoc_options = ['--charset=UTF-8']
43
43
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
44
44
  s.add_runtime_dependency 'backtrace', '~> 0.3'
45
- s.add_runtime_dependency 'factbase', '~>0.0.21'
45
+ s.add_runtime_dependency 'factbase', '~>0.0.22'
46
46
  s.add_runtime_dependency 'gli', '~>2.21'
47
47
  s.add_runtime_dependency 'loog', '~>0.2'
48
48
  s.add_runtime_dependency 'nokogiri', '~> 1.10'
@@ -44,14 +44,16 @@ class Judges::Test
44
44
  @loog.info("Testing judges in #{dir.to_rel}...")
45
45
  errors = []
46
46
  done = 0
47
- Judges::Packs.new(dir, @loog).each_with_index do |p, i|
47
+ global = {}
48
+ Judges::Packs.new(dir, opts['lib'], @loog).each_with_index do |p, i|
49
+ local = {}
48
50
  next unless include?(opts, p.name)
49
51
  @loog.info("\n👉 Testing #{p.script} (##{i}) in #{p.dir.to_rel}...")
50
52
  p.tests.each do |f|
51
53
  yaml = YAML.load_file(f, permitted_classes: [Time])
52
54
  @loog.info("Testing #{f.to_rel}:")
53
55
  begin
54
- test_one(p, yaml)
56
+ test_one(p, global, local, yaml)
55
57
  rescue StandardError => e
56
58
  @loog.warn(Backtrace.new(e))
57
59
  errors << f
@@ -78,7 +80,7 @@ class Judges::Test
78
80
  packs.include?(name)
79
81
  end
80
82
 
81
- def test_one(pack, yaml)
83
+ def test_one(pack, global, local, yaml)
82
84
  fb = Factbase.new
83
85
  yaml['input'].each do |i|
84
86
  f = fb.insert
@@ -92,7 +94,7 @@ class Judges::Test
92
94
  end
93
95
  end
94
96
  end
95
- pack.run(Factbase::Looged.new(fb, @loog), Judges::Options.new(yaml['options']))
97
+ pack.run(Factbase::Looged.new(fb, @loog), global, local, Judges::Options.new(yaml['options']))
96
98
  xml = Nokogiri::XML.parse(fb.to_xml)
97
99
  yaml['expected'].each do |xp|
98
100
  raise "#{pack.script} doesn't match '#{xp}':\n#{xml}" if xml.xpath(xp).empty?
@@ -37,10 +37,14 @@ class Judges::Trim
37
37
  raise 'Exactly one argument required' unless args.size == 1
38
38
  impex = Judges::Impex.new(@loog, args[0])
39
39
  fb = impex.import
40
- day = Time.now - (opts['days'].to_i * 60 * 60 * 24)
41
- p "(lt time #{day.utc.iso8601})"
40
+ days = opts['days']
41
+ day = Time.now - (days * 60 * 60 * 24)
42
42
  deleted = fb.query("(lt time #{day.utc.iso8601})").delete!
43
- @loog.info("#{deleted} facts deleted because they are too old")
44
- impex.export(fb)
43
+ if deleted.zero?
44
+ @loog.info('No facts deleted')
45
+ else
46
+ @loog.info("🗑 #{deleted} fact(s) deleted, because they were older than #{days} days")
47
+ impex.export(fb)
48
+ end
45
49
  end
46
50
  end
@@ -46,7 +46,7 @@ class Judges::Update
46
46
  fb = Factbase::Looged.new(fb, @loog)
47
47
  options = Judges::Options.new(opts['option'])
48
48
  @loog.debug("The following options provided:\n\t#{options.to_s.gsub("\n", "\n\t")}")
49
- packs = Judges::Packs.new(dir, @loog)
49
+ packs = Judges::Packs.new(dir, opts['lib'], @loog)
50
50
  c = 0
51
51
  loop do
52
52
  c += 1
@@ -66,11 +66,13 @@ class Judges::Update
66
66
  def cycle(packs, fb, impex, options)
67
67
  errors = []
68
68
  diff = 0
69
+ global = {}
69
70
  done = packs.each_with_index do |p, i|
71
+ local = {}
70
72
  @loog.info("👉 Running #{p.name} (##{i}) at #{p.dir.to_rel}...")
71
73
  before = fb.size
72
74
  begin
73
- p.run(fb, options)
75
+ p.run(fb, global, local, options)
74
76
  rescue StandardError => e
75
77
  @loog.warn(Backtrace.new(e))
76
78
  errors << p.script
data/lib/judges/impex.rb CHANGED
@@ -39,7 +39,7 @@ class Judges::Impex
39
39
  fb = Factbase.new
40
40
  if File.exist?(@file)
41
41
  fb.import(File.binread(@file))
42
- @loog.info("The factbase imported from #{@file.to_rel} (#{File.size(@file)} bytes)")
42
+ @loog.info("The factbase imported from #{@file.to_rel} (#{File.size(@file)} bytes, #{fb.size} facts)")
43
43
  elsif strict
44
44
  raise "The factbase is absent at #{@file.to_rel}"
45
45
  end
@@ -49,12 +49,12 @@ class Judges::Impex
49
49
  def import_to(fb)
50
50
  raise "The factbase is absent at #{@file.to_rel}" unless File.exist?(@file)
51
51
  fb.import(File.binread(@file))
52
- @loog.info("The factbase loaded from #{@file.to_rel} (#{File.size(@file)} bytes)")
52
+ @loog.info("The factbase loaded from #{@file.to_rel} (#{File.size(@file)} bytes, #{fb.size} facts)")
53
53
  end
54
54
 
55
55
  def export(fb)
56
56
  FileUtils.mkdir_p(File.dirname(@file))
57
57
  File.binwrite(@file, fb.export)
58
- @loog.info("Factbase exported to #{@file.to_rel} (#{File.size(@file)} bytes)")
58
+ @loog.info("Factbase exported to #{@file.to_rel} (#{File.size(@file)} bytes, #{fb.size} facts)")
59
59
  end
60
60
  end
data/lib/judges/pack.rb CHANGED
@@ -20,9 +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 'yaml'
24
- require 'time'
25
23
  require_relative '../judges'
24
+ require_relative '../judges/to_rel'
26
25
  require_relative '../judges/fb/once'
27
26
  require_relative '../judges/fb/if_absent'
28
27
 
@@ -33,17 +32,27 @@ require_relative '../judges/fb/if_absent'
33
32
  class Judges::Pack
34
33
  attr_reader :dir
35
34
 
36
- def initialize(dir, loog)
35
+ def initialize(dir, lib, loog)
37
36
  @dir = dir
37
+ @lib = lib
38
38
  @loog = loog
39
39
  end
40
40
 
41
41
  # Run it with the given Factbase and environment variables.
42
- def run(fbase, options)
42
+ def run(fbase, global, local, options)
43
43
  $fb = fbase
44
44
  $judge = File.basename(@dir)
45
45
  $options = options
46
46
  $loog = @loog
47
+ $global = global
48
+ $local = local
49
+ unless @lib.nil?
50
+ raise "Lib dir #{@lib.to_rel} is absent" unless File.exist?(@lib)
51
+ raise "Lib #{@lib.to_rel} is not a directory" unless File.directory?(@lib)
52
+ Dir.glob(File.join(@lib, '*.rb')).each do |f|
53
+ require_relative(File.absolute_path(f))
54
+ end
55
+ end
47
56
  s = File.join(@dir, script)
48
57
  raise "Can't load '#{s}'" unless File.exist?(s)
49
58
  begin
@@ -60,7 +69,9 @@ class Judges::Pack
60
69
 
61
70
  # Get the name of the .rb script in the pack.
62
71
  def script
63
- File.basename(Dir.glob(File.join(@dir, '*.rb')).first)
72
+ s = Dir.glob(File.join(@dir, '*.rb')).first
73
+ raise "No *.rb scripts in #{@dir.to_rel}" if s.nil?
74
+ File.basename(s)
64
75
  end
65
76
 
66
77
  # Return all .yml tests files.
data/lib/judges/packs.rb CHANGED
@@ -28,8 +28,9 @@ require_relative 'pack'
28
28
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
29
29
  # License:: MIT
30
30
  class Judges::Packs
31
- def initialize(dir, loog)
31
+ def initialize(dir, lib, loog)
32
32
  @dir = dir
33
+ @lib = lib
33
34
  @loog = loog
34
35
  end
35
36
 
@@ -38,7 +39,7 @@ class Judges::Packs
38
39
  def each
39
40
  Dir.glob(File.join(@dir, '**/*.rb')).each do |f|
40
41
  d = File.dirname(File.absolute_path(f))
41
- yield Judges::Pack.new(d, @loog)
42
+ yield Judges::Pack.new(d, @lib, @loog)
42
43
  end
43
44
  end
44
45
 
@@ -39,7 +39,7 @@ class TestTrim < Minitest::Test
39
39
  before.insert.time = Time.now + 1
40
40
  before.insert.time = Time.now - (100 * 24 * 60 * 60)
41
41
  File.binwrite(file, before.export)
42
- Judges::Trim.new(Loog::VERBOSE).run({ 'days' => '10' }, [file])
42
+ Judges::Trim.new(Loog::VERBOSE).run({ 'days' => 10 }, [file])
43
43
  after = Factbase.new
44
44
  after.import(File.binread(file))
45
45
  assert_equal(1, after.size)
data/test/test_pack.rb CHANGED
@@ -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, Loog::VERBOSE)
38
+ pack = Judges::Pack.new(d, nil, Loog::VERBOSE)
39
39
  fb = Factbase.new
40
- pack.run(fb, {})
40
+ pack.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, Loog::VERBOSE)
48
+ pack = Judges::Pack.new(d, nil, Loog::VERBOSE)
49
49
  fb1 = Factbase.new
50
- pack.run(fb1, {})
50
+ pack.run(fb1, {}, {}, {})
51
51
  assert_equal(1, fb1.size)
52
52
  fb2 = Factbase.new
53
- pack.run(fb2, {})
53
+ pack.run(fb2, {}, {}, {})
54
54
  assert_equal(1, fb2.size)
55
55
  end
56
56
  end
@@ -58,8 +58,26 @@ 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'), 'once($fb).insert')
61
- pack = Judges::Pack.new(d, Loog::VERBOSE)
62
- pack.run(Factbase.new, {})
61
+ pack = Judges::Pack.new(d, nil, Loog::VERBOSE)
62
+ pack.run(Factbase.new, {}, {}, {})
63
+ end
64
+ end
65
+
66
+ def test_passes_local_vars_between_tests
67
+ Dir.mktmpdir do |d|
68
+ File.write(
69
+ File.join(d, 'x.rb'),
70
+ '
71
+ $local[:foo] = 42 if $local[:foo].nil?
72
+ $local[:foo] = $local[:foo] + 1
73
+ '
74
+ )
75
+ pack = Judges::Pack.new(d, nil, Loog::NULL)
76
+ local = {}
77
+ pack.run(Factbase.new, {}, local, {})
78
+ pack.run(Factbase.new, {}, local, {})
79
+ pack.run(Factbase.new, {}, local, {})
80
+ assert_equal(45, local[:foo])
63
81
  end
64
82
  end
65
83
 
@@ -70,8 +88,23 @@ class TestPack < Minitest::Test
70
88
  FileUtils.mkdir(dir)
71
89
  File.write(File.join(dir, 'foo.rb'), '$loog.info("judge=" + $judge)')
72
90
  log = Loog::Buffer.new
73
- Judges::Pack.new(dir, log).run(Factbase.new, {})
91
+ Judges::Pack.new(dir, nil, log).run(Factbase.new, {}, {}, {})
74
92
  assert(log.to_s.include?("judge=#{j}"))
75
93
  end
76
94
  end
95
+
96
+ def test_with_library
97
+ Dir.mktmpdir do |d|
98
+ dir = File.join(d, 'packs')
99
+ FileUtils.mkdir_p(dir)
100
+ File.write(File.join(dir, 'x.rb'), 'once($fb).insert.bar = $foo')
101
+ lib = File.join(d, 'lib')
102
+ FileUtils.mkdir_p(lib)
103
+ File.write(File.join(lib, 'y.rb'), '$foo = 42')
104
+ pack = Judges::Pack.new(dir, lib, Loog::VERBOSE)
105
+ fb = Factbase.new
106
+ pack.run(fb, {}, {}, {})
107
+ assert_equal(42, fb.query('()').each.to_a.first.bar)
108
+ end
109
+ end
77
110
  end
data/test/test_packs.rb CHANGED
@@ -36,7 +36,7 @@ class TestPacks < Minitest::Test
36
36
  File.write(File.join(d, 'foo.rb'), 'hey')
37
37
  File.write(File.join(d, 'something.yml'), "---\nfoo: 42")
38
38
  found = 0
39
- Judges::Packs.new(d, Loog::VERBOSE).each do |p|
39
+ Judges::Packs.new(d, nil, Loog::VERBOSE).each do |p|
40
40
  assert_equal('foo.rb', p.script)
41
41
  found += 1
42
42
  assert_equal('something.yml', File.basename(p.tests.first))
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.23
4
+ version: 0.0.25
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-15 00:00:00.000000000 Z
11
+ date: 2024-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.0.21
33
+ version: 0.0.22
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.0.21
40
+ version: 0.0.22
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: gli
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -107,14 +107,20 @@ files:
107
107
  - ".rultor.yml"
108
108
  - ".simplecov"
109
109
  - Gemfile
110
+ - Gemfile.lock
110
111
  - LICENSE.txt
111
112
  - README.md
112
113
  - Rakefile
113
114
  - bin/judges
114
- - features/cli.feature
115
115
  - features/gem_package.feature
116
+ - features/inspect.feature
117
+ - features/misc.feature
118
+ - features/print.feature
116
119
  - features/step_definitions/steps.rb
117
120
  - features/support/env.rb
121
+ - features/test.feature
122
+ - features/trim.feature
123
+ - features/update.feature
118
124
  - fixtures/reward_for_good_bug/README.md
119
125
  - fixtures/reward_for_good_bug/no-reward.yml
120
126
  - fixtures/reward_for_good_bug/reward_it.rb
data/features/cli.feature DELETED
@@ -1,79 +0,0 @@
1
- Feature: Simple Run
2
- I want to run a few judges over a factbase
3
-
4
- Scenario: Help can be printed
5
- When I run bin/judges with "-h"
6
- Then Exit code is zero
7
- And Stdout contains "--help"
8
-
9
- Scenario: Version can be printed
10
- When I run bin/judges with "--version"
11
- Then Exit code is zero
12
-
13
- Scenario: Simple run of a few judges
14
- Given I make a temp directory
15
- Then I have a "simple/simple_judge.rb" file with content:
16
- """
17
- n = $fb.insert
18
- n.kind = 'yes!'
19
- """
20
- Then I run bin/judges with "--verbose update --quiet -o foo=1 -o bar=2 --max-cycles 3 . simple.fb"
21
- Then Stdout contains "foo → "
22
- Then Stdout contains "bar → "
23
- Then Stdout contains "1 judge(s) processed"
24
- Then Stdout contains "Update finished in 3 cycles"
25
- And Exit code is zero
26
-
27
- Scenario: Simple test of a few judges
28
- Given I run bin/judges with "test ./fixtures"
29
- Then Stdout contains "👉 Testing"
30
- Then Stdout contains "judge(s) tested successfully"
31
- And Exit code is zero
32
-
33
- Scenario: Simple test of just one pack
34
- Given I run bin/judges with "test --pack reward_for_good_bug ./fixtures"
35
- Then Stdout contains "judge(s) tested successfully"
36
- And Exit code is zero
37
-
38
- Scenario: Simple test of no packs
39
- Given I run bin/judges with "test --pack absent_for_sure ./fixtures"
40
- Then Exit code is not zero
41
-
42
- Scenario: Simple trimming of a factbase
43
- Given I make a temp directory
44
- Then I have a "simple/simple_judge.rb" file with content:
45
- """
46
- return if $fb.size > 2
47
- $fb.insert.time = Time.now - 100 * 60 * 60 * 24
48
- """
49
- Then I run bin/judges with "--verbose update . simple.fb"
50
- Given I run bin/judges with "trim --days 5 simple.fb"
51
- Then Stdout contains "3 facts deleted"
52
- And Exit code is zero
53
-
54
- Scenario: Simple print of a small factbase
55
- Given I make a temp directory
56
- Then I have a "simple/simple_judge.rb" file with content:
57
- """
58
- return if $fb.size > 2
59
- n = $fb.insert
60
- n.kind = 'yes!'
61
- """
62
- Then I run bin/judges with "update . simple.fb"
63
- Then I run bin/judges with "print --format=yaml simple.fb simple.yml"
64
- Then Stdout contains "printed"
65
- And Exit code is zero
66
-
67
- Scenario: Simple inspect of a small factbase
68
- Given I make a temp directory
69
- Then I have a "simple/simple_judge.rb" file with content:
70
- """
71
- return if $fb.size > 2
72
- n = $fb.insert
73
- n.kind = 'yes!'
74
- """
75
- Then I run bin/judges with "update . simple.fb"
76
- Then I run bin/judges with "inspect simple.fb"
77
- Then Stdout contains "Facts: 3"
78
- And Exit code is zero
79
-