judges 0.53.6 → 0.53.7
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/Gemfile.lock +20 -20
- data/features/test.feature +2 -2
- data/judges.gemspec +2 -2
- data/lib/judges/commands/push.rb +3 -3
- data/lib/judges.rb +1 -1
- metadata +1 -39
- data/.0pdd.yml +0 -8
- data/.gitattributes +0 -7
- data/.github/workflows/actionlint.yml +0 -25
- data/.github/workflows/codecov.yml +0 -27
- data/.github/workflows/copyrights.yml +0 -19
- data/.github/workflows/eslint.yml +0 -20
- data/.github/workflows/markdown-lint.yml +0 -23
- data/.github/workflows/pdd.yml +0 -19
- data/.github/workflows/rake.yml +0 -28
- data/.github/workflows/reuse.yml +0 -19
- data/.github/workflows/typos.yml +0 -19
- data/.github/workflows/xcop.yml +0 -19
- data/.github/workflows/yamllint.yml +0 -19
- data/.gitignore +0 -12
- data/.pdd +0 -7
- data/.rubocop.yml +0 -53
- data/.rultor.yml +0 -37
- data/renovate.json +0 -6
- data/test/commands/test_download.rb +0 -127
- data/test/commands/test_eval.rb +0 -28
- data/test/commands/test_import.rb +0 -40
- data/test/commands/test_inspect.rb +0 -44
- data/test/commands/test_join.rb +0 -38
- data/test/commands/test_print.rb +0 -146
- data/test/commands/test_pull.rb +0 -77
- data/test/commands/test_push.rb +0 -79
- data/test/commands/test_test.rb +0 -217
- data/test/commands/test_trim.rb +0 -31
- data/test/commands/test_update.rb +0 -282
- data/test/commands/test_upload.rb +0 -119
- data/test/test__helper.rb +0 -45
- data/test/test_bin.rb +0 -26
- data/test/test_categories.rb +0 -33
- data/test/test_impex.rb +0 -35
- data/test/test_judge.rb +0 -114
- data/test/test_judges.rb +0 -137
- data/test/test_options.rb +0 -88
- data/test/test_to_rel.rb +0 -24
data/test/commands/test_test.rb
DELETED
@@ -1,217 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
-
# SPDX-License-Identifier: MIT
|
5
|
-
|
6
|
-
require 'loog'
|
7
|
-
require_relative '../../lib/judges'
|
8
|
-
require_relative '../../lib/judges/commands/test'
|
9
|
-
require_relative '../test__helper'
|
10
|
-
|
11
|
-
# Test.
|
12
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
13
|
-
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
14
|
-
# License:: MIT
|
15
|
-
class TestTest < Minitest::Test
|
16
|
-
def test_positive
|
17
|
-
Dir.mktmpdir do |d|
|
18
|
-
save_it(File.join(d, 'foo/foo.rb'), '$fb.query("(eq foo 42)").each { |f| f.bar = 4 }')
|
19
|
-
save_it(
|
20
|
-
File.join(d, 'foo/something.yml'),
|
21
|
-
<<-YAML
|
22
|
-
input:
|
23
|
-
-
|
24
|
-
foo: 42
|
25
|
-
expected:
|
26
|
-
- /fb[count(f)=1]
|
27
|
-
- /fb/f[foo='42']
|
28
|
-
- /fb/f[bar='4']
|
29
|
-
YAML
|
30
|
-
)
|
31
|
-
Judges::Test.new(Loog::NULL).run({}, [d])
|
32
|
-
assert_path_exists(d)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_negative
|
37
|
-
Dir.mktmpdir do |d|
|
38
|
-
save_it(File.join(d, 'foo/foo.rb'), '$fb.query("(eq foo 42)").each { |f| f.bar = 4 }')
|
39
|
-
save_it(
|
40
|
-
File.join(d, 'foo/something.yml'),
|
41
|
-
<<-YAML
|
42
|
-
input:
|
43
|
-
-
|
44
|
-
foo: 42
|
45
|
-
expected:
|
46
|
-
- /fb[count(f)=1]
|
47
|
-
- /fb/f[foo/v='42']
|
48
|
-
- /fb/f[bar/v='5']
|
49
|
-
YAML
|
50
|
-
)
|
51
|
-
assert_raises(StandardError) do
|
52
|
-
Judges::Test.new(Loog::NULL).run({}, [d])
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_with_options
|
58
|
-
Dir.mktmpdir do |d|
|
59
|
-
save_it(File.join(d, 'foo/foo.rb'), '$fb.insert.foo = $options.bar')
|
60
|
-
save_it(
|
61
|
-
File.join(d, 'foo/something.yml'),
|
62
|
-
<<-YAML
|
63
|
-
input: []
|
64
|
-
options:
|
65
|
-
bar: 42
|
66
|
-
expected:
|
67
|
-
- /fb[count(f)=1]
|
68
|
-
- /fb/f[foo='42']
|
69
|
-
YAML
|
70
|
-
)
|
71
|
-
Judges::Test.new(Loog::NULL).run({}, [d])
|
72
|
-
assert_path_exists(d)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_with_before
|
77
|
-
Dir.mktmpdir do |d|
|
78
|
-
save_it(File.join(d, 'first/first.rb'), 'x = $fb.size; $fb.insert.foo = x')
|
79
|
-
save_it(File.join(d, 'second/second.rb'), '$fb.insert.bar = 55')
|
80
|
-
save_it(
|
81
|
-
File.join(d, 'second/something.yml'),
|
82
|
-
<<-YAML
|
83
|
-
input:
|
84
|
-
-
|
85
|
-
hi: 42
|
86
|
-
before:
|
87
|
-
- first
|
88
|
-
expected:
|
89
|
-
- /fb[count(f)=3]
|
90
|
-
- /fb/f[hi=42]
|
91
|
-
- /fb/f[foo=1]
|
92
|
-
- /fb/f[bar=55]
|
93
|
-
YAML
|
94
|
-
)
|
95
|
-
Judges::Test.new(Loog::NULL).run({}, [d])
|
96
|
-
assert_path_exists(d)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_one_judge_negative
|
101
|
-
Dir.mktmpdir do |d|
|
102
|
-
save_it(File.join(d, 'foo/foo.rb'), '')
|
103
|
-
save_it(
|
104
|
-
File.join(d, 'foo/x.yml'),
|
105
|
-
<<-YAML
|
106
|
-
input: []
|
107
|
-
expected:
|
108
|
-
- /fb[count(f)=1]
|
109
|
-
YAML
|
110
|
-
)
|
111
|
-
assert_raises(StandardError) do
|
112
|
-
Judges::Test.new(Loog::NULL).run({ 'judge' => [File.basename(dir)] }, [d])
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_with_after_assertion
|
118
|
-
Dir.mktmpdir do |d|
|
119
|
-
save_it(File.join(d, 'foo/foo.rb'), '$fb.insert.foo = 42;')
|
120
|
-
save_it(File.join(d, 'foo/assert.rb'), 'raise unless $fb.size == 1')
|
121
|
-
save_it(
|
122
|
-
File.join(d, 'foo/x.yml'),
|
123
|
-
<<-YAML
|
124
|
-
input: []
|
125
|
-
after:
|
126
|
-
- assert.rb
|
127
|
-
YAML
|
128
|
-
)
|
129
|
-
Judges::Test.new(Loog::NULL).run({}, [d])
|
130
|
-
assert_path_exists(d)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
def test_with_expected_failure
|
135
|
-
Dir.mktmpdir do |d|
|
136
|
-
save_it(File.join(d, 'foo/foo.rb'), 'raise "this is intentional";')
|
137
|
-
save_it(
|
138
|
-
File.join(d, 'foo/x.yml'),
|
139
|
-
<<-YAML
|
140
|
-
input: []
|
141
|
-
expected_failure:
|
142
|
-
- intentional
|
143
|
-
YAML
|
144
|
-
)
|
145
|
-
Judges::Test.new(Loog::NULL).run({}, [d])
|
146
|
-
assert_path_exists(d)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
def test_with_expected_failure_no_string
|
151
|
-
Dir.mktmpdir do |d|
|
152
|
-
save_it(File.join(d, 'foo/foo.rb'), 'raise "this is intentional";')
|
153
|
-
save_it(
|
154
|
-
File.join(d, 'foo/x.yml'),
|
155
|
-
<<-YAML
|
156
|
-
input: []
|
157
|
-
expected_failure: true
|
158
|
-
YAML
|
159
|
-
)
|
160
|
-
Judges::Test.new(Loog::NULL).run({}, [d])
|
161
|
-
assert_path_exists(d)
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
def test_with_timeout_success
|
166
|
-
Dir.mktmpdir do |d|
|
167
|
-
save_it(File.join(d, 'foo/foo.rb'), '$fb.insert.foo = 42')
|
168
|
-
save_it(
|
169
|
-
File.join(d, 'foo/x.yml'),
|
170
|
-
<<-YAML
|
171
|
-
input: []
|
172
|
-
timeout: 5
|
173
|
-
expected:
|
174
|
-
- /fb[count(f)=1]
|
175
|
-
- /fb/f[foo='42']
|
176
|
-
YAML
|
177
|
-
)
|
178
|
-
Judges::Test.new(Loog::NULL).run({}, [d])
|
179
|
-
assert_path_exists(d)
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
def test_with_timeout_failure
|
184
|
-
Dir.mktmpdir do |d|
|
185
|
-
save_it(File.join(d, 'foo/foo.rb'), 'sleep(10)')
|
186
|
-
save_it(
|
187
|
-
File.join(d, 'foo/x.yml'),
|
188
|
-
<<-YAML
|
189
|
-
input: []
|
190
|
-
timeout: 1
|
191
|
-
YAML
|
192
|
-
)
|
193
|
-
assert_raises(StandardError) do
|
194
|
-
Judges::Test.new(Loog::NULL).run({}, [d])
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
def test_with_timeout_in_after_script
|
200
|
-
Dir.mktmpdir do |d|
|
201
|
-
save_it(File.join(d, 'foo/foo.rb'), '$fb.insert.foo = 42')
|
202
|
-
save_it(File.join(d, 'foo/assert.rb'), 'sleep(10)')
|
203
|
-
save_it(
|
204
|
-
File.join(d, 'foo/x.yml'),
|
205
|
-
<<-YAML
|
206
|
-
input: []
|
207
|
-
timeout: 1
|
208
|
-
after:
|
209
|
-
- assert.rb
|
210
|
-
YAML
|
211
|
-
)
|
212
|
-
assert_raises(StandardError) do
|
213
|
-
Judges::Test.new(Loog::NULL).run({}, [d])
|
214
|
-
end
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|
data/test/commands/test_trim.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
-
# SPDX-License-Identifier: MIT
|
5
|
-
|
6
|
-
require 'loog'
|
7
|
-
require 'nokogiri'
|
8
|
-
require 'time'
|
9
|
-
require_relative '../../lib/judges'
|
10
|
-
require_relative '../../lib/judges/commands/trim'
|
11
|
-
require_relative '../test__helper'
|
12
|
-
|
13
|
-
# Test.
|
14
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
15
|
-
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
16
|
-
# License:: MIT
|
17
|
-
class TestTrim < Minitest::Test
|
18
|
-
def test_trims_factbase
|
19
|
-
Dir.mktmpdir do |d|
|
20
|
-
file = File.join(d, 'base.fb')
|
21
|
-
before = Factbase.new
|
22
|
-
before.insert.time = Time.now + 1
|
23
|
-
before.insert.time = Time.now - (100 * 24 * 60 * 60)
|
24
|
-
File.binwrite(file, before.export)
|
25
|
-
Judges::Trim.new(Loog::NULL).run({ 'query' => "(lt time #{Time.now.utc.iso8601})" }, [file])
|
26
|
-
after = Factbase.new
|
27
|
-
after.import(File.binread(file))
|
28
|
-
assert_equal(1, after.size)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,282 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
-
# SPDX-License-Identifier: MIT
|
5
|
-
|
6
|
-
require 'loog'
|
7
|
-
require 'loog/tee'
|
8
|
-
require 'nokogiri'
|
9
|
-
require 'factbase/to_xml'
|
10
|
-
require_relative '../test__helper'
|
11
|
-
require_relative '../../lib/judges'
|
12
|
-
require_relative '../../lib/judges/commands/update'
|
13
|
-
|
14
|
-
# Test.
|
15
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
16
|
-
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
17
|
-
# License:: MIT
|
18
|
-
class TestUpdate < Minitest::Test
|
19
|
-
def test_build_factbase_from_scratch
|
20
|
-
Dir.mktmpdir do |d|
|
21
|
-
save_it(File.join(d, 'foo/foo.rb'), 'return if $fb.size > 2; $fb.insert.zzz = $options.foo_bar + 1')
|
22
|
-
file = File.join(d, 'base.fb')
|
23
|
-
Judges::Update.new(Loog::NULL).run({ 'option' => ['foo_bar=42'] }, [d, file])
|
24
|
-
fb = Factbase.new
|
25
|
-
fb.import(File.binread(file))
|
26
|
-
xml = Nokogiri::XML.parse(Factbase::ToXML.new(fb).xml)
|
27
|
-
refute_empty(xml.xpath('/fb/f[zzz="43"]'), xml)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_with_only_one_judge
|
32
|
-
Dir.mktmpdir do |d|
|
33
|
-
save_it(File.join(d, 'foo/foo.rb'), 'return if $fb.size > 2; $fb.insert')
|
34
|
-
save_it(File.join(d, 'bar/bar.rb'), '-&- bug here -&-')
|
35
|
-
file = File.join(d, 'base.fb')
|
36
|
-
Judges::Update.new(Loog::NULL).run({ 'judge' => ['foo'] }, [d, file])
|
37
|
-
assert_path_exists(file)
|
38
|
-
assert_raises(StandardError) { Judges::Update.new(Loog::NULL).run({}, [d, file]) }
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_cancels_slow_execution
|
43
|
-
Dir.mktmpdir do |d|
|
44
|
-
100.times do |i|
|
45
|
-
save_it(File.join(d, "foo-#{i}/foo-#{i}.rb"), '$fb.insert.foo = 0.05; sleep 2;')
|
46
|
-
end
|
47
|
-
file = File.join(d, 'base.fb')
|
48
|
-
Judges::Update.new(Loog::NULL).run({ 'lifetime' => 0.12, 'timeout' => 0.1, 'quiet' => true }, [d, file])
|
49
|
-
fb = Factbase.new
|
50
|
-
fb.import(File.binread(file))
|
51
|
-
xml = Nokogiri::XML.parse(Factbase::ToXML.new(fb).xml)
|
52
|
-
refute_empty(xml.xpath('/fb/f[foo]'), xml)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_cancels_slow_judge
|
57
|
-
Dir.mktmpdir do |d|
|
58
|
-
save_it(File.join(d, 'foo/foo.rb'), 'sleep 10; $fb.insert.foo = 1')
|
59
|
-
file = File.join(d, 'base.fb')
|
60
|
-
Judges::Update.new(Loog::NULL).run({ 'timeout' => 0.1, 'quiet' => true }, [d, file])
|
61
|
-
fb = Factbase.new
|
62
|
-
fb.import(File.binread(file))
|
63
|
-
xml = Nokogiri::XML.parse(Factbase::ToXML.new(fb).xml)
|
64
|
-
assert_empty(xml.xpath('/fb/f'), xml)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_accepts_changes_from_slow_judge
|
69
|
-
Dir.mktmpdir do |d|
|
70
|
-
save_it(File.join(d, 'foo/foo.rb'), '$fb.insert.foo = 1; sleep 10')
|
71
|
-
file = File.join(d, 'base.fb')
|
72
|
-
Judges::Update.new(Loog::NULL).run(
|
73
|
-
{ 'timeout' => 0.1, 'quiet' => true, 'fail-fast' => true },
|
74
|
-
[d, file]
|
75
|
-
)
|
76
|
-
fb = Factbase.new
|
77
|
-
fb.import(File.binread(file))
|
78
|
-
xml = Nokogiri::XML.parse(Factbase::ToXML.new(fb).xml)
|
79
|
-
refute_empty(xml.xpath('/fb/f[foo]'), xml)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_reports_changes_from_slow_judge
|
84
|
-
Dir.mktmpdir do |d|
|
85
|
-
save_it(File.join(d, 'foo/foo.rb'), '$fb.insert.foo = 1; sleep 10')
|
86
|
-
file = File.join(d, 'base.fb')
|
87
|
-
log = Loog::Buffer.new
|
88
|
-
Judges::Update.new(Loog::Tee.new(log, Loog::NULL)).run(
|
89
|
-
{ 'timeout' => 0.1, 'quiet' => true, 'fail-fast' => true },
|
90
|
-
[d, file]
|
91
|
-
)
|
92
|
-
assert_includes(log.to_s, 'did 1i/0d/1a')
|
93
|
-
assert_includes(log.to_s, 'Update completed in 1 cycle(s), did 1i/0d/1a')
|
94
|
-
fb = Factbase.new
|
95
|
-
fb.import(File.binread(file))
|
96
|
-
xml = Nokogiri::XML.parse(Factbase::ToXML.new(fb).xml)
|
97
|
-
refute_empty(xml.xpath('/fb/f[foo]'), xml)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_extend_existing_factbase
|
102
|
-
Dir.mktmpdir do |d|
|
103
|
-
file = File.join(d, 'base.fb')
|
104
|
-
fb = Factbase.new
|
105
|
-
fb.insert.foo_bar = 42
|
106
|
-
File.binwrite(file, fb.export)
|
107
|
-
save_it(File.join(d, 'foo/foo.rb'), '$fb.insert.tt = 4')
|
108
|
-
Judges::Update.new(Loog::NULL).run({ 'max-cycles' => 1 }, [d, file])
|
109
|
-
fb = Factbase.new
|
110
|
-
fb.import(File.binread(file))
|
111
|
-
xml = Nokogiri::XML.parse(Factbase::ToXML.new(fb).xml)
|
112
|
-
refute_empty(xml.xpath('/fb/f[tt="4"]'), xml)
|
113
|
-
refute_empty(xml.xpath('/fb/f[foo_bar="42"]'), xml)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_update_with_error
|
118
|
-
Dir.mktmpdir do |d|
|
119
|
-
save_it(File.join(d, 'foo/foo.rb'), 'this$is$a$broken$Ruby$script')
|
120
|
-
file = File.join(d, 'base.fb')
|
121
|
-
Judges::Update.new(Loog::NULL).run({ 'quiet' => true, 'max-cycles' => 2 }, [d, file])
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
def test_update_with_options_in_file
|
126
|
-
Dir.mktmpdir do |d|
|
127
|
-
save_it(File.join(d, 'foo/foo.rb'), '$fb.insert.foo = $options.bar')
|
128
|
-
file = File.join(d, 'base.fb')
|
129
|
-
opts = File.join(d, 'opts.txt')
|
130
|
-
save_it(opts, " bar = helloo \n bar = 444\n\n")
|
131
|
-
Judges::Update.new(Loog::NULL).run({ 'quiet' => true, 'max-cycles' => 1, 'options-file' => opts }, [d, file])
|
132
|
-
fb = Factbase.new
|
133
|
-
fb.import(File.binread(file))
|
134
|
-
xml = Nokogiri::XML.parse(Factbase::ToXML.new(fb).xml)
|
135
|
-
refute_empty(xml.xpath('/fb/f[foo="444"]'), xml)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
def test_terminates_on_lifetime
|
140
|
-
Dir.mktmpdir do |d|
|
141
|
-
save_it(File.join(d, 'foo/foo.rb'), 'sleep 999')
|
142
|
-
file = File.join(d, 'base.fb')
|
143
|
-
log = Loog::Buffer.new
|
144
|
-
assert_raises(StandardError) do
|
145
|
-
Judges::Update.new(Loog::Tee.new(log, Loog::NULL)).run({ 'lifetime' => 0.1 }, [d, file])
|
146
|
-
end
|
147
|
-
assert_includes(log.to_s, 'execution expired')
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
def test_passes_timeout_and_lifetime_through
|
152
|
-
%w[lifetime timeout].each do |o|
|
153
|
-
Dir.mktmpdir do |d|
|
154
|
-
save_it(File.join(d, 'foo/foo.rb'), "$loog.info '#{o}=' + $options.#{o}.to_s")
|
155
|
-
file = File.join(d, 'base.fb')
|
156
|
-
log = Loog::Buffer.new
|
157
|
-
Judges::Update.new(Loog::Tee.new(log, Loog::NULL)).run({ o => 666 }, [d, file])
|
158
|
-
assert_includes(log.to_s, "#{o}=666")
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
def test_update_with_error_no_quiet
|
164
|
-
assert_raises(StandardError) do
|
165
|
-
Dir.mktmpdir do |d|
|
166
|
-
save_it(File.join(d, 'foo/foo.rb'), 'a < 1')
|
167
|
-
file = File.join(d, 'base.fb')
|
168
|
-
Judges::Update.new(Loog::NULL).run({ 'quiet' => false }, [d, file])
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
def test_update_with_error_and_summary
|
174
|
-
Dir.mktmpdir do |d|
|
175
|
-
save_it(File.join(d, 'foo/foo.rb'), 'this$is$a$broken$Ruby$script')
|
176
|
-
file = File.join(d, 'base.fb')
|
177
|
-
2.times do
|
178
|
-
Judges::Update.new(Loog::NULL).run(
|
179
|
-
{ 'quiet' => true, 'summary' => 'add', 'max-cycles' => 2 },
|
180
|
-
[d, file]
|
181
|
-
)
|
182
|
-
end
|
183
|
-
fb = Factbase.new
|
184
|
-
fb.import(File.binread(file))
|
185
|
-
sums = fb.query('(eq what "judges-summary")').each.to_a
|
186
|
-
assert_equal(1, sums.size)
|
187
|
-
sum = sums.first
|
188
|
-
assert_includes(sum.error, 'unexpected global variable', sum.error)
|
189
|
-
refute_nil(sum.seconds)
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
def test_appends_to_existing_summary
|
194
|
-
Dir.mktmpdir do |d|
|
195
|
-
save_it(File.join(d, 'foo/foo.rb'), 'mistake here')
|
196
|
-
file = File.join(d, 'base.fb')
|
197
|
-
fb = Factbase.new
|
198
|
-
fb.insert.then do |f|
|
199
|
-
f.what = 'judges-summary'
|
200
|
-
f.error = 'first'
|
201
|
-
f.error = 'second'
|
202
|
-
end
|
203
|
-
File.binwrite(file, fb.export)
|
204
|
-
Judges::Update.new(Loog::NULL).run(
|
205
|
-
{ 'quiet' => true, 'summary' => 'append', 'max-cycles' => 2 },
|
206
|
-
[d, file]
|
207
|
-
)
|
208
|
-
fb = Factbase.new
|
209
|
-
fb.import(File.binread(file))
|
210
|
-
sums = fb.query('(eq what "judges-summary")').each.to_a
|
211
|
-
assert_equal(1, sums.size)
|
212
|
-
sum = sums.first
|
213
|
-
assert_equal(3, sum['error'].size)
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
def test_fail_fast_stops_cycle
|
218
|
-
Dir.mktmpdir do |d|
|
219
|
-
save_it(File.join(d, 'error/error.rb'), 'invalid$ruby$syntax')
|
220
|
-
save_it(File.join(d, 'valid/valid.rb'), '$fb.insert')
|
221
|
-
file = File.join(d, 'base.fb')
|
222
|
-
Judges::Update.new(Loog::NULL).run(
|
223
|
-
{ 'fail-fast' => true, 'quiet' => true, 'max-cycles' => 3, 'boost' => 'error' },
|
224
|
-
[d, file]
|
225
|
-
)
|
226
|
-
fb = Factbase.new
|
227
|
-
fb.import(File.binread(file))
|
228
|
-
assert_equal(0, fb.size)
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
def test_isolates_churns
|
233
|
-
Dir.mktmpdir do |d|
|
234
|
-
save_it(File.join(d, 'first/first.rb'), '$global[:fb] ||= $fb; 2 + 2')
|
235
|
-
save_it(File.join(d, 'second/second.rb'), '$global[:fb] ||= $fb; $global[:fb].insert')
|
236
|
-
file = File.join(d, 'base.fb')
|
237
|
-
Judges::Update.new(Loog::NULL).run(
|
238
|
-
{ 'max-cycles' => 3, 'boost' => 'first' },
|
239
|
-
[d, file]
|
240
|
-
)
|
241
|
-
fb = Factbase.new
|
242
|
-
fb.import(File.binread(file))
|
243
|
-
assert_equal(3, fb.size)
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
def test_fails_when_no_judges_used
|
248
|
-
assert_raises(StandardError) do
|
249
|
-
Dir.mktmpdir do |d|
|
250
|
-
save_it(File.join(d, 'foo/foo.rb'), '$fb.insert')
|
251
|
-
file = File.join(d, 'base.fb')
|
252
|
-
Judges::Update.new(Loog::NULL).run({ 'judge' => ['nonexistent'], 'expect-judges' => true }, [d, file])
|
253
|
-
end
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
|
-
def test_fails_when_empty_directory
|
258
|
-
assert_raises(StandardError) do
|
259
|
-
Dir.mktmpdir do |d|
|
260
|
-
file = File.join(d, 'base.fb')
|
261
|
-
Judges::Update.new(Loog::NULL).run({ 'expect-judges' => true }, [d, file])
|
262
|
-
end
|
263
|
-
end
|
264
|
-
end
|
265
|
-
|
266
|
-
def test_no_failure_when_expect_judges_false
|
267
|
-
Dir.mktmpdir do |d|
|
268
|
-
file = File.join(d, 'base.fb')
|
269
|
-
Judges::Update.new(Loog::NULL).run({ 'expect-judges' => false }, [d, file])
|
270
|
-
assert_path_exists(file)
|
271
|
-
end
|
272
|
-
end
|
273
|
-
|
274
|
-
def test_no_failure_with_nonexistent_judge_when_expect_judges_false
|
275
|
-
Dir.mktmpdir do |d|
|
276
|
-
save_it(File.join(d, 'foo/foo.rb'), '$fb.insert')
|
277
|
-
file = File.join(d, 'base.fb')
|
278
|
-
Judges::Update.new(Loog::NULL).run({ 'judge' => ['nonexistent'], 'expect-judges' => false }, [d, file])
|
279
|
-
assert_path_exists(file)
|
280
|
-
end
|
281
|
-
end
|
282
|
-
end
|
@@ -1,119 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
-
# SPDX-License-Identifier: MIT
|
5
|
-
|
6
|
-
require 'loog'
|
7
|
-
require 'webmock/minitest'
|
8
|
-
require_relative '../../lib/judges'
|
9
|
-
require_relative '../../lib/judges/commands/upload'
|
10
|
-
require_relative '../test__helper'
|
11
|
-
|
12
|
-
# Test.
|
13
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
14
|
-
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
15
|
-
# License:: MIT
|
16
|
-
class TestUpload < Minitest::Test
|
17
|
-
def test_upload_simple_durable
|
18
|
-
WebMock.disable_net_connect!
|
19
|
-
content = 'Hello, World!'
|
20
|
-
stub_request(:get, 'https://example.org/durables/find?file=upload.txt&jname=myjudge').to_return(
|
21
|
-
status: 404
|
22
|
-
)
|
23
|
-
stub_request(:get, 'https://example.org/csrf').to_return(body: 'test-csrf-token')
|
24
|
-
stub_request(:post, 'https://example.org/durables/place').to_return(
|
25
|
-
status: 302, headers: { 'X-Zerocracy-DurableId' => '42' }
|
26
|
-
)
|
27
|
-
stub_request(:post, %r{https://example.org/durables/42/lock}).to_return(status: 302)
|
28
|
-
stub_request(:put, %r{https://example.org/durables/42}).to_return(status: 200)
|
29
|
-
stub_request(:post, %r{https://example.org/durables/42/unlock}).to_return(status: 302)
|
30
|
-
Dir.mktmpdir do |d|
|
31
|
-
file = File.join(d, 'upload.txt')
|
32
|
-
File.write(file, content)
|
33
|
-
Judges::Upload.new(Loog::NULL).run(
|
34
|
-
{
|
35
|
-
'token' => '000',
|
36
|
-
'host' => 'example.org',
|
37
|
-
'port' => 443,
|
38
|
-
'ssl' => true,
|
39
|
-
'owner' => 'default'
|
40
|
-
},
|
41
|
-
['myjudge', file]
|
42
|
-
)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_upload_with_custom_owner
|
47
|
-
WebMock.disable_net_connect!
|
48
|
-
content = 'Binary data here'
|
49
|
-
stub_request(:get, 'http://example.org/durables/find?file=data.bin&jname=judge1').to_return(
|
50
|
-
status: 200, body: '123'
|
51
|
-
)
|
52
|
-
stub_request(:get, 'http://example.org/csrf').to_return(body: 'test-csrf-token')
|
53
|
-
stub_request(:post, %r{http://example.org/durables/123/lock}).to_return(status: 302)
|
54
|
-
stub_request(:put, 'http://example.org/durables/123').to_return(status: 200)
|
55
|
-
stub_request(:post, %r{http://example.org/durables/123/unlock}).to_return(status: 302)
|
56
|
-
Dir.mktmpdir do |d|
|
57
|
-
file = File.join(d, 'data.bin')
|
58
|
-
File.write(file, content)
|
59
|
-
Judges::Upload.new(Loog::NULL).run(
|
60
|
-
{
|
61
|
-
'token' => '000',
|
62
|
-
'host' => 'example.org',
|
63
|
-
'port' => 80,
|
64
|
-
'ssl' => false,
|
65
|
-
'owner' => 'custom'
|
66
|
-
},
|
67
|
-
['judge1', file]
|
68
|
-
)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_fails_on_http_error
|
73
|
-
WebMock.disable_net_connect!
|
74
|
-
stub_request(:get, 'http://example.org/durables/find?file=test.txt&jname=somejudge').to_return(
|
75
|
-
status: 404
|
76
|
-
)
|
77
|
-
stub_request(:get, 'http://example.org/csrf').to_return(body: 'test-csrf-token')
|
78
|
-
stub_request(:post, 'http://example.org/durables/place').to_return(status: 500)
|
79
|
-
Dir.mktmpdir do |d|
|
80
|
-
file = File.join(d, 'test.txt')
|
81
|
-
File.write(file, 'content')
|
82
|
-
assert_raises(StandardError) do
|
83
|
-
Judges::Upload.new(Loog::NULL).run(
|
84
|
-
{
|
85
|
-
'token' => '000',
|
86
|
-
'host' => 'example.org',
|
87
|
-
'port' => 80,
|
88
|
-
'ssl' => false,
|
89
|
-
'owner' => 'none'
|
90
|
-
},
|
91
|
-
['somejudge', file]
|
92
|
-
)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_fails_with_wrong_number_of_arguments
|
98
|
-
assert_raises(RuntimeError) do
|
99
|
-
Judges::Upload.new(Loog::NULL).run({}, ['only_one_arg'])
|
100
|
-
end
|
101
|
-
assert_raises(RuntimeError) do
|
102
|
-
Judges::Upload.new(Loog::NULL).run({}, %w[too many args])
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_fails_when_file_does_not_exist
|
107
|
-
assert_raises(RuntimeError) do
|
108
|
-
Judges::Upload.new(Loog::NULL).run(
|
109
|
-
{
|
110
|
-
'token' => '000',
|
111
|
-
'host' => 'example.org',
|
112
|
-
'port' => 80,
|
113
|
-
'ssl' => false
|
114
|
-
},
|
115
|
-
['myjudge', '/nonexistent/file.txt']
|
116
|
-
)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
data/test/test__helper.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
-
# SPDX-License-Identifier: MIT
|
5
|
-
|
6
|
-
$stdout.sync = true
|
7
|
-
|
8
|
-
require 'simplecov'
|
9
|
-
require 'simplecov-cobertura'
|
10
|
-
unless SimpleCov.running || ENV['PICKS']
|
11
|
-
SimpleCov.command_name('test')
|
12
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
|
13
|
-
[
|
14
|
-
SimpleCov::Formatter::HTMLFormatter,
|
15
|
-
SimpleCov::Formatter::CoberturaFormatter
|
16
|
-
]
|
17
|
-
)
|
18
|
-
SimpleCov.minimum_coverage 90
|
19
|
-
SimpleCov.minimum_coverage_by_file 80
|
20
|
-
SimpleCov.start do
|
21
|
-
add_filter 'test/'
|
22
|
-
add_filter 'vendor/'
|
23
|
-
add_filter 'target/'
|
24
|
-
track_files 'lib/**/*.rb'
|
25
|
-
track_files '*.rb'
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
require 'minitest/autorun'
|
30
|
-
require 'minitest/reporters'
|
31
|
-
Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new]
|
32
|
-
|
33
|
-
# To make tests retry on failure:
|
34
|
-
if ENV['RACK_RUN']
|
35
|
-
require 'minitest/retry'
|
36
|
-
Minitest::Retry.use!
|
37
|
-
end
|
38
|
-
|
39
|
-
class Minitest::Test
|
40
|
-
def save_it(file, content)
|
41
|
-
require 'fileutils'
|
42
|
-
FileUtils.mkdir_p(File.dirname(file))
|
43
|
-
File.binwrite(file, content)
|
44
|
-
end
|
45
|
-
end
|