test/test_judges.rb in judges-0.20.0 vs test/test_judges.rb in judges-0.21.0
- old
+ new
@@ -31,12 +31,13 @@
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
# License:: MIT
class TestJudges < Minitest::Test
def test_basic
Dir.mktmpdir do |d|
- File.write(File.join(d, 'foo.rb'), 'hey')
- File.write(File.join(d, 'something.yml'), "---\nfoo: 42")
+ dir = File.join(d, 'foo')
+ save_it(File.join(dir, 'foo.rb'), 'hey')
+ save_it(File.join(dir, 'something.yml'), "---\nfoo: 42")
found = 0
Judges::Judges.new(d, nil, Loog::NULL).each do |p|
assert_equal('foo.rb', p.script)
found += 1
assert_equal('something.yml', File.basename(p.tests.first))
@@ -45,13 +46,34 @@
end
end
def test_get_one
Dir.mktmpdir do |d|
- f = File.join(d, 'boo/foo.rb')
- FileUtils.mkdir_p(File.dirname(f))
- File.write(f, 'hey')
+ save_it(File.join(d, 'boo/boo.rb'), 'hey')
j = Judges::Judges.new(d, nil, Loog::NULL).get('boo')
- assert_equal('foo.rb', j.script)
+ assert_equal('boo.rb', j.script)
+ end
+ end
+
+ def test_list_only_direct_subdirs
+ Dir.mktmpdir do |d|
+ save_it(File.join(d, 'first/first.rb'), '')
+ save_it(File.join(d, 'second/second.rb'), '')
+ save_it(File.join(d, 'second/just-file.rb'), '')
+ save_it(File.join(d, 'wrong.rb'), '')
+ save_it(File.join(d, 'another/wrong/wrong.rb'), '')
+ save_it(File.join(d, 'bad/hello.rb'), '')
+ list = Judges::Judges.new(d, nil, Loog::NULL).each.to_a
+ assert_equal(2, list.size)
+ end
+ end
+
+ def test_list_with_empty_dir
+ Dir.mktmpdir do |d|
+ save_it(File.join(d, 'wrong.rb'), '')
+ save_it(File.join(d, 'another/wrong/wrong.rb'), '')
+ save_it(File.join(d, 'bad/hello.rb'), '')
+ list = Judges::Judges.new(d, nil, Loog::NULL).each.to_a
+ assert(list.empty?)
end
end
end