judges 0.0.1 → 0.0.3

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: 6ff9c5cda4904c14f9a32d344dcfae49a25e199795d3a6a9d42ea0e6071983a6
4
- data.tar.gz: 6c57648815517accb61a017c8d36749c83013ef66a66ce28e29abc9149a588da
3
+ metadata.gz: a8fa940672a16773cc8c32985a34d17be69953bfe402720276139d5e0729cab3
4
+ data.tar.gz: 9a06976c0a9853a2f8df682ab226d1d1e99944686f9d928e758c96d5b4a0c0f3
5
5
  SHA512:
6
- metadata.gz: bc1ceb3d41ab2c6b24cda01ab8f8d81876ab759eab3982703ed075ff23bd2557045b3d9216fbfcfbc0c18a9c3fc9eaaca4f43a5239bdeccc269731e3d06d055e
7
- data.tar.gz: d3094a158604614bc2a408363939af5e39e83eef34813bc8504c63f240b14ea7d002751eeb3c6e700da6526a9fba06b4b3a47754fcbb899104c321ad6450468f
6
+ metadata.gz: 809aae9b795fc20d590482ed7d5d10f4f67aabfe3d5313e6f91972e285791fcc2c460908535c2fb83d7e6d2459f0d05bc594eb31d5c5ca43ac77f4cd20b2dfd2
7
+ data.tar.gz: ee8d097cbb5dc297b9abbcdac9d47a7dc826ba1e1d9af68f2a37552eef6f5ee781222e229546bf03236d12c18eaacd1fe9d3eee2452b9efdb365235e9b1f58c5
data/.rubocop.yml CHANGED
@@ -23,14 +23,16 @@ AllCops:
23
23
  - 'bin/**/*'
24
24
  - 'assets/**/*'
25
25
  DisplayCopNames: true
26
- TargetRubyVersion: 2.3
26
+ TargetRubyVersion: 3.2
27
27
  SuggestExtensions: false
28
28
  NewCops: enable
29
29
 
30
- Gemspec/RequiredRubyVersion:
30
+ Style/GlobalVars:
31
31
  Enabled: false
32
32
  Metrics/MethodLength:
33
33
  Enabled: false
34
+ Gemspec/RequiredRubyVersion:
35
+ Enabled: false
34
36
  Style/ClassAndModuleChildren:
35
37
  Enabled: false
36
38
  Layout/MultilineMethodCallIndentation:
@@ -38,10 +40,10 @@ Layout/MultilineMethodCallIndentation:
38
40
  Metrics/AbcSize:
39
41
  Enabled: false
40
42
  Metrics/BlockLength:
41
- Max: 30
43
+ Enabled: false
42
44
  Metrics/CyclomaticComplexity:
43
- Max: 20
45
+ Enabled: false
44
46
  Metrics/PerceivedComplexity:
45
- Max: 20
47
+ Enabled: false
46
48
  Layout/EmptyLineAfterGuardClause:
47
49
  Enabled: false
data/bin/judges CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- # Copyright (c) 2014-2024 Yegor Bugayenko
3
+ # Copyright (c) 2024 Yegor Bugayenko
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -22,65 +22,49 @@
22
22
 
23
23
  $stdout.sync = true
24
24
 
25
- require 'slop'
25
+ require 'gli'
26
26
  require 'loog'
27
27
  require 'factbase'
28
28
 
29
- loog = Loog::REGULAR
30
-
31
- opts = Slop.parse(ARGV, strict: true, help: true) do |o|
32
- o.banner = "Usage: judges [options] <directory> <factbase>"
33
- o.bool '-h', '--help', 'Show brief intro'
34
- o.bool '--version', 'Print tool\'s version'
35
- end
29
+ Encoding.default_external = Encoding::UTF_8
30
+ Encoding.default_internal = Encoding::UTF_8
36
31
 
37
- if opts.help?
38
- puts opts
39
- exit
40
- end
32
+ class App
33
+ extend GLI::App
41
34
 
42
- if opts.verbose?
43
- loog = Loog::VERBOSE
44
- end
35
+ loog = Loog::REGULAR
45
36
 
46
- if opts.version?
47
- loog.info('0.0.1')
48
- exit
49
- end
37
+ program_desc 'Automated executor of judges for a factbase'
50
38
 
51
- Encoding.default_external = Encoding::UTF_8
52
- Encoding.default_internal = Encoding::UTF_8
39
+ version '0.0.3'
53
40
 
54
- dir = opts.arguments[0]
55
- file = opts.arguments[1]
56
- $fb = Factbase.new
57
- if File.exist?(file)
58
- $fb.import(File.read(file))
59
- loog.info("Factbase imported from #{file} (#{File.size(file)})")
60
- else
61
- loog.info("There is no Factbase to import from #{file}")
62
- end
41
+ desc 'Make it more verbose, logging as much as possible'
42
+ switch([:v, :verbose])
63
43
 
64
- def base(file)
65
- File::basename(file).gsub(/\.rb$/, '')
66
- end
44
+ pre do |global, command, options, args|
45
+ if global[:verbose]
46
+ loog = Loog::VERBOSE
47
+ end
48
+ true
49
+ end
67
50
 
68
- scripts = Dir.glob(File.join(dir, "**/*.rb")).to_a
69
- loog.info("#{scripts.size} .rb scripts found in #{dir}")
70
- scripts.each do |f|
71
- next unless base(f).start_with?('_')
72
- require f
73
- end
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/update'
57
+ Judges::Update.new(loog).run(options, args)
58
+ end
59
+ end
74
60
 
75
- done = 0
76
- scripts.each do |f|
77
- b = base(f)
78
- next if b.start_with?('_')
79
- $judge = b
80
- require f
81
- done += 1
61
+ desc 'Run automated tests for all judges'
62
+ command :test do |c|
63
+ c.action do |global, options, args|
64
+ require_relative '../lib/judges/test'
65
+ Judges::Test.new(loog).run(options, args)
66
+ end
67
+ end
82
68
  end
83
- loog.info("#{done} judges processed")
84
69
 
85
- File.write(file, $fb.export)
86
- loog.info("Factbase exported to #{file} (#{File.size(file)})")
70
+ exit App.run(ARGV)
data/features/cli.feature CHANGED
@@ -11,13 +11,13 @@ Feature: Simple Run
11
11
  Then Exit code is zero
12
12
 
13
13
  Scenario: Simple run of a few judges
14
- Given I have a "simple_judge.rb" file with content:
14
+ Given I have a "simple/simple_judge.rb" file with content:
15
15
  """
16
16
  $fb.query("(eq kind 'foo')").each do |f|
17
17
  n = $fb.insert
18
18
  n.kind = 'yes!'
19
19
  end
20
20
  """
21
- When I run bin/judges with ". simple.fb"
21
+ When I run bin/judges with "update . simple.fb"
22
22
  Then Stdout contains "1 judges processed"
23
23
  And Exit code is zero
@@ -21,7 +21,6 @@
21
21
  # SOFTWARE.
22
22
 
23
23
  require 'tmpdir'
24
- require 'slop'
25
24
  require 'English'
26
25
 
27
26
  Before do
@@ -29,9 +28,6 @@ Before do
29
28
  @dir = Dir.mktmpdir('test')
30
29
  FileUtils.mkdir_p(@dir)
31
30
  Dir.chdir(@dir)
32
- @opts = Slop.parse ['-v'] do |o|
33
- o.bool '-v', '--verbose'
34
- end
35
31
  end
36
32
 
37
33
  After do
@@ -77,11 +73,3 @@ When(/^I run bash with:$/) do |text|
77
73
  @stdout = `#{text}`
78
74
  @exitstatus = $CHILD_STATUS.exitstatus
79
75
  end
80
-
81
- Given(/^It is Unix$/) do
82
- pending if Gem.win_platform?
83
- end
84
-
85
- Given(/^It is Windows$/) do
86
- pending unless Gem.win_platform?
87
- end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2022-2024 Yegor Bugayenko
3
+ # Copyright (c) 2024 Yegor Bugayenko
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -0,0 +1,31 @@
1
+ # Copyright (c) 2024 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+ ---
21
+ input:
22
+ -
23
+ kind: bug was accepted
24
+ reporter: yegor256
25
+ time: 2024-01-01T03:15:45
26
+ seen:
27
+ - one
28
+ - this judge
29
+ - two
30
+ expected:
31
+ - /fb[count(f)=1]
@@ -0,0 +1,8 @@
1
+ # Why bugs reports are rewarded?
2
+
3
+ Every bug reported and accepted deserves a reward, which
4
+ are given to the reporter of the bug. A bug is considered as
5
+ "accepted" only if it has the `bug`, `enhancement`, or `question` label
6
+ attached to it. Such a reward encourages programmers to report
7
+ more bugs, thus revealing problems that will be fixed before they
8
+ are shipped to a customer.
@@ -0,0 +1,29 @@
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
+ $fb.query("(and (eq kind 'bug was accepted') (not (eq seen 'this judge')))").each do |f|
24
+ n = $fb.insert
25
+ n.kind = 'nominate for good bug'
26
+ n.payee = f.reporter
27
+ n.amount = 15
28
+ n.message = 'thanks for reporting a bug; you get +15 points for this'
29
+ end
@@ -0,0 +1,34 @@
1
+ # Copyright (c) 2024 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+ ---
21
+ input:
22
+ -
23
+ kind: bug was accepted
24
+ reporter: yegor256
25
+ time: 2024-01-01T03:15:45
26
+ seen:
27
+ - one
28
+ - two
29
+ - three
30
+ expected:
31
+ - /fb[count(f)=2]
32
+ - /fb/f[kind='nominate for good bug']
33
+ - /fb/f[payee='yegor256']
34
+ - /fb/f[amount='15']
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 = '>=2.3'
28
28
  s.name = 'judges'
29
- s.version = '0.0.1'
29
+ s.version = '0.0.3'
30
30
  s.license = 'MIT'
31
31
  s.summary = 'Command-line tool for a Factbase'
32
32
  s.description = 'Runs a collection of judges against a factbase'
@@ -39,7 +39,8 @@ Gem::Specification.new do |s|
39
39
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
40
40
  s.add_runtime_dependency 'backtrace', '~>0.3'
41
41
  s.add_runtime_dependency 'factbase', '~>0.0'
42
+ s.add_runtime_dependency 'gli', '~>2.21'
42
43
  s.add_runtime_dependency 'loog', '~>0.2'
43
- s.add_runtime_dependency 'slop', '~>4.4'
44
+ s.add_runtime_dependency 'nokogiri', '~> 1.10'
44
45
  s.metadata['rubygems_mfa_required'] = 'true'
45
46
  end
@@ -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
+ require 'yaml'
24
+ require_relative '../judges'
25
+
26
+ # A single pack.
27
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
28
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
29
+ # License:: MIT
30
+ class Judges::Pack
31
+ attr_reader :dir
32
+
33
+ def initialize(dir)
34
+ @dir = dir
35
+ end
36
+
37
+ # Run it with the given Factbase and environment variables.
38
+ def run(fbase, env)
39
+ $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
45
+ s = File.join(@dir, script)
46
+ raise "Can't load '#{s}'" unless File.exist?(s)
47
+ load s
48
+ end
49
+
50
+ # Get the name of the .rb script in the pack.
51
+ def script
52
+ File.basename(Dir.glob(File.join(@dir, '*.rb')).first)
53
+ end
54
+
55
+ # Iterate over .yml tests.
56
+ def tests
57
+ Dir.glob(File.join(@dir, '*.yml')).map do |f|
58
+ YAML.load_file(f)
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,54 @@
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
+ require_relative 'pack'
25
+
26
+ # Collection of all packs to run.
27
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
28
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
29
+ # License:: MIT
30
+ class Judges::Packs
31
+ def initialize(dir)
32
+ @dir = dir
33
+ end
34
+
35
+ # Iterate over them all.
36
+ # @yield [Pack]
37
+ def each
38
+ Dir.glob(File.join(@dir, '**/*.rb')).each do |f|
39
+ d = File.dirname(File.absolute_path(f))
40
+ yield Judges::Pack.new(d)
41
+ end
42
+ end
43
+
44
+ # Iterate over them all.
45
+ # @yield [(Pack, Integer)]
46
+ def each_with_index
47
+ idx = 0
48
+ each do |p|
49
+ yield [p, idx]
50
+ idx += 1
51
+ end
52
+ idx
53
+ end
54
+ end
@@ -0,0 +1,71 @@
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 'factbase'
24
+ require 'nokogiri'
25
+ require_relative '../judges'
26
+ require_relative '../judges/packs'
27
+
28
+ # Test.
29
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
30
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
31
+ # License:: MIT
32
+ class Judges::Test
33
+ def initialize(loog)
34
+ @loog = loog
35
+ end
36
+
37
+ def run(_opts, args)
38
+ raise 'Exactly one argument required' unless args.size == 1
39
+ dir = args[0]
40
+ done = Judges::Packs.new(dir).each_with_index do |p, i|
41
+ p.tests.each do |t|
42
+ test_one(p, t)
43
+ end
44
+ @loog.info("Pack ##{i} found in #{p.dir}")
45
+ end
46
+ @loog.info("#{done} judges tested")
47
+ end
48
+
49
+ private
50
+
51
+ def test_one(pack, yaml)
52
+ fb = Factbase.new
53
+ yaml['input'].each do |i|
54
+ f = fb.insert
55
+ i.each do |k, vv|
56
+ if vv.is_a?(Array)
57
+ vv.each do |v|
58
+ send(f, "#{k}=", v)
59
+ end
60
+ else
61
+ f.send('foo=', 42)
62
+ end
63
+ end
64
+ end
65
+ pack.run(fb, {})
66
+ xml = Nokogiri::XML.parse(fb.to_xml)
67
+ yaml['expected'].each do |xp|
68
+ raise "#{pack.script} with '#{xp}' doesn't match:\n#{xml}" if xml.xpath(xp).empty?
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,55 @@
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 'factbase'
24
+ require_relative '../judges'
25
+ require_relative '../judges/packs'
26
+
27
+ # Update.
28
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
29
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
30
+ # License:: MIT
31
+ class Judges::Update
32
+ def initialize(loog)
33
+ @loog = loog
34
+ end
35
+
36
+ def run(_opts, args)
37
+ raise 'Exactly two arguments required' unless args.size == 2
38
+ dir = args[0]
39
+ file = args[1]
40
+ fb = Factbase.new
41
+ if File.exist?(file)
42
+ fb.import(File.read(file))
43
+ @loog.info("Factbase imported from #{file} (#{File.size(file)} bytes)")
44
+ else
45
+ @loog.info("There is no Factbase to import from #{file}")
46
+ end
47
+ done = Judges::Packs.new(dir).each_with_index do |p, i|
48
+ @loog.info("Pack ##{i} found in #{p.dir}")
49
+ p.run(fb, {})
50
+ end
51
+ @loog.info("#{done} judges processed")
52
+ File.write(file, fb.export)
53
+ @loog.info("Factbase exported to #{file} (#{File.size(file)} bytes)")
54
+ end
55
+ end
data/lib/judges.rb CHANGED
@@ -19,3 +19,9 @@
19
19
  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  # SOFTWARE.
22
+
23
+ # Judges.
24
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
25
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
26
+ # License:: MIT
27
+ module Judges; end
data/test/test_judges.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- #
4
3
  # Copyright (c) 2024 Yegor Bugayenko
5
4
  #
6
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
data/test/test_pack.rb ADDED
@@ -0,0 +1,56 @@
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/pack'
28
+
29
+ # Test.
30
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
31
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
32
+ # License:: MIT
33
+ class TestPack < Minitest::Test
34
+ def test_basic_run
35
+ Dir.mktmpdir do |d|
36
+ File.write(File.join(d, 'foo.rb'), '$fb.insert')
37
+ pack = Judges::Pack.new(d)
38
+ fb = Factbase.new
39
+ pack.run(fb, {})
40
+ assert_equal(1, fb.size)
41
+ end
42
+ end
43
+
44
+ def test_run_isolated
45
+ Dir.mktmpdir do |d|
46
+ File.write(File.join(d, 'bar.rb'), '$fb.insert')
47
+ pack = Judges::Pack.new(d)
48
+ fb1 = Factbase.new
49
+ pack.run(fb1, {})
50
+ assert_equal(1, fb1.size)
51
+ fb2 = Factbase.new
52
+ pack.run(fb2, {})
53
+ assert_equal(1, fb2.size)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,46 @@
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_relative '../lib/judges'
26
+ require_relative '../lib/judges/packs'
27
+
28
+ # Test.
29
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
30
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
31
+ # License:: MIT
32
+ class TestPacks < Minitest::Test
33
+ def test_basic
34
+ Dir.mktmpdir do |d|
35
+ File.write(File.join(d, 'foo.rb'), 'hey')
36
+ File.write(File.join(d, 'something.yml'), "---\nfoo: 42")
37
+ found = 0
38
+ Judges::Packs.new(d).each do |p|
39
+ assert_equal('foo.rb', p.script)
40
+ found += 1
41
+ assert_equal(42, p.tests.first['foo'])
42
+ end
43
+ assert_equal(1, found)
44
+ end
45
+ end
46
+ end
data/test/test_test.rb ADDED
@@ -0,0 +1,72 @@
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 'loog'
25
+ require_relative '../lib/judges'
26
+ require_relative '../lib/judges/test'
27
+
28
+ # Test.
29
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
30
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
31
+ # License:: MIT
32
+ class TestTest < Minitest::Test
33
+ def test_positive
34
+ Dir.mktmpdir do |d|
35
+ File.write(File.join(d, 'foo.rb'), '$fb.query("(eq foo 42)").each { |f| f.bar = 4 }')
36
+ File.write(
37
+ File.join(d, 'something.yml'),
38
+ <<-YAML
39
+ input:
40
+ -
41
+ foo: 42
42
+ expected:
43
+ - /fb[count(f)=1]
44
+ - /fb/f[foo/v='42']
45
+ - /fb/f[bar/v='4']
46
+ YAML
47
+ )
48
+ Judges::Test.new(Loog::VERBOSE).run(nil, [d])
49
+ end
50
+ end
51
+
52
+ def test_negative
53
+ Dir.mktmpdir do |d|
54
+ File.write(File.join(d, 'foo.rb'), '$fb.query("(eq foo 42)").each { |f| f.bar = 4 }')
55
+ File.write(
56
+ File.join(d, 'something.yml'),
57
+ <<-YAML
58
+ input:
59
+ -
60
+ foo: 42
61
+ expected:
62
+ - /fb[count(f)=1]
63
+ - /fb/f[foo/v='42']
64
+ - /fb/f[bar/v='5']
65
+ YAML
66
+ )
67
+ assert_raises do
68
+ Judges::Test.new(Loog::VERBOSE).run(nil, [d])
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,41 @@
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 'loog'
25
+ require_relative '../lib/judges'
26
+ require_relative '../lib/judges/update'
27
+
28
+ # Test.
29
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
30
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
31
+ # License:: MIT
32
+ class TestUpdate < Minitest::Test
33
+ def test_simple_update
34
+ 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))
39
+ end
40
+ end
41
+ 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.0.1
4
+ version: 0.0.3
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-11 00:00:00.000000000 Z
11
+ date: 2024-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: gli
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.21'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.21'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: loog
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -53,19 +67,19 @@ dependencies:
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0.2'
55
69
  - !ruby/object:Gem::Dependency
56
- name: slop
70
+ name: nokogiri
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '4.4'
75
+ version: '1.10'
62
76
  type: :runtime
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '4.4'
82
+ version: '1.10'
69
83
  description: Runs a collection of judges against a factbase
70
84
  email: yegor256@gmail.com
71
85
  executables:
@@ -98,11 +112,23 @@ files:
98
112
  - features/gem_package.feature
99
113
  - features/step_definitions/steps.rb
100
114
  - features/support/env.rb
115
+ - fixtures/reward_for_good_bug/no-reward.yml
116
+ - fixtures/reward_for_good_bug/reason.md
117
+ - fixtures/reward_for_good_bug/reward_it.rb
118
+ - fixtures/reward_for_good_bug/simple-reward.yml
101
119
  - judges.gemspec
102
120
  - lib/judges.rb
121
+ - lib/judges/pack.rb
122
+ - lib/judges/packs.rb
123
+ - lib/judges/test.rb
124
+ - lib/judges/update.rb
103
125
  - renovate.json
104
126
  - test/test__helper.rb
105
127
  - test/test_judges.rb
128
+ - test/test_pack.rb
129
+ - test/test_packs.rb
130
+ - test/test_test.rb
131
+ - test/test_update.rb
106
132
  homepage: http://github.com/yegor256/judges
107
133
  licenses:
108
134
  - MIT