judges 0.20.0 → 0.21.0

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: 1661542d2bb953029d98b55aee247ee5067488e67e7fa4debd8a35d7278bce55
4
- data.tar.gz: 79803f9f17983970b404abd8c8619e08ad3d5587156f4cedd477f295c98ab2bb
3
+ metadata.gz: f826572e575f1c40c556cb5c0de0a2ca5aaf39554ef9d4219e517c6d8492236b
4
+ data.tar.gz: 7f16f70af23a1fb4903934939133015289f06d4a276c32a567356dd60e3fa75f
5
5
  SHA512:
6
- metadata.gz: 60bc48ba4d2532ce4d7960d132a5bc59674794c6b8495ada4852ea83745cdd6cdf1064ff9f76440573c34564c73057a19306f55b23fdddd783bd240517f23099
7
- data.tar.gz: 528812bef0c9f6ba6225210a1130cfd03aea5816eb7c75da99adf323aaf09932cb18d6c0e9e057096212e353b85bf551a65b3144ba86504ff2d1930cdc1dcdaa
6
+ metadata.gz: f3b4e89fcd538caddf490ca8769c2142e6c06bec83eb99582bf426f48ce35617ce169d08d604a9d4ee2780d88f0cc877651fabd863efffc5cb2d1ee96cf6a6ec
7
+ data.tar.gz: 4dd669683164fcd9402f9f4043b5fab0faa086cc68de9f0a6dc1f6e78f9959f5a8a2f18eb3c8fed23986d735010e71c964313090acba222966803b02bd8ba9e3
@@ -21,7 +21,11 @@
21
21
  name: copyrights
22
22
  'on':
23
23
  push:
24
+ branches:
25
+ - master
24
26
  pull_request:
27
+ branches:
28
+ - master
25
29
  jobs:
26
30
  copyrights:
27
31
  runs-on: ubuntu-22.04
@@ -19,9 +19,13 @@
19
19
  # SOFTWARE.
20
20
  ---
21
21
  name: xcop
22
- on:
22
+ 'on':
23
23
  push:
24
+ branches:
25
+ - master
24
26
  pull_request:
27
+ branches:
28
+ - master
25
29
  jobs:
26
30
  xcop:
27
31
  runs-on: ubuntu-22.04
data/README.md CHANGED
@@ -48,6 +48,9 @@ options:
48
48
  max: 100
49
49
  expected:
50
50
  - /fb[count(f)=1]
51
+ after:
52
+ - first.rb
53
+ - second.rb
51
54
  ```
52
55
 
53
56
  Here, the `input` is an array of facts to be placed into the Factbase before
@@ -65,6 +68,10 @@ be executed. After each execution, all expected XPath expressions are validated.
65
68
  The `before` (default: `[]`) is a list of judges that must be executed before
66
69
  the current one.
67
70
 
71
+ The `after` (default: `[]`) is a list of relative file names
72
+ of Ruby scripts that are executed after the judge
73
+ (`$fb` and `$loog` are passed into them).
74
+
68
75
  ## How to contribute
69
76
 
70
77
  Read
@@ -1,12 +1,10 @@
1
1
  Feature: Pull
2
2
  I want to pull a factbase
3
3
 
4
- Scenario: Pull a small factbase
4
+ Scenario: Pull a small factbase, which is absent on the server
5
5
  Given We are online
6
6
  Given I make a temp directory
7
- Then I run bin/judges with "--verbose pull --token 00000000-0000-0000-0000-000000000000 --wait=15 simple simple.fb"
8
- Then Stdout contains "Pulled"
9
- And Exit code is zero
10
- Then I run bin/judges with "inspect simple.fb"
7
+ Then I run bin/judges with "--verbose pull --token 00000000-0000-0000-0000-000000000000 --wait=15 {FAKE-NAME} simple.fb"
8
+ Then Stdout contains "doesn't exist at www.zerocracy.com"
11
9
  And Exit code is zero
12
10
 
@@ -6,6 +6,6 @@ Feature: Push
6
6
  Given I make a temp directory
7
7
  Then I run bin/judges with "--verbose eval simple.fb '(0..1000).each { $fb.insert.foo = 42 }'"
8
8
  And Exit code is zero
9
- Then I run bin/judges with "push --token 00000000-0000-0000-0000-000000000000 --meta a:b --meta foo:bar --meta=pages_url:https://zerocracy.github.io/zerocracy.html --meta=duration:1055 simple simple.fb"
9
+ Then I run bin/judges with "push --token 00000000-0000-0000-0000-000000000000 --meta a:b --meta foo:bar --meta=pages_url:https://zerocracy.github.io/zerocracy.html --meta=duration:1055 {FAKE-NAME} simple.fb"
10
10
  Then Stdout contains "Pushed"
11
11
  And Exit code is zero
@@ -23,6 +23,7 @@
23
23
  require 'tmpdir'
24
24
  require 'net/ping'
25
25
  require 'English'
26
+ require 'securerandom'
26
27
 
27
28
  Before do
28
29
  @cwd = Dir.pwd
@@ -52,6 +53,7 @@ end
52
53
 
53
54
  When(%r{^I run bin/judges with "([^"]*)"$}) do |arg|
54
55
  home = File.join(File.dirname(__FILE__), '../..')
56
+ arg.gsub!('{FAKE-NAME}') { "fake#{SecureRandom.hex(8)}" }
55
57
  cmd = "ruby -I#{home}/lib #{home}/bin/judges #{arg}"
56
58
  cmd = "GLI_DEBUG=true #{cmd}" unless Gem.win_platform?
57
59
  @stdout = `#{cmd} 2>&1`
@@ -28,14 +28,14 @@ Feature: Test
28
28
 
29
29
  Scenario: Simple test of a few judges, with a lib
30
30
  Given I make a temp directory
31
- Then I have a "myjudges/myjudge/simple_judge.rb" file with content:
31
+ Then I have a "myjudges/good/good.rb" file with content:
32
32
  """
33
33
  $valve.enter('boom', 'some reason') do
34
34
  n = $fb.insert
35
35
  n.foo = $foo
36
36
  end
37
37
  """
38
- Then I have a "myjudges/myjudge/good.yml" file with content:
38
+ Then I have a "myjudges/good/good.yml" file with content:
39
39
  """
40
40
  ---
41
41
  category: good
@@ -51,7 +51,7 @@ Feature: Test
51
51
 
52
52
  Scenario: Simple test with many runs
53
53
  Given I make a temp directory
54
- Then I have a "foo/simple.rb" file with content:
54
+ Then I have a "foo/foo.rb" file with content:
55
55
  """
56
56
  n = $fb.insert
57
57
  n.foo = $fb.size
@@ -70,7 +70,7 @@ Feature: Test
70
70
 
71
71
  Scenario: Simple test with many runs and many asserts
72
72
  Given I make a temp directory
73
- Then I have a "foo/simple.rb" file with content:
73
+ Then I have a "foo/foo.rb" file with content:
74
74
  """
75
75
  n = $fb.insert
76
76
  n.foo = $fb.size
@@ -141,3 +141,25 @@ Feature: Test
141
141
  """
142
142
  Then I run bin/judges with "test mine"
143
143
  And Exit code is zero
144
+
145
+ Scenario: Test with a post-assert
146
+ Given I make a temp directory
147
+ Then I have a "mine/foo/foo.rb" file with content:
148
+ """
149
+ n = $fb.insert
150
+ n.foo = 42
151
+ """
152
+ Then I have a "mine/foo/assert.rb" file with content:
153
+ """
154
+ raise unless $fb.size == 1
155
+ """
156
+ Then I have a "mine/foo/simple.yml" file with content:
157
+ """
158
+ ---
159
+ expected:
160
+ - /fb[count(f)=1]
161
+ after:
162
+ - assert.rb
163
+ """
164
+ Then I run bin/judges with "test mine"
165
+ And Exit code is zero
@@ -3,7 +3,7 @@ Feature: Update
3
3
 
4
4
  Scenario: Simple run of a few judges
5
5
  Given I make a temp directory
6
- Then I have a "simple/simple_judge.rb" file with content:
6
+ Then I have a "simple/simple.rb" file with content:
7
7
  """
8
8
  n = $fb.insert
9
9
  n.kind = 'yes!'
@@ -17,7 +17,7 @@ Feature: Update
17
17
 
18
18
  Scenario: Simple run of a few judges, with a lib
19
19
  Given I make a temp directory
20
- Then I have a "mine/judge1/simple_judge.rb" file with content:
20
+ Then I have a "mine/judge1/judge1.rb" file with content:
21
21
  """
22
22
  $valve.enter('boom', 'for no particular reason') do
23
23
  n = $fb.insert
@@ -35,7 +35,7 @@ Feature: Update
35
35
 
36
36
  Scenario: The update fails when a bug in a judge
37
37
  Given I make a temp directory
38
- Then I have a "mine/judge1/broken.rb" file with content:
38
+ Then I have a "mine/broken/broken.rb" file with content:
39
39
  """
40
40
  a < 1
41
41
  """
@@ -45,7 +45,7 @@ Feature: Update
45
45
 
46
46
  Scenario: The update fails when a broken Ruby syntax in a judge
47
47
  Given I make a temp directory
48
- Then I have a "mine/judge1/broken.rb" file with content:
48
+ Then I have a "mine/broken/broken.rb" file with content:
49
49
  """
50
50
  invalid$ruby$syntax$here
51
51
  """
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.20.0'
29
+ s.version = '0.21.0'
30
30
  s.license = 'MIT'
31
31
  s.summary = 'Command-Line Tool for a Factbase'
32
32
  s.description =
@@ -82,6 +82,12 @@ class Judges::Test
82
82
  test_one(fb, opts, j, n, yaml, assert: false)
83
83
  end
84
84
  test_one(fb, opts, judge, tname, yaml)
85
+ yaml['after']&.each do |rb|
86
+ @loog.info("Running #{rb} assertion script...")
87
+ $fb = fb
88
+ $loog = @loog
89
+ load(File.join(judge.dir, rb), true)
90
+ end
85
91
  tests += 1
86
92
  rescue StandardError => e
87
93
  @loog.warn(Backtrace.new(e))
data/lib/judges/judge.rb CHANGED
@@ -70,9 +70,10 @@ class Judges::Judge
70
70
 
71
71
  # Get the name of the .rb script in the judge.
72
72
  def script
73
- s = Dir.glob(File.join(@dir, '*.rb')).first
74
- raise "No *.rb scripts in #{@dir.to_rel}" if s.nil?
75
- File.basename(s)
73
+ b = "#{File.basename(@dir)}.rb"
74
+ files = Dir.glob(File.join(@dir, '*.rb')).map { |f| File.basename(f) }
75
+ raise "No #{b} script in #{@dir.to_rel} among #{files}" unless files.include?(b)
76
+ b
76
77
  end
77
78
 
78
79
  # Return all .yml tests files.
data/lib/judges/judges.rb CHANGED
@@ -24,6 +24,20 @@ require_relative '../judges'
24
24
  require_relative 'judge'
25
25
 
26
26
  # Collection of all judges to run.
27
+ #
28
+ # In the directory +dir+ the following structure must be maintained:
29
+ #
30
+ # dir/
31
+ # judge-one/
32
+ # judge-one.rb
33
+ # other files...
34
+ # judge-two/
35
+ # judge-two.rb
36
+ # other files...
37
+ #
38
+ # The name of a directory of a judge must be exactly the same as the
39
+ # name of the +.rb+ script inside the directory.
40
+ #
27
41
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
28
42
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
29
43
  # License:: MIT
@@ -45,9 +59,12 @@ class Judges::Judges
45
59
  # Iterate over them all.
46
60
  # @yield [Judge]
47
61
  def each
48
- Dir.glob(File.join(@dir, '**/*.rb')).each do |f|
49
- d = File.dirname(File.absolute_path(f))
50
- yield Judges::Judge.new(d, @lib, @loog)
62
+ return to_enum(__method__) unless block_given?
63
+ Dir.glob(File.join(@dir, '*')).each do |d|
64
+ next unless File.directory?(d)
65
+ b = File.basename(d)
66
+ next unless File.exist?(File.join(d, "#{b}.rb"))
67
+ yield Judges::Judge.new(File.absolute_path(d), @lib, @loog)
51
68
  end
52
69
  end
53
70
 
@@ -50,7 +50,7 @@ class Judges::Options
50
50
  def to_s
51
51
  to_h.map do |k, v|
52
52
  v = v.to_s
53
- v = "#{v[0..3]}#{'*' * (v.length - 4)}" if v.length > 8
53
+ v = "#{v[0..3]}#{'*' * (v.length - 8)}#{v[-4..]}" if v.length > 8
54
54
  "#{k} → \"#{v}\""
55
55
  end.join("\n")
56
56
  end
data/lib/judges.rb CHANGED
@@ -25,5 +25,5 @@
25
25
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
26
26
  # License:: MIT
27
27
  module Judges
28
- VERSION = '0.20.0'
28
+ VERSION = '0.21.0'
29
29
  end
@@ -36,7 +36,7 @@ class TestImport < Minitest::Test
36
36
  Dir.mktmpdir do |d|
37
37
  file = File.join(d, 'base.fb')
38
38
  yaml = File.join(d, 'input.yml')
39
- File.write(
39
+ save_it(
40
40
  yaml,
41
41
  <<-YAML
42
42
  -
@@ -32,9 +32,9 @@ require_relative '../../lib/judges/commands/test'
32
32
  class TestTest < Minitest::Test
33
33
  def test_positive
34
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'),
35
+ save_it(File.join(d, 'foo/foo.rb'), '$fb.query("(eq foo 42)").each { |f| f.bar = 4 }')
36
+ save_it(
37
+ File.join(d, 'foo/something.yml'),
38
38
  <<-YAML
39
39
  input:
40
40
  -
@@ -51,9 +51,9 @@ class TestTest < Minitest::Test
51
51
 
52
52
  def test_negative
53
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'),
54
+ save_it(File.join(d, 'foo/foo.rb'), '$fb.query("(eq foo 42)").each { |f| f.bar = 4 }')
55
+ save_it(
56
+ File.join(d, 'foo/something.yml'),
57
57
  <<-YAML
58
58
  input:
59
59
  -
@@ -72,9 +72,9 @@ class TestTest < Minitest::Test
72
72
 
73
73
  def test_with_options
74
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'),
75
+ save_it(File.join(d, 'foo/foo.rb'), '$fb.insert.foo = $options.bar')
76
+ save_it(
77
+ File.join(d, 'foo/something.yml'),
78
78
  <<-YAML
79
79
  input: []
80
80
  options:
@@ -90,13 +90,10 @@ class TestTest < Minitest::Test
90
90
 
91
91
  def test_with_before
92
92
  Dir.mktmpdir do |d|
93
- home = File.join(d, 'judges')
94
- FileUtils.mkdir_p(File.join(home, 'first'))
95
- File.write(File.join(d, 'judges/first/the-first.rb'), 'x = $fb.size; $fb.insert.foo = x')
96
- FileUtils.mkdir_p(File.join(home, 'second'))
97
- File.write(File.join(d, 'judges/second/the-second.rb'), '$fb.insert.bar = 55')
98
- File.write(
99
- File.join(d, 'judges/second/something.yml'),
93
+ save_it(File.join(d, 'first/first.rb'), 'x = $fb.size; $fb.insert.foo = x')
94
+ save_it(File.join(d, 'second/second.rb'), '$fb.insert.bar = 55')
95
+ save_it(
96
+ File.join(d, 'second/something.yml'),
100
97
  <<-YAML
101
98
  input:
102
99
  -
@@ -110,15 +107,15 @@ class TestTest < Minitest::Test
110
107
  - /fb/f[bar=55]
111
108
  YAML
112
109
  )
113
- Judges::Test.new(Loog::NULL).run({}, [home])
110
+ Judges::Test.new(Loog::NULL).run({}, [d])
114
111
  end
115
112
  end
116
113
 
117
114
  def test_one_judge_negative
118
115
  Dir.mktmpdir do |d|
119
- File.write(File.join(d, 'foo.rb'), '')
120
- File.write(
121
- File.join(d, 'x.yml'),
116
+ save_it(File.join(d, 'foo/foo.rb'), '')
117
+ save_it(
118
+ File.join(d, 'foo/x.yml'),
122
119
  <<-YAML
123
120
  input: []
124
121
  expected:
@@ -130,4 +127,20 @@ class TestTest < Minitest::Test
130
127
  end
131
128
  end
132
129
  end
130
+
131
+ def test_with_after_assertion
132
+ Dir.mktmpdir do |d|
133
+ save_it(File.join(d, 'foo/foo.rb'), '$fb.insert.foo = 42;')
134
+ save_it(File.join(d, 'foo/assert.rb'), 'raise unless $fb.size == 1')
135
+ save_it(
136
+ File.join(d, 'foo/x.yml'),
137
+ <<-YAML
138
+ input: []
139
+ after:
140
+ - assert.rb
141
+ YAML
142
+ )
143
+ Judges::Test.new(Loog::NULL).run({}, [d])
144
+ end
145
+ end
133
146
  end
@@ -34,7 +34,7 @@ require_relative '../../lib/judges/commands/update'
34
34
  class TestUpdate < Minitest::Test
35
35
  def test_build_factbase_from_scratch
36
36
  Dir.mktmpdir do |d|
37
- File.write(File.join(d, 'foo.rb'), 'return if $fb.size > 2; $fb.insert.zzz = $options.foo_bar + 1')
37
+ save_it(File.join(d, 'foo/foo.rb'), 'return if $fb.size > 2; $fb.insert.zzz = $options.foo_bar + 1')
38
38
  file = File.join(d, 'base.fb')
39
39
  Judges::Update.new(Loog::NULL).run({ 'option' => ['foo_bar=42'] }, [d, file])
40
40
  fb = Factbase.new
@@ -50,7 +50,7 @@ class TestUpdate < Minitest::Test
50
50
  fb = Factbase.new
51
51
  fb.insert.foo_bar = 42
52
52
  File.binwrite(file, fb.export)
53
- File.write(File.join(d, 'foo.rb'), '$fb.insert.tt = 4')
53
+ save_it(File.join(d, 'foo/foo.rb'), '$fb.insert.tt = 4')
54
54
  Judges::Update.new(Loog::NULL).run({ 'max-cycles' => 1 }, [d, file])
55
55
  fb = Factbase.new
56
56
  fb.import(File.binread(file))
@@ -62,7 +62,7 @@ class TestUpdate < Minitest::Test
62
62
 
63
63
  def test_update_with_error
64
64
  Dir.mktmpdir do |d|
65
- File.write(File.join(d, 'foo.rb'), 'this$is$a$broken$Ruby$script')
65
+ save_it(File.join(d, 'foo/foo.rb'), 'this$is$a$broken$Ruby$script')
66
66
  file = File.join(d, 'base.fb')
67
67
  Judges::Update.new(Loog::NULL).run({ 'quiet' => true, 'max-cycles' => 2 }, [d, file])
68
68
  end
@@ -71,7 +71,7 @@ class TestUpdate < Minitest::Test
71
71
  def test_update_with_error_no_quiet
72
72
  assert_raises do
73
73
  Dir.mktmpdir do |d|
74
- File.write(File.join(d, 'foo.rb'), 'a < 1')
74
+ save_it(File.join(d, 'foo/foo.rb'), 'a < 1')
75
75
  file = File.join(d, 'base.fb')
76
76
  Judges::Update.new(Loog::NULL).run({ 'quiet' => false }, [d, file])
77
77
  end
@@ -80,7 +80,7 @@ class TestUpdate < Minitest::Test
80
80
 
81
81
  def test_update_with_error_and_summary
82
82
  Dir.mktmpdir do |d|
83
- File.write(File.join(d, 'foo.rb'), 'this$is$a$broken$Ruby$script')
83
+ save_it(File.join(d, 'foo/foo.rb'), 'this$is$a$broken$Ruby$script')
84
84
  file = File.join(d, 'base.fb')
85
85
  2.times do
86
86
  Judges::Update.new(Loog::NULL).run(
data/test/test__helper.rb CHANGED
@@ -32,3 +32,11 @@ require 'minitest/autorun'
32
32
 
33
33
  require 'minitest/reporters'
34
34
  Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new]
35
+
36
+ class Minitest::Test
37
+ def save_it(file, content)
38
+ require 'fileutils'
39
+ FileUtils.mkdir_p(File.dirname(file))
40
+ File.binwrite(file, content)
41
+ end
42
+ end
data/test/test_judge.rb CHANGED
@@ -34,7 +34,7 @@ require_relative '../lib/judges/judge'
34
34
  class TestJudge < Minitest::Test
35
35
  def test_basic_run
36
36
  Dir.mktmpdir do |d|
37
- File.write(File.join(d, 'foo.rb'), '$fb.insert')
37
+ save_it(File.join(d, "#{File.basename(d)}.rb"), '$fb.insert')
38
38
  judge = Judges::Judge.new(d, nil, Loog::NULL)
39
39
  fb = Factbase.new
40
40
  judge.run(fb, {}, {}, {})
@@ -44,7 +44,7 @@ class TestJudge < Minitest::Test
44
44
 
45
45
  def test_run_isolated
46
46
  Dir.mktmpdir do |d|
47
- File.write(File.join(d, 'bar.rb'), '$fb.insert')
47
+ save_it(File.join(d, "#{File.basename(d)}.rb"), '$fb.insert')
48
48
  judge = Judges::Judge.new(d, nil, Loog::NULL)
49
49
  fb1 = Factbase.new
50
50
  judge.run(fb1, {}, {}, {})
@@ -57,8 +57,8 @@ class TestJudge < Minitest::Test
57
57
 
58
58
  def test_passes_local_vars_between_tests
59
59
  Dir.mktmpdir do |d|
60
- File.write(
61
- File.join(d, 'x.rb'),
60
+ save_it(
61
+ File.join(d, "#{File.basename(d)}.rb"),
62
62
  '
63
63
  $local[:foo] = 42 if $local[:foo].nil?
64
64
  $local[:foo] = $local[:foo] + 1
@@ -77,8 +77,7 @@ class TestJudge < Minitest::Test
77
77
  Dir.mktmpdir do |d|
78
78
  j = 'this_is_it'
79
79
  dir = File.join(d, j)
80
- FileUtils.mkdir(dir)
81
- File.write(File.join(dir, 'foo.rb'), '$loog.info("judge=" + $judge)')
80
+ save_it(File.join(dir, "#{j}.rb"), '$loog.info("judge=" + $judge)')
82
81
  log = Loog::Buffer.new
83
82
  Judges::Judge.new(dir, nil, log).run(Factbase.new, {}, {}, {})
84
83
  assert(log.to_s.include?("judge=#{j}"))
@@ -89,8 +88,7 @@ class TestJudge < Minitest::Test
89
88
  assert_raises do
90
89
  Dir.mktmpdir do |d|
91
90
  dir = File.join(d, 'judges')
92
- FileUtils.mkdir_p(dir)
93
- File.write(File.join(dir, 'x.rb'), 'this$is$broken$syntax')
91
+ save_it(File.join(dir, "#{File.basename(d)}.rb"), 'this$is$broken$syntax')
94
92
  judge = Judges::Judge.new(dir, lib, Loog::NULL)
95
93
  judge.run(Factbase.new, {}, {}, {})
96
94
  end
@@ -101,8 +99,7 @@ class TestJudge < Minitest::Test
101
99
  assert_raises do
102
100
  Dir.mktmpdir do |d|
103
101
  dir = File.join(d, 'judges')
104
- FileUtils.mkdir_p(dir)
105
- File.write(File.join(dir, 'x.rb'), 'a < 1')
102
+ save_it(File.join(dir, "#{File.basename(d)}.rb"), 'a < 1')
106
103
  judge = Judges::Judge.new(dir, lib, Loog::NULL)
107
104
  judge.run(Factbase.new, {}, {}, {})
108
105
  end
data/test/test_judges.rb CHANGED
@@ -33,8 +33,9 @@ require_relative '../lib/judges/judges'
33
33
  class TestJudges < Minitest::Test
34
34
  def test_basic
35
35
  Dir.mktmpdir do |d|
36
- File.write(File.join(d, 'foo.rb'), 'hey')
37
- File.write(File.join(d, 'something.yml'), "---\nfoo: 42")
36
+ dir = File.join(d, 'foo')
37
+ save_it(File.join(dir, 'foo.rb'), 'hey')
38
+ save_it(File.join(dir, 'something.yml'), "---\nfoo: 42")
38
39
  found = 0
39
40
  Judges::Judges.new(d, nil, Loog::NULL).each do |p|
40
41
  assert_equal('foo.rb', p.script)
@@ -47,11 +48,32 @@ class TestJudges < Minitest::Test
47
48
 
48
49
  def test_get_one
49
50
  Dir.mktmpdir do |d|
50
- f = File.join(d, 'boo/foo.rb')
51
- FileUtils.mkdir_p(File.dirname(f))
52
- File.write(f, 'hey')
51
+ save_it(File.join(d, 'boo/boo.rb'), 'hey')
53
52
  j = Judges::Judges.new(d, nil, Loog::NULL).get('boo')
54
- assert_equal('foo.rb', j.script)
53
+ assert_equal('boo.rb', j.script)
54
+ end
55
+ end
56
+
57
+ def test_list_only_direct_subdirs
58
+ Dir.mktmpdir do |d|
59
+ save_it(File.join(d, 'first/first.rb'), '')
60
+ save_it(File.join(d, 'second/second.rb'), '')
61
+ save_it(File.join(d, 'second/just-file.rb'), '')
62
+ save_it(File.join(d, 'wrong.rb'), '')
63
+ save_it(File.join(d, 'another/wrong/wrong.rb'), '')
64
+ save_it(File.join(d, 'bad/hello.rb'), '')
65
+ list = Judges::Judges.new(d, nil, Loog::NULL).each.to_a
66
+ assert_equal(2, list.size)
67
+ end
68
+ end
69
+
70
+ def test_list_with_empty_dir
71
+ Dir.mktmpdir do |d|
72
+ save_it(File.join(d, 'wrong.rb'), '')
73
+ save_it(File.join(d, 'another/wrong/wrong.rb'), '')
74
+ save_it(File.join(d, 'bad/hello.rb'), '')
75
+ list = Judges::Judges.new(d, nil, Loog::NULL).each.to_a
76
+ assert(list.empty?)
55
77
  end
56
78
  end
57
79
  end
data/test/test_options.rb CHANGED
@@ -81,7 +81,7 @@ class TestOptions < Minitest::Test
81
81
  opts = Judges::Options.new('foo' => 44, 'bar' => 'long-string-maybe-secret')
82
82
  s = opts.to_s
83
83
  assert(s.include?('FOO → "44"'), s)
84
- assert(s.include?('"long********************"'))
84
+ assert(s.include?('"long****************cret"'), s)
85
85
  end
86
86
 
87
87
  def test_merge
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.20.0
4
+ version: 0.21.0
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-07-22 00:00:00.000000000 Z
11
+ date: 2024-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace