judges 0.0.22 → 0.0.24

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: c7b4a80762cb37240925afe0778c87a829f891a4e5a3a3fb7f22ccc3802c1a3a
4
- data.tar.gz: 914e85bda9dea1030a06fde8a635d1452ae73c0d3e736e8ef04164cd692df378
3
+ metadata.gz: ed5fca9c346d6f092bde73a242e8b347f2abba9f7330767db25edca3d1df1dd3
4
+ data.tar.gz: cbb70db60a4dc7c953cfa6feea4d5955a27f76cf34b3c5403423e8e3b804db84
5
5
  SHA512:
6
- metadata.gz: 2fb32730607a2b122391447f7bd371f9b1d318d4c6be50ae1bf2d3bcd46c80561ac1ebe792824909cfa8f7fbd4edda17404e41b2510b9ab25c750fcb34f836ef
7
- data.tar.gz: 6f6fa5d67867c3f0abb8b54e65d59aedbfa607abde5ca1336505001d35c916c8a928a4228393c2d5d22e2a341ed09afb2c199057389a966ce1f07326b7444e13
6
+ metadata.gz: c6d4dffa49971e1dc77788263b005d843223bf96faba1cb67333b773f411fdd9b6920577f1edaab9ae9e6fcb7191c37febc2b1ae0ee55d6fa272f45f36242aa2
7
+ data.tar.gz: a0cde0d189d3ae6bf15da5252fb03dc530103de68adeb2379dc048a2354987bb5371863352640a64cc04663db5b4c099ff7ae474f793ce4ff7f6589f5f0b4da5
data/Gemfile CHANGED
@@ -24,7 +24,7 @@ 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
data/bin/judges CHANGED
@@ -29,93 +29,99 @@ require 'factbase'
29
29
  Encoding.default_external = Encoding::UTF_8
30
30
  Encoding.default_internal = Encoding::UTF_8
31
31
 
32
- ver = '0.0.22'
32
+ class App
33
+ extend GLI::App
33
34
 
34
- include GLI::App
35
+ ver = '0.0.24'
35
36
 
36
- loog = Loog::REGULAR
37
+ loog = Loog::REGULAR
37
38
 
38
- program_desc('Automated executor of judges for a factbase')
39
+ program_desc('Automated executor of judges for a factbase')
39
40
 
40
- version(ver)
41
+ version(ver)
41
42
 
42
- synopsis_format(:full)
43
+ synopsis_format(:full)
43
44
 
44
- subcommand_option_handling(:normal)
45
+ subcommand_option_handling(:normal)
45
46
 
46
- desc 'Make it more verbose, logging as much as possible'
47
- switch([:v, :verbose])
47
+ desc 'Make it more verbose, logging as much as possible'
48
+ switch([:v, :verbose])
48
49
 
49
- pre do |global, command, options, args|
50
- if global[:verbose]
51
- loog = Loog::VERBOSE
50
+ pre do |global, command, options, args|
51
+ if global[:verbose]
52
+ loog = Loog::VERBOSE
53
+ end
54
+ loog.debug("judges #{ver}")
55
+ true
52
56
  end
53
- loog.debug("judges #{ver}")
54
- true
55
- end
56
57
 
57
- desc 'Update the factbase by passing all judges one by one'
58
- command :update do |c|
59
- c.desc 'Options to pass to every judge'
60
- c.flag([:o, :option], multiple: true, arg_name: '<key=value>')
61
- c.desc 'Maximum number of update cycles to run'
62
- c.flag([:'max-cycles'], default_value: 8, type: Integer)
63
- c.desc 'Stay quiet even if some judges fail'
64
- c.switch([:q, :quiet], default_value: false)
65
- c.action do |global, options, args|
66
- require_relative '../lib/judges/commands/update'
67
- Judges::Update.new(loog).run(options, args)
58
+ desc 'Update the factbase by passing all judges one by one'
59
+ command :update do |c|
60
+ c.desc 'Options to pass to every judge'
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])
64
+ c.desc 'Maximum number of update cycles to run'
65
+ c.flag([:'max-cycles'], default_value: 8, type: Integer)
66
+ c.desc 'Stay quiet even if some judges fail'
67
+ c.switch([:q, :quiet], default_value: false)
68
+ c.action do |global, options, args|
69
+ require_relative '../lib/judges/commands/update'
70
+ Judges::Update.new(loog).run(options, args)
71
+ end
68
72
  end
69
- end
70
73
 
71
- desc 'Join two factbases'
72
- command :print do |c|
73
- c.action do |global, options, args|
74
- require_relative '../lib/judges/commands/join'
75
- Judges::Join.new(loog).run(options, args)
74
+ desc 'Join two factbases'
75
+ command :print do |c|
76
+ c.action do |global, options, args|
77
+ require_relative '../lib/judges/commands/join'
78
+ Judges::Join.new(loog).run(options, args)
79
+ end
76
80
  end
77
- end
78
81
 
79
- desc 'Remove the facts that are too old'
80
- command :trim do |c|
81
- c.desc 'Remove facts that are older than X days'
82
- c.flag([:days], type: Integer, default_value: 90)
83
- c.action do |global, options, args|
84
- require_relative '../lib/judges/commands/trim'
85
- Judges::Trim.new(loog).run(options, args)
82
+ desc 'Remove the facts that are too old'
83
+ command :trim do |c|
84
+ c.desc 'Remove facts that are older than X days'
85
+ c.flag([:days], type: Integer, default_value: 90)
86
+ c.action do |global, options, args|
87
+ require_relative '../lib/judges/commands/trim'
88
+ Judges::Trim.new(loog).run(options, args)
89
+ end
86
90
  end
87
- end
88
91
 
89
- desc 'Print the factbase into a human-readable format (YAML, JSON, etc.)'
90
- command :print do |c|
91
- c.desc 'Output format (xml, json, or yaml)'
92
- c.flag([:format], default_value: 'yaml')
93
- c.desc 'Generate output name of the file automatically'
94
- c.switch([:auto], default_value: false)
95
- c.action do |global, options, args|
96
- require_relative '../lib/judges/commands/print'
97
- Judges::Print.new(loog).run(options, args)
92
+ desc 'Print the factbase into a human-readable format (YAML, JSON, etc.)'
93
+ command :print do |c|
94
+ c.desc 'Output format (xml, json, or yaml)'
95
+ c.flag([:format], default_value: 'yaml')
96
+ c.desc 'Generate output name of the file automatically'
97
+ c.switch([:auto], default_value: false)
98
+ c.action do |global, options, args|
99
+ require_relative '../lib/judges/commands/print'
100
+ Judges::Print.new(loog).run(options, args)
101
+ end
98
102
  end
99
- end
100
103
 
101
- desc 'Inspect the factbase and print all its possible meta-data'
102
- command :inspect do |c|
103
- c.action do |global, options, args|
104
- require_relative '../lib/judges/commands/inspect'
105
- Judges::Inspect.new(loog).run(options, args)
104
+ desc 'Inspect the factbase and print all its possible meta-data'
105
+ command :inspect do |c|
106
+ c.action do |global, options, args|
107
+ require_relative '../lib/judges/commands/inspect'
108
+ Judges::Inspect.new(loog).run(options, args)
109
+ end
106
110
  end
107
- end
108
111
 
109
- desc 'Run automated tests for all judges'
110
- command :test do |c|
111
- c.desc 'Name of the test pack to run'
112
- c.flag([:pack], multiple: true)
113
- c.desc 'Stay quiet even if some tests fail or simply no tests executed?'
114
- c.switch([:quiet], default_value: false)
115
- c.action do |global, options, args|
116
- require_relative '../lib/judges/commands/test'
117
- Judges::Test.new(loog).run(options, args)
112
+ desc 'Run automated tests for all judges'
113
+ command :test do |c|
114
+ c.desc 'Name of the test pack to run'
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])
118
+ c.desc 'Stay quiet even if some tests fail or simply no tests executed?'
119
+ c.switch([:quiet], default_value: false)
120
+ c.action do |global, options, args|
121
+ require_relative '../lib/judges/commands/test'
122
+ Judges::Test.new(loog).run(options, args)
123
+ end
118
124
  end
119
125
  end
120
126
 
121
- exit run(ARGV)
127
+ exit App.run(ARGV)
@@ -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
@@ -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.22'
29
+ s.version = '0.0.24'
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,7 +44,7 @@ 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
+ Judges::Packs.new(dir, opts['lib'], @loog).each_with_index do |p, i|
48
48
  next unless include?(opts, p.name)
49
49
  @loog.info("\n👉 Testing #{p.script} (##{i}) in #{p.dir.to_rel}...")
50
50
  p.tests.each do |f|
@@ -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
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,8 +32,9 @@ 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
 
@@ -44,6 +44,13 @@ class Judges::Pack
44
44
  $judge = File.basename(@dir)
45
45
  $options = options
46
46
  $loog = @loog
47
+ unless @lib.nil?
48
+ raise "Lib dir #{@lib.to_rel} is absent" unless File.exist?(@lib)
49
+ raise "Lib #{@lib.to_rel} is not a directory" unless File.directory?(@lib)
50
+ Dir.glob(File.join(@lib, '*.rb')).each do |f|
51
+ require_relative(File.absolute_path(f))
52
+ end
53
+ end
47
54
  s = File.join(@dir, script)
48
55
  raise "Can't load '#{s}'" unless File.exist?(s)
49
56
  begin
@@ -60,7 +67,9 @@ class Judges::Pack
60
67
 
61
68
  # Get the name of the .rb script in the pack.
62
69
  def script
63
- File.basename(Dir.glob(File.join(@dir, '*.rb')).first)
70
+ s = Dir.glob(File.join(@dir, '*.rb')).first
71
+ raise "No *.rb scripts in #{@dir.to_rel}" if s.nil?
72
+ File.basename(s)
64
73
  end
65
74
 
66
75
  # 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,7 +35,7 @@ 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
40
  pack.run(fb, {})
41
41
  assert_equal(1, fb.size)
@@ -45,7 +45,7 @@ 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
50
  pack.run(fb1, {})
51
51
  assert_equal(1, fb1.size)
@@ -58,7 +58,7 @@ 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)
61
+ pack = Judges::Pack.new(d, nil, Loog::VERBOSE)
62
62
  pack.run(Factbase.new, {})
63
63
  end
64
64
  end
@@ -70,8 +70,23 @@ class TestPack < Minitest::Test
70
70
  FileUtils.mkdir(dir)
71
71
  File.write(File.join(dir, 'foo.rb'), '$loog.info("judge=" + $judge)')
72
72
  log = Loog::Buffer.new
73
- Judges::Pack.new(dir, log).run(Factbase.new, {})
73
+ Judges::Pack.new(dir, nil, log).run(Factbase.new, {})
74
74
  assert(log.to_s.include?("judge=#{j}"))
75
75
  end
76
76
  end
77
+
78
+ def test_with_library
79
+ Dir.mktmpdir do |d|
80
+ dir = File.join(d, 'packs')
81
+ FileUtils.mkdir_p(dir)
82
+ File.write(File.join(dir, 'x.rb'), 'once($fb).insert.bar = $foo')
83
+ lib = File.join(d, 'lib')
84
+ FileUtils.mkdir_p(lib)
85
+ File.write(File.join(lib, 'y.rb'), '$foo = 42')
86
+ pack = Judges::Pack.new(dir, lib, Loog::VERBOSE)
87
+ fb = Factbase.new
88
+ pack.run(fb, {})
89
+ assert_equal(42, fb.query('()').each.to_a.first.bar)
90
+ end
91
+ end
77
92
  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.22
4
+ version: 0.0.24
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
@@ -111,10 +111,15 @@ files:
111
111
  - README.md
112
112
  - Rakefile
113
113
  - bin/judges
114
- - features/cli.feature
115
114
  - features/gem_package.feature
115
+ - features/inspect.feature
116
+ - features/misc.feature
117
+ - features/print.feature
116
118
  - features/step_definitions/steps.rb
117
119
  - features/support/env.rb
120
+ - features/test.feature
121
+ - features/trim.feature
122
+ - features/update.feature
118
123
  - fixtures/reward_for_good_bug/README.md
119
124
  - fixtures/reward_for_good_bug/no-reward.yml
120
125
  - 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
-