forked from flo-l/sep-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.rb
103 lines (89 loc) · 3.07 KB
/
test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
BINARY = './basic'
TESTCASES = 'testcases/'
def run_test(test_name)
test_basepath = TESTCASES + test_name
input_file_path = test_basepath + '.in'
expected_file_path = test_basepath + '.ref'
output_file_path = test_basepath + '.out'
autosave_ref_path = test_basepath + '.save.ref'
autosave_out_path = test_basepath + '.save.out'
autosave_arg = ""
cmd = "#{BINARY} < #{input_file_path} > #{output_file_path} #{autosave_arg}"
if File.exist? autosave_ref_path
cmd << " -s #{autosave_out_path}"
end
`#{cmd}`
exit_code = $?
if !exit_code.success?
info = [
"Exit code: #{exit_code.inspect}",
"Output: #{`cat #{output_file_path}`}"
].join("\n")
return ["ERROR", info]
end
# autosave check
if File.exist? autosave_ref_path
`cmp -s #{autosave_ref_path} #{autosave_out_path}`
if !$?.success?
diff = `diff -u #{autosave_ref_path} #{autosave_out_path}`
return ["AUTOSAVE_ERROR", diff]
end
end
# output check
`cmp -s #{expected_file_path} #{output_file_path}`
if !$?.success?
diff = `diff -u #{expected_file_path} #{output_file_path}`
["ERROR", diff]
else
valgrind_cmd = 'valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all --error-exitcode=1'
`#{valgrind_cmd} #{cmd} 2>> #{TESTCASES}valgrind.log`
if $?.success?
["OK"]
else
["VALGRIND ERROR", `cat #{TESTCASES}valgrind.log`]
end
end
end
def test_with_args(args, expected)
cmd = [BINARY, args].join(' ')
`#{cmd} < #{TESTCASES}quit.in > /dev/null`
return_code = $?.exitstatus
if return_code != expected
puts "cmd_args ... [ERROR]"
puts "#{cmd} => #{return_code}"
puts "Output: #{`cat #{TESTCASES}quit.out`}"
exit
end
end
# preparation
`touch #{TESTCASES}readonlyautosave.save.out`
`chmod 0444 #{TESTCASES}readonlyautosave.save.out`
`touch unopenable.test`
`chmod -rwx unopenable.test`
# dynamically create no_eof.in because git could have added line ending during
# download and use printf instead of echo -ne because ruby sets POSIXLY_CORRECT
# environment var --> See:
#https://www.gnu.org/software/coreutils/manual/html_node/echo-invocation.html
`printf "quit" > #{TESTCASES}no_eof.in`
# cmd tests
test_with_args "", 0
test_with_args "-s #{TESTCASES}valid.poke", 0
test_with_args "-m #{TESTCASES}valid.poke", 0
test_with_args "-s #{TESTCASES}valid.poke -m #{TESTCASES}valid.poke", 0
test_with_args "-m", 2
test_with_args "-s", 2
test_with_args "-m -s #{TESTCASES}valid.poke", 2
test_with_args "#{TESTCASES}valid.poke", 2
test_with_args "#{TESTCASES}valid.poke -m", 2
test_with_args "-s #{TESTCASES}valid.poke -m", 2
test_with_args "-s #{TESTCASES}valid.poke #{TESTCASES}valid.poke", 2
test_with_args "-s #{TESTCASES}valid.poke -m #{TESTCASES}valid.poke -m", 2
puts "cmd_args ... [OK]"
# run testcases
Dir["#{TESTCASES}*.in"].each do |input_file|
test_name = File.basename(input_file, '.in')
puts "Beginning #{test_name}" #User can see which testcase makes problems if he/she runs into endless loop...
result, info = run_test(test_name)
puts "#{test_name} ... [#{result}]"
puts info.chomp if info && info != ""
end