judges 0.0.10 → 0.0.11

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: 550115852b44ae26b7af9cb776bcbf9e5b7e043579ab8eec3930854f573a6768
4
- data.tar.gz: 7efe473542ffd401220d8e5b65d853ba144ad8ceab0273f9531e3d462e072afc
3
+ metadata.gz: a3b228cb0e22d71082da253b074c34367a2bd25f2b8eaa94f18941f976161b30
4
+ data.tar.gz: 4f5296d0a6827f40e4b72e8dbf4485c7c945fcb6bff57a413b303924580019b1
5
5
  SHA512:
6
- metadata.gz: '096f25e43ee418b94ae0a2f4b3d678c170170dfda2228191a269931bcfa1150e4f50151830e1132b3282ccaa768b2129deb8f29e55faebefd0bc7c2bd5ce2700'
7
- data.tar.gz: d3f8922eeee30008f3883a7592667ce084a1d96785c4b04c51478c028ba99aa28eaddd151ac13a1bb7a101de8cc0f05434d22edcf6bbb1691b4bb76a4bd89067
6
+ metadata.gz: 7efa088162e4d2b94a4776886a17fc2d9ad144aa9cb470c3ca0b58cb5ba22fe01b6d18d5dd38bbb0a914376fe0e908fa2105dad94a58bb48b3235fb503162816
7
+ data.tar.gz: ddfa2405cdb2c3deb91365fc4f04b44add319615b71081476655d4539c3838eb65ec9d9b842250f737ea8f3376df8bc87c87553f973bedab489e6ee3a5721ec9
@@ -30,7 +30,7 @@ jobs:
30
30
  - uses: actions/checkout@v4
31
31
  - uses: ruby/setup-ruby@v1
32
32
  with:
33
- ruby-version: 2.7
33
+ ruby-version: 3.2
34
34
  - run: bundle update
35
35
  - run: bundle exec rake
36
36
  - uses: codecov/codecov-action@v4.0.0-beta.3
@@ -32,7 +32,7 @@ jobs:
32
32
  strategy:
33
33
  matrix:
34
34
  os: [ubuntu-20.04, macos-12]
35
- ruby: [2.7, 3.2]
35
+ ruby: [3.2]
36
36
  runs-on: ${{ matrix.os }}
37
37
  steps:
38
38
  - uses: actions/checkout@v4
@@ -20,23 +20,28 @@
20
20
  ---
21
21
  name: zerocracy
22
22
  on:
23
- schedule:
24
- - cron: '0,10,20,30,50,50 * * * *'
23
+ push:
24
+ # schedule:
25
+ # - cron: '0,10,20,30,50,50 * * * *'
25
26
  concurrency:
26
27
  group: zerocracy
27
28
  cancel-in-progress: true
28
29
  jobs:
29
- yamllint:
30
+ zerocracy:
30
31
  runs-on: ubuntu-22.04
31
32
  steps:
32
33
  - uses: actions/checkout@v4
34
+ - uses: actions/cache@v4
35
+ with:
36
+ path: recent.fb
37
+ key: judges
38
+ restore-keys: judges
33
39
  - uses: zerocracy/judges-action@master
34
40
  with:
35
41
  factbase: recent.fb
36
- - run: mkdir gh-pages && cp recent.yml gh-pages
42
+ - run: mkdir gh-pages && cp recent.yaml gh-pages
37
43
  - uses: JamesIves/github-pages-deploy-action@v4.6.0
38
44
  with:
39
45
  branch: gh-pages
40
- folder: gh-pages/recent.yml
41
- factbase: recent.fb
42
- clean: true
46
+ folder: gh-pages
47
+ clean: false
data/.rubocop.yml CHANGED
@@ -49,3 +49,5 @@ Layout/EmptyLineAfterGuardClause:
49
49
  Enabled: false
50
50
  Layout/CaseIndentation:
51
51
  Enabled: false
52
+ Naming/MethodParameterName:
53
+ MinNameLength: 2
data/bin/judges CHANGED
@@ -29,53 +29,55 @@ require 'factbase'
29
29
  Encoding.default_external = Encoding::UTF_8
30
30
  Encoding.default_internal = Encoding::UTF_8
31
31
 
32
- class App
33
- extend GLI::App
32
+ include GLI::App
34
33
 
35
- loog = Loog::REGULAR
34
+ loog = Loog::REGULAR
36
35
 
37
- program_desc 'Automated executor of judges for a factbase'
36
+ program_desc('Automated executor of judges for a factbase')
38
37
 
39
- version '0.0.10'
38
+ version('0.0.11')
40
39
 
41
- desc 'Make it more verbose, logging as much as possible'
42
- switch([:v, :verbose])
40
+ synopsis_format(:full)
43
41
 
44
- pre do |global, command, options, args|
45
- if global[:verbose]
46
- loog = Loog::VERBOSE
47
- end
48
- true
42
+ subcommand_option_handling(:normal)
43
+
44
+ desc 'Make it more verbose, logging as much as possible'
45
+ switch([:v, :verbose])
46
+
47
+ pre do |global, command, options, args|
48
+ if global[:verbose]
49
+ loog = Loog::VERBOSE
49
50
  end
51
+ true
52
+ end
50
53
 
51
- desc 'Update the factbase by passing all judges one by one'
52
- command :update do |c|
53
- c.desc 'Environment variable to pass to every judge'
54
- c.flag([:e, :environment], default_value: 'yes')
55
- c.action do |global, options, args|
56
- require_relative '../lib/judges/commands/update'
57
- Judges::Update.new(loog).run(options, args)
58
- end
54
+ desc 'Update the factbase by passing all judges one by one'
55
+ command :update do |c|
56
+ c.desc 'Options to pass to every judge'
57
+ c.flag([:o, :option], default_value: 'yes', type: Array, arg_name: '<key=value>')
58
+ c.action do |global, options, args|
59
+ require_relative '../lib/judges/commands/update'
60
+ Judges::Update.new(loog).run(options, args)
59
61
  end
62
+ end
60
63
 
61
- desc 'Print the factbase into a human-readable format (YAML, JSON, etc.)'
62
- command :print do |c|
63
- c.desc 'Output format (xml, json, or yaml)'
64
- c.flag([:format], default_value: 'yaml')
65
- c.switch([:auto])
66
- c.action do |global, options, args|
67
- require_relative '../lib/judges/commands/print'
68
- Judges::Print.new(loog).run(options, args)
69
- end
64
+ desc 'Print the factbase into a human-readable format (YAML, JSON, etc.)'
65
+ command :print do |c|
66
+ c.desc 'Output format (xml, json, or yaml)'
67
+ c.flag([:format], default_value: 'yaml')
68
+ c.switch([:auto])
69
+ c.action do |global, options, args|
70
+ require_relative '../lib/judges/commands/print'
71
+ Judges::Print.new(loog).run(options, args)
70
72
  end
73
+ end
71
74
 
72
- desc 'Run automated tests for all judges'
73
- command :test do |c|
74
- c.action do |global, options, args|
75
- require_relative '../lib/judges/commands/test'
76
- Judges::Test.new(loog).run(options, args)
77
- end
75
+ desc 'Run automated tests for all judges'
76
+ command :test do |c|
77
+ c.action do |global, options, args|
78
+ require_relative '../lib/judges/commands/test'
79
+ Judges::Test.new(loog).run(options, args)
78
80
  end
79
81
  end
80
82
 
81
- exit App.run(ARGV)
83
+ exit run(ARGV)
data/features/cli.feature CHANGED
@@ -24,8 +24,8 @@ Feature: Simple Run
24
24
  And Exit code is zero
25
25
 
26
26
  Scenario: Simple test of a few judges
27
- Given I run bin/judges with "update ./fixtures temp/simple.fb"
28
- Then Stdout contains "judges processed"
27
+ Given I run bin/judges with "test ./fixtures"
28
+ Then Stdout contains "judges tested"
29
29
  And Exit code is zero
30
30
 
31
31
  Scenario: Simple print of a small factbase
@@ -47,7 +47,7 @@ end
47
47
 
48
48
  When(%r{^I run bin/judges with "([^"]*)"$}) do |arg|
49
49
  home = File.join(File.dirname(__FILE__), '../..')
50
- @stdout = `ruby -I#{home}/lib #{home}/bin/judges #{arg}`
50
+ @stdout = `GLI_DEBUG=true ruby -I#{home}/lib #{home}/bin/judges #{arg}`
51
51
  @exitstatus = $CHILD_STATUS.exitstatus
52
52
  end
53
53
 
@@ -25,7 +25,7 @@ input:
25
25
  time: 2024-01-01T03:15:45
26
26
  seen:
27
27
  - one
28
- - this judge
28
+ - reward_for_good_bug
29
29
  - two
30
30
  expected:
31
31
  - /fb[count(f)=1]
@@ -20,7 +20,10 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  # SOFTWARE.
22
22
 
23
- $fb.query("(and (eq kind 'bug was accepted') (not (eq seen 'this judge')))").each do |f|
23
+ $loog.info("Trying to reward a good reported bug (judge=#{$judge})...")
24
+
25
+ once($fb).query("(eq kind 'bug was accepted')").each do |f|
26
+ $loog.info('Good candidate found!')
24
27
  n = $fb.insert
25
28
  n.kind = 'nominate for good bug'
26
29
  n.payee = f.reporter
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.10'
29
+ s.version = '0.0.11'
30
30
  s.license = 'MIT'
31
31
  s.summary = 'Command-Line Tool for a Factbase'
32
32
  s.description = '
@@ -41,8 +41,7 @@ Gem::Specification.new do |s|
41
41
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
42
42
  s.rdoc_options = ['--charset=UTF-8']
43
43
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
44
- s.add_runtime_dependency 'backtrace', '~>0.3'
45
- s.add_runtime_dependency 'factbase', '~>0.0'
44
+ s.add_runtime_dependency 'factbase', '~>0.0.11'
46
45
  s.add_runtime_dependency 'gli', '~>2.21'
47
46
  s.add_runtime_dependency 'loog', '~>0.2'
48
47
  s.add_runtime_dependency 'nokogiri', '~> 1.10'
@@ -20,10 +20,11 @@
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 'factbase'
24
23
  require 'nokogiri'
24
+ require 'factbase'
25
25
  require_relative '../../judges'
26
26
  require_relative '../../judges/packs'
27
+ require_relative '../../judges/options'
27
28
 
28
29
  # Test.
29
30
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -37,7 +38,9 @@ class Judges::Test
37
38
  def run(_opts, args)
38
39
  raise 'Exactly one argument required' unless args.size == 1
39
40
  dir = args[0]
40
- done = Judges::Packs.new(dir).each_with_index do |p, i|
41
+ @loog.info("Testing judges in #{dir}...")
42
+ done = Judges::Packs.new(dir, @loog).each_with_index do |p, i|
43
+ @loog.info("Testing #{p.script} in #{p.dir}...")
41
44
  p.tests.each do |t|
42
45
  test_one(p, t)
43
46
  end
@@ -55,17 +58,17 @@ class Judges::Test
55
58
  i.each do |k, vv|
56
59
  if vv.is_a?(Array)
57
60
  vv.each do |v|
58
- send(f, "#{k}=", v)
61
+ f.send("#{k}=", v)
59
62
  end
60
63
  else
61
- f.send('foo=', 42)
64
+ f.send("#{k}=", vv)
62
65
  end
63
66
  end
64
67
  end
65
- pack.run(fb, {})
68
+ pack.run(fb, Judges::Options.new(yaml['options']))
66
69
  xml = Nokogiri::XML.parse(fb.to_xml)
67
70
  yaml['expected'].each do |xp|
68
- raise "#{pack.script} with '#{xp}' doesn't match:\n#{xml}" if xml.xpath(xp).empty?
71
+ raise "#{pack.script} doesn't match '#{xp}':\n#{xml}" if xml.xpath(xp).empty?
69
72
  end
70
73
  end
71
74
  end
@@ -24,6 +24,7 @@ require 'factbase'
24
24
  require 'fileutils'
25
25
  require_relative '../../judges'
26
26
  require_relative '../../judges/packs'
27
+ require_relative '../../judges/options'
27
28
 
28
29
  # Update.
29
30
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -34,7 +35,7 @@ class Judges::Update
34
35
  @loog = loog
35
36
  end
36
37
 
37
- def run(_opts, args)
38
+ def run(opts, args)
38
39
  raise 'Exactly two arguments required' unless args.size == 2
39
40
  dir = args[0]
40
41
  raise "The directory is absent: #{dir}" unless File.exist?(dir)
@@ -46,9 +47,9 @@ class Judges::Update
46
47
  else
47
48
  @loog.info("There is no Factbase to import from #{file}")
48
49
  end
49
- done = Judges::Packs.new(dir).each_with_index do |p, i|
50
+ done = Judges::Packs.new(dir, @loog).each_with_index do |p, i|
50
51
  @loog.info("Pack ##{i} found in #{p.dir}")
51
- p.run(fb, {})
52
+ p.run(fb, Judges::Options.new(opts['options']))
52
53
  end
53
54
  @loog.info("#{done} judges processed")
54
55
  FileUtils.mkdir_p(File.dirname(file))
@@ -0,0 +1,61 @@
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
+ # Returns a decorated global factbase, which only touches facts once
24
+ def once(fb, judge: $judge)
25
+ Factbase::Once.new(fb, judge)
26
+ end
27
+
28
+ # Runs only once.
29
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
30
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
31
+ # License:: MIT
32
+ class Factbase::Once
33
+ def initialize(fb, func)
34
+ @fb = fb
35
+ @func = func
36
+ end
37
+
38
+ def query(expr)
39
+ expr = "(and #{expr} (not (eq seen '#{@func}')))"
40
+ After.new(@fb.query(expr), @func)
41
+ end
42
+
43
+ def insert
44
+ @fb.insert
45
+ end
46
+
47
+ # What happens after a fact is processed.
48
+ class After
49
+ def initialize(query, func)
50
+ @query = query
51
+ @func = func
52
+ end
53
+
54
+ def each
55
+ @query.each do |f|
56
+ yield f
57
+ f.seen = @func
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,59 @@
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
+ # Options for ruby scripts.
26
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
27
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
28
+ # License:: MIT
29
+ class Judges::Options
30
+ # Ctor.
31
+ # @param [Array<String>] List of pairs, like ["token=af73cd3", "max_speed=1"]
32
+ def initialize(pairs)
33
+ @pairs = pairs
34
+ end
35
+
36
+ # Get option by name.
37
+ def method_missing(*args)
38
+ @hash ||= (if @pairs.nil?
39
+ []
40
+ else
41
+ (@pairs.is_a?(Hash) ? @pairs.map { |k, v| "#{k}=#{v}" } : @pairs)
42
+ end).to_h do |pair|
43
+ p = pair.split('=', 2)
44
+ [p[0].to_sym, p[1].match?(/^[0-9]+$/) ? p[1].to_i : p[1]]
45
+ end
46
+ k = args[0].downcase
47
+ @hash[k]
48
+ end
49
+
50
+ # rubocop:disable Style/OptionalBooleanParameter
51
+ def respond_to?(_method, _include_private = false)
52
+ # rubocop:enable Style/OptionalBooleanParameter
53
+ true
54
+ end
55
+
56
+ def respond_to_missing?(_method, _include_private = false)
57
+ true
58
+ end
59
+ end
data/lib/judges/pack.rb CHANGED
@@ -21,7 +21,9 @@
21
21
  # SOFTWARE.
22
22
 
23
23
  require 'yaml'
24
+ require 'time'
24
25
  require_relative '../judges'
26
+ require_relative '../judges/fb/once'
25
27
 
26
28
  # A single pack.
27
29
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -30,21 +32,24 @@ require_relative '../judges'
30
32
  class Judges::Pack
31
33
  attr_reader :dir
32
34
 
33
- def initialize(dir)
35
+ def initialize(dir, loog)
34
36
  @dir = dir
37
+ @loog = loog
35
38
  end
36
39
 
37
40
  # Run it with the given Factbase and environment variables.
38
- def run(fbase, env)
41
+ def run(fbase, options)
39
42
  $fb = fbase
40
- env.each do |k, v|
41
- # rubocop:disable Security/Eval
42
- eval("$#{k} = '#{v}'", binding, __FILE__, __LINE__) # $foo = 42
43
- # rubocop:enable Security/Eval
44
- end
43
+ $judge = File.basename(@dir)
44
+ $options = options
45
+ $loog = @loog
45
46
  s = File.join(@dir, script)
46
47
  raise "Can't load '#{s}'" unless File.exist?(s)
47
- load s
48
+ begin
49
+ load s
50
+ ensure
51
+ $fb = $judge = $options = $loog = nil
52
+ end
48
53
  end
49
54
 
50
55
  # Get the name of the .rb script in the pack.
@@ -55,7 +60,7 @@ class Judges::Pack
55
60
  # Iterate over .yml tests.
56
61
  def tests
57
62
  Dir.glob(File.join(@dir, '*.yml')).map do |f|
58
- YAML.load_file(f)
63
+ YAML.load_file(f, permitted_classes: [Time])
59
64
  end
60
65
  end
61
66
  end
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)
31
+ def initialize(dir, loog)
32
32
  @dir = dir
33
+ @loog = loog
33
34
  end
34
35
 
35
36
  # Iterate over them all.
@@ -37,7 +38,7 @@ class Judges::Packs
37
38
  def each
38
39
  Dir.glob(File.join(@dir, '**/*.rb')).each do |f|
39
40
  d = File.dirname(File.absolute_path(f))
40
- yield Judges::Pack.new(d)
41
+ yield Judges::Pack.new(d, @loog)
41
42
  end
42
43
  end
43
44
 
@@ -69,4 +69,22 @@ class TestTest < Minitest::Test
69
69
  end
70
70
  end
71
71
  end
72
+
73
+ def test_with_options
74
+ Dir.mktmpdir do |d|
75
+ File.write(File.join(d, 'foo.rb'), '$fb.insert.foo = $options.bar')
76
+ File.write(
77
+ File.join(d, 'something.yml'),
78
+ <<-YAML
79
+ input: []
80
+ options:
81
+ bar: 42
82
+ expected:
83
+ - /fb[count(f)=1]
84
+ - /fb/f[foo='42']
85
+ YAML
86
+ )
87
+ Judges::Test.new(Loog::VERBOSE).run(nil, [d])
88
+ end
89
+ end
72
90
  end
@@ -22,6 +22,7 @@
22
22
 
23
23
  require 'minitest/autorun'
24
24
  require 'loog'
25
+ require 'nokogiri'
25
26
  require_relative '../../lib/judges'
26
27
  require_relative '../../lib/judges/commands/update'
27
28
 
@@ -32,10 +33,13 @@ require_relative '../../lib/judges/commands/update'
32
33
  class TestUpdate < Minitest::Test
33
34
  def test_simple_update
34
35
  Dir.mktmpdir do |d|
35
- File.write(File.join(d, 'foo.rb'), '$fb.query("(eq foo 42)").each { |f| f.bar = 4 }')
36
- fb = File.join(d, 'base.fb')
37
- Judges::Update.new(Loog::VERBOSE).run(nil, [d, fb])
38
- assert(File.exist?(fb))
36
+ File.write(File.join(d, 'foo.rb'), '$fb.insert.zzz = $options.bar + 1')
37
+ file = File.join(d, 'base.fb')
38
+ Judges::Update.new(Loog::VERBOSE).run({ 'options' => ['bar=42'] }, [d, file])
39
+ fb = Factbase.new
40
+ fb.import(File.read(file))
41
+ xml = Nokogiri::XML.parse(fb.to_xml)
42
+ assert(!xml.xpath('/fb/f[zzz="43"]').empty?)
39
43
  end
40
44
  end
41
45
  end
@@ -0,0 +1,40 @@
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 'tmpdir'
25
+ require 'factbase'
26
+ require_relative '../../lib/judges'
27
+ require_relative '../../lib/judges/fb/once'
28
+
29
+ # Test.
30
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
31
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
32
+ # License:: MIT
33
+ class TestOnce < Minitest::Test
34
+ def test_touch_once
35
+ fb = once(Factbase.new, judge: 'something')
36
+ fb.insert
37
+ fb.query('()').each { |f| f.foo = 42 }
38
+ assert(fb.query('()').extend(Enumerable).to_a.empty?)
39
+ end
40
+ end
@@ -0,0 +1,47 @@
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/options'
26
+
27
+ # Test.
28
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
29
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
30
+ # License:: MIT
31
+ class TestOptions < Minitest::Test
32
+ def test_basic
33
+ opts = Judges::Options.new(['token=a77', 'max=42'])
34
+ assert_equal('a77', opts.token)
35
+ assert_equal(42, opts.max)
36
+ end
37
+
38
+ def test_with_nil
39
+ opts = Judges::Options.new(nil)
40
+ assert(opts.foo.nil?)
41
+ end
42
+
43
+ def test_with_hash
44
+ opts = Judges::Options.new('foo' => 42)
45
+ assert_equal(42, opts.foo)
46
+ end
47
+ end
data/test/test_pack.rb CHANGED
@@ -22,6 +22,7 @@
22
22
 
23
23
  require 'minitest/autorun'
24
24
  require 'tmpdir'
25
+ require 'loog'
25
26
  require 'factbase'
26
27
  require_relative '../lib/judges'
27
28
  require_relative '../lib/judges/pack'
@@ -34,7 +35,7 @@ class TestPack < Minitest::Test
34
35
  def test_basic_run
35
36
  Dir.mktmpdir do |d|
36
37
  File.write(File.join(d, 'foo.rb'), '$fb.insert')
37
- pack = Judges::Pack.new(d)
38
+ pack = Judges::Pack.new(d, Loog::VERBOSE)
38
39
  fb = Factbase.new
39
40
  pack.run(fb, {})
40
41
  assert_equal(1, fb.size)
@@ -44,7 +45,7 @@ class TestPack < Minitest::Test
44
45
  def test_run_isolated
45
46
  Dir.mktmpdir do |d|
46
47
  File.write(File.join(d, 'bar.rb'), '$fb.insert')
47
- pack = Judges::Pack.new(d)
48
+ pack = Judges::Pack.new(d, Loog::VERBOSE)
48
49
  fb1 = Factbase.new
49
50
  pack.run(fb1, {})
50
51
  assert_equal(1, fb1.size)
@@ -53,4 +54,24 @@ class TestPack < Minitest::Test
53
54
  assert_equal(1, fb2.size)
54
55
  end
55
56
  end
57
+
58
+ def test_with_supplemenary_functions
59
+ Dir.mktmpdir do |d|
60
+ File.write(File.join(d, 'x.rb'), 'once($fb).insert')
61
+ pack = Judges::Pack.new(d, Loog::VERBOSE)
62
+ pack.run(Factbase.new, {})
63
+ end
64
+ end
65
+
66
+ def test_sets_judge_value_correctly
67
+ Dir.mktmpdir do |d|
68
+ j = 'this_is_it'
69
+ dir = File.join(d, j)
70
+ FileUtils.mkdir(dir)
71
+ File.write(File.join(dir, 'foo.rb'), '$loog.info("judge=" + $judge)')
72
+ log = Loog::Buffer.new
73
+ Judges::Pack.new(dir, log).run(Factbase.new, {})
74
+ assert(log.to_s.include?("judge=#{j}"))
75
+ end
76
+ end
56
77
  end
data/test/test_packs.rb CHANGED
@@ -22,6 +22,7 @@
22
22
 
23
23
  require 'minitest/autorun'
24
24
  require 'tmpdir'
25
+ require 'loog'
25
26
  require_relative '../lib/judges'
26
27
  require_relative '../lib/judges/packs'
27
28
 
@@ -35,7 +36,7 @@ class TestPacks < Minitest::Test
35
36
  File.write(File.join(d, 'foo.rb'), 'hey')
36
37
  File.write(File.join(d, 'something.yml'), "---\nfoo: 42")
37
38
  found = 0
38
- Judges::Packs.new(d).each do |p|
39
+ Judges::Packs.new(d, Loog::VERBOSE).each do |p|
39
40
  assert_equal('foo.rb', p.script)
40
41
  found += 1
41
42
  assert_equal(42, p.tests.first['foo'])
metadata CHANGED
@@ -1,43 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: judges
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
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-12 00:00:00.000000000 Z
11
+ date: 2024-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: backtrace
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '0.3'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '0.3'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: factbase
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - "~>"
32
18
  - !ruby/object:Gem::Version
33
- version: '0.0'
19
+ version: 0.0.11
34
20
  type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
24
  - - "~>"
39
25
  - !ruby/object:Gem::Version
40
- version: '0.0'
26
+ version: 0.0.11
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: gli
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -101,7 +87,7 @@ files:
101
87
  - ".github/workflows/rake.yml"
102
88
  - ".github/workflows/xcop.yml"
103
89
  - ".github/workflows/yamllint.yml"
104
- - ".github/workflows/zerocracy.yaml"
90
+ - ".github/workflows/zerocracy.yml"
105
91
  - ".gitignore"
106
92
  - ".pdd"
107
93
  - ".rubocop.yml"
@@ -125,14 +111,18 @@ files:
125
111
  - lib/judges/commands/print.rb
126
112
  - lib/judges/commands/test.rb
127
113
  - lib/judges/commands/update.rb
114
+ - lib/judges/fb/once.rb
115
+ - lib/judges/options.rb
128
116
  - lib/judges/pack.rb
129
117
  - lib/judges/packs.rb
130
118
  - renovate.json
131
119
  - test/commands/test_print.rb
132
120
  - test/commands/test_test.rb
133
121
  - test/commands/test_update.rb
122
+ - test/fb/test_once.rb
134
123
  - test/test__helper.rb
135
124
  - test/test_judges.rb
125
+ - test/test_options.rb
136
126
  - test/test_pack.rb
137
127
  - test/test_packs.rb
138
128
  homepage: http://github.com/yegor256/judges