judges 0.0.12 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/judges +2 -2
- data/features/cli.feature +3 -1
- data/judges.gemspec +1 -1
- data/lib/judges/commands/join.rb +3 -3
- data/lib/judges/commands/print.rb +2 -2
- data/lib/judges/commands/test.rb +3 -3
- data/lib/judges/commands/update.rb +11 -8
- data/lib/judges/options.rb +6 -2
- data/lib/judges/to_rel.rb +5 -2
- data/test/commands/test_join.rb +3 -3
- data/test/commands/test_print.rb +1 -1
- data/test/commands/test_update.rb +4 -4
- data/test/test_options.rb +15 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e45e98c063327eedc9ae2731bb8c8c39358291ca8c687f6cf37997df37cf84aa
|
4
|
+
data.tar.gz: 811ae41514764e68e9cc4fa0a3ea0429bed9128eec2142268e4cdb779ce12b5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0414dfaa83953985ce7186c336eac2c1a53e71f88c73f9b89c8f1410208191c5d1ff106d91045fa7c6f6f0dd9eb59ed8c189138b51d4b546d5a0a9bbe4211546
|
7
|
+
data.tar.gz: d3b3e538af3fa858fd19d67afe3f4b10942c97befa99538fceefcb3eef770cb130bbb1631160191d4e7bac47c0dbe62a184959ba3f1c29956bdf86708f88eefe
|
data/bin/judges
CHANGED
@@ -35,7 +35,7 @@ loog = Loog::REGULAR
|
|
35
35
|
|
36
36
|
program_desc('Automated executor of judges for a factbase')
|
37
37
|
|
38
|
-
version('0.0.
|
38
|
+
version('0.0.14')
|
39
39
|
|
40
40
|
synopsis_format(:full)
|
41
41
|
|
@@ -54,7 +54,7 @@ end
|
|
54
54
|
desc 'Update the factbase by passing all judges one by one'
|
55
55
|
command :update do |c|
|
56
56
|
c.desc 'Options to pass to every judge'
|
57
|
-
c.flag([:o, :option],
|
57
|
+
c.flag([:o, :option], multiple: true, arg_name: '<key=value>')
|
58
58
|
c.action do |global, options, args|
|
59
59
|
require_relative '../lib/judges/commands/update'
|
60
60
|
Judges::Update.new(loog).run(options, args)
|
data/features/cli.feature
CHANGED
@@ -19,7 +19,9 @@ Feature: Simple Run
|
|
19
19
|
n.kind = 'yes!'
|
20
20
|
end
|
21
21
|
"""
|
22
|
-
Then I run bin/judges with "update . simple.fb"
|
22
|
+
Then I run bin/judges with "--verbose update -o foo=1 -o bar=2 . simple.fb"
|
23
|
+
Then Stdout contains "foo → "
|
24
|
+
Then Stdout contains "bar → "
|
23
25
|
Then Stdout contains "1 judges processed"
|
24
26
|
And Exit code is zero
|
25
27
|
|
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.
|
29
|
+
s.version = '0.0.14'
|
30
30
|
s.license = 'MIT'
|
31
31
|
s.summary = 'Command-Line Tool for a Factbase'
|
32
32
|
s.description = '
|
data/lib/judges/commands/join.rb
CHANGED
@@ -43,11 +43,11 @@ class Judges::Join
|
|
43
43
|
slave = args[1]
|
44
44
|
raise "The slave factbase is absent: #{slave.to_rel}" unless File.exist?(slave)
|
45
45
|
fb = Factbase.new
|
46
|
-
fb.import(File.
|
46
|
+
fb.import(File.binread(master))
|
47
47
|
@loog.info("Master factbase imported from #{master.to_rel} (#{File.size(master)} bytes)")
|
48
|
-
fb.import(File.
|
48
|
+
fb.import(File.binread(slave))
|
49
49
|
@loog.info("Slave factbase imported from #{slave.to_rel} (#{File.size(slave)} bytes)")
|
50
|
-
File.
|
50
|
+
File.binwrite(master, fb.export)
|
51
51
|
@loog.info("Master factbase exported to #{master.to_rel} (#{File.size(master)} bytes)")
|
52
52
|
end
|
53
53
|
end
|
@@ -46,7 +46,7 @@ class Judges::Print
|
|
46
46
|
o = "#{o}.#{opts[:format]}"
|
47
47
|
end
|
48
48
|
fb = Factbase.new
|
49
|
-
fb.import(File.
|
49
|
+
fb.import(File.binread(f))
|
50
50
|
@loog.info("Factbase imported from #{f.to_rel} (#{File.size(f)} bytes)")
|
51
51
|
FileUtils.mkdir_p(File.dirname(o))
|
52
52
|
output =
|
@@ -58,7 +58,7 @@ class Judges::Print
|
|
58
58
|
when 'xml'
|
59
59
|
fb.to_xml
|
60
60
|
end
|
61
|
-
File.
|
61
|
+
File.binwrite(o, output)
|
62
62
|
@loog.info("Factbase printed to #{o.to_rel} (#{File.size(o)} bytes)")
|
63
63
|
end
|
64
64
|
end
|
data/lib/judges/commands/test.rb
CHANGED
@@ -40,13 +40,13 @@ class Judges::Test
|
|
40
40
|
def run(_opts, args)
|
41
41
|
raise 'Exactly one argument required' unless args.size == 1
|
42
42
|
dir = args[0]
|
43
|
-
@loog.info("Testing judges in
|
43
|
+
@loog.info("Testing judges in #{dir.to_rel}...")
|
44
44
|
errors = []
|
45
45
|
done = Judges::Packs.new(dir, @loog).each_with_index do |p, i|
|
46
|
-
@loog.info("\n👉 Testing
|
46
|
+
@loog.info("\n👉 Testing #{p.script} (##{i}) in #{p.dir.to_rel}...")
|
47
47
|
p.tests.each do |f|
|
48
48
|
yaml = YAML.load_file(f, permitted_classes: [Time])
|
49
|
-
@loog.info("Testing
|
49
|
+
@loog.info("Testing #{f.to_rel}:")
|
50
50
|
begin
|
51
51
|
test_one(p, yaml)
|
52
52
|
rescue StandardError => e
|
@@ -40,31 +40,34 @@ class Judges::Update
|
|
40
40
|
def run(opts, args)
|
41
41
|
raise 'Exactly two arguments required' unless args.size == 2
|
42
42
|
dir = args[0]
|
43
|
-
raise "The directory is absent: #{dir}" unless File.exist?(dir)
|
43
|
+
raise "The directory is absent: #{dir.to_rel}" unless File.exist?(dir)
|
44
44
|
file = args[1]
|
45
45
|
fb = Factbase.new
|
46
46
|
if File.exist?(file)
|
47
|
-
fb.import(File.
|
48
|
-
@loog.info("Factbase imported from
|
47
|
+
fb.import(File.binread(file))
|
48
|
+
@loog.info("Factbase imported from #{file.to_rel} (#{File.size(file)} bytes)")
|
49
49
|
else
|
50
|
-
@loog.info("There is no Factbase to import from
|
50
|
+
@loog.info("There is no Factbase to import from #{file.to_rel} (file is absent)")
|
51
51
|
end
|
52
|
-
options = Judges::Options.new(opts['
|
52
|
+
options = Judges::Options.new(opts['option'])
|
53
53
|
@loog.debug("The following options provided:\n\t#{options.to_s.gsub("\n", "\n\t")}")
|
54
54
|
errors = []
|
55
55
|
done = Judges::Packs.new(dir, @loog).each_with_index do |p, i|
|
56
|
-
@loog.info("
|
56
|
+
@loog.info("Running #{p.dir.to_rel} (##{i})...")
|
57
|
+
before = fb.size
|
57
58
|
begin
|
58
59
|
p.run(fb, options)
|
59
60
|
rescue StandardError => e
|
60
61
|
@loog.warn(Backtrace.new(e))
|
61
62
|
errors << p.script
|
62
63
|
end
|
64
|
+
after = fb.size
|
65
|
+
@loog.info("Pack #{p.dir.to_rel} added #{after - before} facts") if after > before
|
63
66
|
end
|
64
67
|
@loog.info("#{done} judges processed (#{errors.size} errors)")
|
65
68
|
FileUtils.mkdir_p(File.dirname(file))
|
66
|
-
File.
|
67
|
-
@loog.info("Factbase exported to
|
69
|
+
File.binwrite(file, fb.export)
|
70
|
+
@loog.info("Factbase exported to #{file.to_rel} (#{File.size(file)} bytes)")
|
68
71
|
raise "Failed to update correctly (#{errors.size} errors)" unless errors.empty?
|
69
72
|
end
|
70
73
|
end
|
data/lib/judges/options.rb
CHANGED
@@ -39,7 +39,7 @@ class Judges::Options
|
|
39
39
|
@hash.map do |k, v|
|
40
40
|
v = v.to_s
|
41
41
|
v = "#{v[0..3]}#{'*' * (v.length - 4)}" if v.length > 8
|
42
|
-
"#{k}
|
42
|
+
"#{k} → \"#{v}\""
|
43
43
|
end.join("\n")
|
44
44
|
end
|
45
45
|
|
@@ -48,9 +48,13 @@ class Judges::Options
|
|
48
48
|
@hash ||= begin
|
49
49
|
pp = @pairs || []
|
50
50
|
pp = @pairs.map { |k, v| "#{k}=#{v}" } if pp.is_a?(Hash)
|
51
|
+
pp = pp.split(',') if pp.is_a?(String)
|
51
52
|
pp.to_h do |pair|
|
52
53
|
p = pair.split('=', 2)
|
53
|
-
|
54
|
+
k = p[0].strip
|
55
|
+
v = p[1]
|
56
|
+
v = v.nil? ? 'true' : v.strip
|
57
|
+
[k.to_sym, v.match?(/^[0-9]+$/) ? v.to_i : v]
|
54
58
|
end
|
55
59
|
end
|
56
60
|
k = args[0].downcase
|
data/lib/judges/to_rel.rb
CHANGED
@@ -31,10 +31,13 @@ class Object
|
|
31
31
|
def to_rel
|
32
32
|
s = File.absolute_path(to_s)
|
33
33
|
p = Pathname.new(s).relative_path_from(Dir.getwd)
|
34
|
+
t = p.to_s
|
35
|
+
t = s if t.length > s.length
|
36
|
+
t = "\"#{t}\"" if t.include?(' ')
|
34
37
|
if p.directory?
|
35
|
-
"#{
|
38
|
+
"#{t}/"
|
36
39
|
else
|
37
|
-
|
40
|
+
t
|
38
41
|
end
|
39
42
|
end
|
40
43
|
end
|
data/test/commands/test_join.rb
CHANGED
@@ -36,14 +36,14 @@ class TestJoin < Minitest::Test
|
|
36
36
|
master = File.join(d, 'master.fb')
|
37
37
|
fb1 = Factbase.new
|
38
38
|
fb1.insert.zz = 5
|
39
|
-
File.
|
39
|
+
File.binwrite(master, fb1.export)
|
40
40
|
slave = File.join(d, 'slave.fb')
|
41
41
|
fb2 = Factbase.new
|
42
42
|
fb2.insert.foo_bar = 42
|
43
|
-
File.
|
43
|
+
File.binwrite(slave, fb2.export)
|
44
44
|
Judges::Join.new(Loog::VERBOSE).run({}, [master, slave])
|
45
45
|
fb = Factbase.new
|
46
|
-
fb.import(File.
|
46
|
+
fb.import(File.binread(master))
|
47
47
|
xml = Nokogiri::XML.parse(fb.to_xml)
|
48
48
|
assert(!xml.xpath('/fb/f[zz="5"]').empty?, fb.to_xml)
|
49
49
|
assert(!xml.xpath('/fb/f[foo_bar="42"]').empty?, fb.to_xml)
|
data/test/commands/test_print.rb
CHANGED
@@ -37,7 +37,7 @@ class TestPrint < Minitest::Test
|
|
37
37
|
f = File.join(d, 'base.fb')
|
38
38
|
fb = Factbase.new
|
39
39
|
fb.insert
|
40
|
-
File.
|
40
|
+
File.binwrite(f, fb.export)
|
41
41
|
Judges::Print.new(Loog::VERBOSE).run({ format: 'yaml', auto: true }, [f])
|
42
42
|
y = File.join(d, 'base.yaml')
|
43
43
|
assert(File.exist?(y))
|
@@ -35,9 +35,9 @@ class TestUpdate < Minitest::Test
|
|
35
35
|
Dir.mktmpdir do |d|
|
36
36
|
File.write(File.join(d, 'foo.rb'), '$fb.insert.zzz = $options.foo_bar + 1')
|
37
37
|
file = File.join(d, 'base.fb')
|
38
|
-
Judges::Update.new(Loog::VERBOSE).run({ '
|
38
|
+
Judges::Update.new(Loog::VERBOSE).run({ 'option' => ['foo_bar=42'] }, [d, file])
|
39
39
|
fb = Factbase.new
|
40
|
-
fb.import(File.
|
40
|
+
fb.import(File.binread(file))
|
41
41
|
xml = Nokogiri::XML.parse(fb.to_xml)
|
42
42
|
assert(!xml.xpath('/fb/f[zzz="43"]').empty?)
|
43
43
|
end
|
@@ -48,11 +48,11 @@ class TestUpdate < Minitest::Test
|
|
48
48
|
file = File.join(d, 'base.fb')
|
49
49
|
fb = Factbase.new
|
50
50
|
fb.insert.foo_bar = 42
|
51
|
-
File.
|
51
|
+
File.binwrite(file, fb.export)
|
52
52
|
File.write(File.join(d, 'foo.rb'), '$fb.insert.tt = 4')
|
53
53
|
Judges::Update.new(Loog::VERBOSE).run({}, [d, file])
|
54
54
|
fb = Factbase.new
|
55
|
-
fb.import(File.
|
55
|
+
fb.import(File.binread(file))
|
56
56
|
xml = Nokogiri::XML.parse(fb.to_xml)
|
57
57
|
assert(!xml.xpath('/fb/f[tt="4"]').empty?)
|
58
58
|
assert(!xml.xpath('/fb/f[foo_bar="42"]').empty?)
|
data/test/test_options.rb
CHANGED
@@ -35,11 +35,23 @@ class TestOptions < Minitest::Test
|
|
35
35
|
assert_equal(42, opts.max)
|
36
36
|
end
|
37
37
|
|
38
|
+
def test_stips_spaces
|
39
|
+
opts = Judges::Options.new([' token=a77 ', 'max = 42'])
|
40
|
+
assert_equal('a77', opts.token)
|
41
|
+
assert_equal(42, opts.max)
|
42
|
+
end
|
43
|
+
|
38
44
|
def test_with_nil
|
39
45
|
opts = Judges::Options.new(nil)
|
40
46
|
assert(opts.foo.nil?)
|
41
47
|
end
|
42
48
|
|
49
|
+
def test_with_string
|
50
|
+
opts = Judges::Options.new('a=1,b=42')
|
51
|
+
assert_equal(1, opts.a)
|
52
|
+
assert_equal(42, opts.b)
|
53
|
+
end
|
54
|
+
|
43
55
|
def test_with_hash
|
44
56
|
opts = Judges::Options.new('foo' => 42, 'bar' => 'hello')
|
45
57
|
assert_equal(42, opts.foo)
|
@@ -49,6 +61,8 @@ class TestOptions < Minitest::Test
|
|
49
61
|
|
50
62
|
def test_converts_to_string
|
51
63
|
opts = Judges::Options.new('foo' => 44, 'bar' => 'long-string-maybe-secret')
|
52
|
-
|
64
|
+
s = opts.to_s
|
65
|
+
assert(s.include?('foo → "44"'))
|
66
|
+
assert(s.include?('"long********************"'))
|
53
67
|
end
|
54
68
|
end
|