judges 0.0.3 → 0.0.10

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: a8fa940672a16773cc8c32985a34d17be69953bfe402720276139d5e0729cab3
4
- data.tar.gz: 9a06976c0a9853a2f8df682ab226d1d1e99944686f9d928e758c96d5b4a0c0f3
3
+ metadata.gz: 550115852b44ae26b7af9cb776bcbf9e5b7e043579ab8eec3930854f573a6768
4
+ data.tar.gz: 7efe473542ffd401220d8e5b65d853ba144ad8ceab0273f9531e3d462e072afc
5
5
  SHA512:
6
- metadata.gz: 809aae9b795fc20d590482ed7d5d10f4f67aabfe3d5313e6f91972e285791fcc2c460908535c2fb83d7e6d2459f0d05bc594eb31d5c5ca43ac77f4cd20b2dfd2
7
- data.tar.gz: ee8d097cbb5dc297b9abbcdac9d47a7dc826ba1e1d9af68f2a37552eef6f5ee781222e229546bf03236d12c18eaacd1fe9d3eee2452b9efdb365235e9b1f58c5
6
+ metadata.gz: '096f25e43ee418b94ae0a2f4b3d678c170170dfda2228191a269931bcfa1150e4f50151830e1132b3282ccaa768b2129deb8f29e55faebefd0bc7c2bd5ce2700'
7
+ data.tar.gz: d3f8922eeee30008f3883a7592667ce084a1d96785c4b04c51478c028ba99aa28eaddd151ac13a1bb7a101de8cc0f05434d22edcf6bbb1691b4bb76a4bd89067
@@ -0,0 +1,42 @@
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
+ name: zerocracy
22
+ on:
23
+ schedule:
24
+ - cron: '0,10,20,30,50,50 * * * *'
25
+ concurrency:
26
+ group: zerocracy
27
+ cancel-in-progress: true
28
+ jobs:
29
+ yamllint:
30
+ runs-on: ubuntu-22.04
31
+ steps:
32
+ - uses: actions/checkout@v4
33
+ - uses: zerocracy/judges-action@master
34
+ with:
35
+ factbase: recent.fb
36
+ - run: mkdir gh-pages && cp recent.yml gh-pages
37
+ - uses: JamesIves/github-pages-deploy-action@v4.6.0
38
+ with:
39
+ branch: gh-pages
40
+ folder: gh-pages/recent.yml
41
+ factbase: recent.fb
42
+ clean: true
data/.gitignore CHANGED
@@ -6,4 +6,5 @@ Gemfile.lock
6
6
  .DS_Store
7
7
  rdoc/
8
8
  doc/
9
- .yardoc/
9
+ .yardoc/
10
+ temp/
data/.rubocop.yml CHANGED
@@ -47,3 +47,5 @@ Metrics/PerceivedComplexity:
47
47
  Enabled: false
48
48
  Layout/EmptyLineAfterGuardClause:
49
49
  Enabled: false
50
+ Layout/CaseIndentation:
51
+ Enabled: false
data/bin/judges CHANGED
@@ -36,7 +36,7 @@ class App
36
36
 
37
37
  program_desc 'Automated executor of judges for a factbase'
38
38
 
39
- version '0.0.3'
39
+ version '0.0.10'
40
40
 
41
41
  desc 'Make it more verbose, logging as much as possible'
42
42
  switch([:v, :verbose])
@@ -53,15 +53,26 @@ class App
53
53
  c.desc 'Environment variable to pass to every judge'
54
54
  c.flag([:e, :environment], default_value: 'yes')
55
55
  c.action do |global, options, args|
56
- require_relative '../lib/judges/update'
56
+ require_relative '../lib/judges/commands/update'
57
57
  Judges::Update.new(loog).run(options, args)
58
58
  end
59
59
  end
60
60
 
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
70
+ end
71
+
61
72
  desc 'Run automated tests for all judges'
62
73
  command :test do |c|
63
74
  c.action do |global, options, args|
64
- require_relative '../lib/judges/test'
75
+ require_relative '../lib/judges/commands/test'
65
76
  Judges::Test.new(loog).run(options, args)
66
77
  end
67
78
  end
data/features/cli.feature CHANGED
@@ -11,13 +11,32 @@ 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/simple_judge.rb" file with content:
14
+ Given I make a temp directory
15
+ Then I have a "simple/simple_judge.rb" file with content:
15
16
  """
16
17
  $fb.query("(eq kind 'foo')").each do |f|
17
18
  n = $fb.insert
18
19
  n.kind = 'yes!'
19
20
  end
20
21
  """
21
- When I run bin/judges with "update . simple.fb"
22
+ Then I run bin/judges with "update . simple.fb"
22
23
  Then Stdout contains "1 judges processed"
23
24
  And Exit code is zero
25
+
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"
29
+ And Exit code is zero
30
+
31
+ Scenario: Simple print of a small factbase
32
+ Given I make a temp directory
33
+ Then I have a "simple/simple_judge.rb" file with content:
34
+ """
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=yaml simple.fb simple.yml"
40
+ Then Stdout contains "printed"
41
+ And Exit code is zero
42
+
@@ -3,7 +3,8 @@ Feature: Gem Package
3
3
  package the Gem into .gem file
4
4
 
5
5
  Scenario: Gem can be packaged
6
- Given I have a "execs.rb" file with content:
6
+ Given I make a temp directory
7
+ Then I have a "execs.rb" file with content:
7
8
  """
8
9
  #!/usr/bin/env ruby
9
10
  require 'rubygems'
@@ -25,14 +25,19 @@ require 'English'
25
25
 
26
26
  Before do
27
27
  @cwd = Dir.pwd
28
- @dir = Dir.mktmpdir('test')
29
- FileUtils.mkdir_p(@dir)
30
- Dir.chdir(@dir)
31
28
  end
32
29
 
33
30
  After do
34
- Dir.chdir(@cwd)
35
- FileUtils.rm_rf(@dir)
31
+ unless @tmp.nil?
32
+ Dir.chdir(@cwd)
33
+ FileUtils.rm_rf(@tmp)
34
+ end
35
+ end
36
+
37
+ Given(/^I make a temp directory$/) do
38
+ @tmp = Dir.mktmpdir('test')
39
+ FileUtils.mkdir_p(@tmp)
40
+ Dir.chdir(@tmp)
36
41
  end
37
42
 
38
43
  Given(/^I have a "([^"]*)" file with content:$/) do |file, text|
@@ -46,6 +51,18 @@ When(%r{^I run bin/judges with "([^"]*)"$}) do |arg|
46
51
  @exitstatus = $CHILD_STATUS.exitstatus
47
52
  end
48
53
 
54
+ When(/^I run bash with "([^"]*)"$/) do |text|
55
+ FileUtils.copy_entry(@cwd, File.join(@tmp, 'judges'))
56
+ @stdout = `#{text}`
57
+ @exitstatus = $CHILD_STATUS.exitstatus
58
+ end
59
+
60
+ When(/^I run bash with:$/) do |text|
61
+ FileUtils.copy_entry(@cwd, File.join(@tmp, 'judges'))
62
+ @stdout = `#{text}`
63
+ @exitstatus = $CHILD_STATUS.exitstatus
64
+ end
65
+
49
66
  Then(/^Stdout contains "([^"]*)"$/) do |txt|
50
67
  raise "STDOUT doesn't contain '#{txt}':\n#{@stdout}" unless @stdout.include?(txt)
51
68
  end
@@ -61,15 +78,3 @@ end
61
78
  Then(/^Exit code is not zero$/) do
62
79
  raise 'Zero exit code' if @exitstatus.zero?
63
80
  end
64
-
65
- When(/^I run bash with "([^"]*)"$/) do |text|
66
- FileUtils.copy_entry(@cwd, File.join(@dir, 'judges'))
67
- @stdout = `#{text}`
68
- @exitstatus = $CHILD_STATUS.exitstatus
69
- end
70
-
71
- When(/^I run bash with:$/) do |text|
72
- FileUtils.copy_entry(@cwd, File.join(@dir, 'judges'))
73
- @stdout = `#{text}`
74
- @exitstatus = $CHILD_STATUS.exitstatus
75
- end
data/judges.gemspec CHANGED
@@ -24,12 +24,16 @@ require 'English'
24
24
 
25
25
  Gem::Specification.new do |s|
26
26
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
27
- s.required_ruby_version = '>=2.3'
27
+ s.required_ruby_version = '>=3.2'
28
28
  s.name = 'judges'
29
- s.version = '0.0.3'
29
+ s.version = '0.0.10'
30
30
  s.license = 'MIT'
31
- s.summary = 'Command-line tool for a Factbase'
32
- s.description = 'Runs a collection of judges against a factbase'
31
+ s.summary = 'Command-Line Tool for a Factbase'
32
+ s.description = '
33
+ Runs a collection of \"judges\" against a \"factbase,\" modifying it and updating.
34
+ Also, helps printing a factbase, merge with another one, inspect, and so on.
35
+ Also, helps run automated tests for a set of judges.
36
+ '
33
37
  s.authors = ['Yegor Bugayenko']
34
38
  s.email = 'yegor256@gmail.com'
35
39
  s.homepage = 'http://github.com/yegor256/judges'
@@ -0,0 +1,63 @@
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 'fileutils'
24
+ require 'factbase'
25
+ require_relative '../../judges'
26
+ require_relative '../../judges/packs'
27
+
28
+ # Update.
29
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
30
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
31
+ # License:: MIT
32
+ class Judges::Print
33
+ def initialize(loog)
34
+ @loog = loog
35
+ end
36
+
37
+ def run(opts, args)
38
+ raise 'At lease one argument required' if args.empty?
39
+ f = args[0]
40
+ raise "The file is absent: #{f}" unless File.exist?(f)
41
+ o = args[1]
42
+ if o.nil?
43
+ raise 'Either provide output file name or use --auto' unless opts[:auto]
44
+ o = File.join(File.dirname(f), File.basename(f).gsub(/\.[^.]*$/, ''))
45
+ o = "#{o}.#{opts[:format]}"
46
+ end
47
+ fb = Factbase.new
48
+ fb.import(File.read(f))
49
+ @loog.info("Factbase imported from #{f} (#{File.size(f)} bytes)")
50
+ FileUtils.mkdir_p(File.dirname(o))
51
+ output =
52
+ case opts[:format].downcase
53
+ when 'yaml'
54
+ fb.to_yaml
55
+ when 'json'
56
+ fb.to_json
57
+ when 'xml'
58
+ fb.to_xml
59
+ end
60
+ File.write(o, output)
61
+ @loog.info("Factbase printed to #{o} (#{File.size(o)} bytes)")
62
+ end
63
+ end
@@ -22,8 +22,8 @@
22
22
 
23
23
  require 'factbase'
24
24
  require 'nokogiri'
25
- require_relative '../judges'
26
- require_relative '../judges/packs'
25
+ require_relative '../../judges'
26
+ require_relative '../../judges/packs'
27
27
 
28
28
  # Test.
29
29
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -21,8 +21,9 @@
21
21
  # SOFTWARE.
22
22
 
23
23
  require 'factbase'
24
- require_relative '../judges'
25
- require_relative '../judges/packs'
24
+ require 'fileutils'
25
+ require_relative '../../judges'
26
+ require_relative '../../judges/packs'
26
27
 
27
28
  # Update.
28
29
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -36,6 +37,7 @@ class Judges::Update
36
37
  def run(_opts, args)
37
38
  raise 'Exactly two arguments required' unless args.size == 2
38
39
  dir = args[0]
40
+ raise "The directory is absent: #{dir}" unless File.exist?(dir)
39
41
  file = args[1]
40
42
  fb = Factbase.new
41
43
  if File.exist?(file)
@@ -49,6 +51,7 @@ class Judges::Update
49
51
  p.run(fb, {})
50
52
  end
51
53
  @loog.info("#{done} judges processed")
54
+ FileUtils.mkdir_p(File.dirname(file))
52
55
  File.write(file, fb.export)
53
56
  @loog.info("Factbase exported to #{file} (#{File.size(file)} bytes)")
54
57
  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 'loog'
25
+ require 'factbase'
26
+ require 'yaml'
27
+ require_relative '../../lib/judges'
28
+ require_relative '../../lib/judges/commands/print'
29
+
30
+ # Test.
31
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
32
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
33
+ # License:: MIT
34
+ class TestPrint < Minitest::Test
35
+ def test_simple_print
36
+ Dir.mktmpdir do |d|
37
+ f = File.join(d, 'base.fb')
38
+ fb = Factbase.new
39
+ fb.insert
40
+ File.write(f, fb.export)
41
+ Judges::Print.new(Loog::VERBOSE).run({ format: 'yaml', auto: true }, [f])
42
+ y = File.join(d, 'base.yaml')
43
+ assert(File.exist?(y))
44
+ assert_equal(1, YAML.load_file(y)['facts'].size)
45
+ end
46
+ end
47
+ end
@@ -22,8 +22,8 @@
22
22
 
23
23
  require 'minitest/autorun'
24
24
  require 'loog'
25
- require_relative '../lib/judges'
26
- require_relative '../lib/judges/test'
25
+ require_relative '../../lib/judges'
26
+ require_relative '../../lib/judges/commands/test'
27
27
 
28
28
  # Test.
29
29
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -41,8 +41,8 @@ class TestTest < Minitest::Test
41
41
  foo: 42
42
42
  expected:
43
43
  - /fb[count(f)=1]
44
- - /fb/f[foo/v='42']
45
- - /fb/f[bar/v='4']
44
+ - /fb/f[foo='42']
45
+ - /fb/f[bar='4']
46
46
  YAML
47
47
  )
48
48
  Judges::Test.new(Loog::VERBOSE).run(nil, [d])
@@ -22,8 +22,8 @@
22
22
 
23
23
  require 'minitest/autorun'
24
24
  require 'loog'
25
- require_relative '../lib/judges'
26
- require_relative '../lib/judges/update'
25
+ require_relative '../../lib/judges'
26
+ require_relative '../../lib/judges/commands/update'
27
27
 
28
28
  # Test.
29
29
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: judges
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -80,7 +80,10 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.10'
83
- description: Runs a collection of judges against a factbase
83
+ description: "\n Runs a collection of \\\"judges\\\" against a \\\"factbase,\\\"
84
+ modifying it and updating.\n Also, helps printing a factbase, merge with another
85
+ one, inspect, and so on.\n Also, helps run automated tests for a set of judges.\n
86
+ \ "
84
87
  email: yegor256@gmail.com
85
88
  executables:
86
89
  - judges
@@ -98,6 +101,7 @@ files:
98
101
  - ".github/workflows/rake.yml"
99
102
  - ".github/workflows/xcop.yml"
100
103
  - ".github/workflows/yamllint.yml"
104
+ - ".github/workflows/zerocracy.yaml"
101
105
  - ".gitignore"
102
106
  - ".pdd"
103
107
  - ".rubocop.yml"
@@ -112,23 +116,25 @@ files:
112
116
  - features/gem_package.feature
113
117
  - features/step_definitions/steps.rb
114
118
  - features/support/env.rb
119
+ - fixtures/reward_for_good_bug/README.md
115
120
  - fixtures/reward_for_good_bug/no-reward.yml
116
- - fixtures/reward_for_good_bug/reason.md
117
121
  - fixtures/reward_for_good_bug/reward_it.rb
118
122
  - fixtures/reward_for_good_bug/simple-reward.yml
119
123
  - judges.gemspec
120
124
  - lib/judges.rb
125
+ - lib/judges/commands/print.rb
126
+ - lib/judges/commands/test.rb
127
+ - lib/judges/commands/update.rb
121
128
  - lib/judges/pack.rb
122
129
  - lib/judges/packs.rb
123
- - lib/judges/test.rb
124
- - lib/judges/update.rb
125
130
  - renovate.json
131
+ - test/commands/test_print.rb
132
+ - test/commands/test_test.rb
133
+ - test/commands/test_update.rb
126
134
  - test/test__helper.rb
127
135
  - test/test_judges.rb
128
136
  - test/test_pack.rb
129
137
  - test/test_packs.rb
130
- - test/test_test.rb
131
- - test/test_update.rb
132
138
  homepage: http://github.com/yegor256/judges
133
139
  licenses:
134
140
  - MIT
@@ -143,7 +149,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
149
  requirements:
144
150
  - - ">="
145
151
  - !ruby/object:Gem::Version
146
- version: '2.3'
152
+ version: '3.2'
147
153
  required_rubygems_version: !ruby/object:Gem::Requirement
148
154
  requirements:
149
155
  - - ">="
@@ -153,5 +159,5 @@ requirements: []
153
159
  rubygems_version: 3.4.10
154
160
  signing_key:
155
161
  specification_version: 4
156
- summary: Command-line tool for a Factbase
162
+ summary: Command-Line Tool for a Factbase
157
163
  test_files: []