-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtester.cr
74 lines (64 loc) · 1.63 KB
/
tester.cr
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
class Tester
DEBUG = true
TESTS_DIR = "tests"
SCANNER_TESTS_DIR = "#{TESTS_DIR}/scanner"
PARSER_TESTS_DIR = "#{TESTS_DIR}/parser"
def initialize
@tests_count, @fail_tests_count, @success_tests_count = 0, 0, 0
@debug_info = ""
end
def run
build_compiler
scanner_tests
parser_tests
print_info
rescue ex : Exception
puts ex.message
end
private def run_tests(range, directory)
(range).each do |i|
file_name = i < 10 ? "0#{i}" : i
in_file = "#{directory}/#{file_name}.in"
out_file = "#{directory}/#{file_name}.out"
if File.exists?(in_file)
output = yield in_file
true_output = File.read(out_file)
if output == true_output
print '.'
@success_tests_count += 1
else
print 'E'
@fail_tests_count += 1
debug { @debug_info += "\nin file #{out_file}:\nget:\n#{output}\n\nexpected:\n#{true_output}\n" }
end
@tests_count += 1
else
break
end
end
end
private def parser_tests
run_tests 1..30, PARSER_TESTS_DIR do |file|
`./simple-compiler -p #{file}`
end
end
private def scanner_tests
run_tests 1..60, SCANNER_TESTS_DIR do |file|
`./simple-compiler -s #{file}`
end
end
private def print_info
print @debug_info
print "\nTests: #{@tests_count}\t success: #{@success_tests_count}\t fails: #{@fail_tests_count}\n"
end
private def debug
yield if DEBUG
end
private def build_compiler
build_info = `crystal build simple-compiler.cr`
if build_info != ""
raise Exception.new build_info
end
end
end
Tester.new.run