-
Notifications
You must be signed in to change notification settings - Fork 11
/
test.rb
executable file
·96 lines (84 loc) · 2.1 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
#!/usr/bin/env ruby
require './evalify'
$evalify = false
if ARGV[0] == '-e'
$evalify = true
ARGV.shift
elsif ARGV[0] == '-E'
$evalify = true
$eval_test_only = true
ARGV.shift
end
ref_lisp = ARGV[0] || 'purelisp.rb'
test_lisp = ARGV[1]
test_lisp ||= File.exist?('sedlisp.sed') ? 'sedlisp.sed' : 'beflisp.bef'
COMMANDS = {
'purelisp.rb' => ['ruby', 'purelisp.rb'],
'rblisp.rb' => ['ruby', 'rblisp.rb'],
'sedlisp.sed' => ['sed', '-f', 'sedlisp.sed'],
'lisp.bef' => ['./befunge', 'lisp.bef'],
'beflisp.bef' => ['./befunge', 'beflisp.bef'],
'lisp' => ['./lisp'],
'makelisp.mk' => ['make', '-f', 'makelisp.mk'],
'makelisp2.mk' => ['make', '-f', 'makelisp2.mk'],
'out/lisp.bfs' => ['./bfsim.rb', 'out/lisp.bfs'],
'out/lisp.bf' => ['./out/bfopt', 'out/lisp.bf'],
'bflisp.bf' => ['./out/bfopt', 'bflisp.bf'],
}
def getResult(cmd, line)
pipe = IO.popen(cmd, 'r+')
pipe.puts(line)
pipe.close_write
o = pipe.read
if cmd[-1] == 'rblisp.rb' || cmd[-1] =~ /\.bfs?$/
o.gsub!(/^> /, '')
end
o
end
num_tests = 0
fails = []
lines = File.readlines('test.l')
lineno = -1
while line = lines[lineno += 1]
if line.sub(/;.*/, '') =~ /^ *$/
if (/TEST LAMBDA/ =~ line &&
(ref_lisp == 'rblisp.rb' || test_lisp == 'rblisp.rb'))
break
elsif /TEST EVAL/ =~ line
$eval_test = true
if !$evalify
break
end
end
next
end
next if !$eval_test && $eval_test_only
while line =~ /;cont/
line.sub!(/;cont/, '')
line += lines[lineno += 1]
end
line.chomp!
orig = line
if $evalify
line = evalify(line)
end
expected = getResult(COMMANDS[ref_lisp], $eval_test ? line : orig)
expected = expected.lines.to_a[-1].to_s.chomp
output = getResult(COMMANDS[test_lisp], line)
actual = output.lines.to_a[-1].to_s.chomp
if expected == actual
puts "#{orig}: OK (#{expected})"
else
puts "#{orig}: FAIL expected=#{expected} actual=#{actual}"
puts output
fails << orig
end
num_tests += 1
end
if fails.empty?
puts 'PASS'
else
puts "Failed tests:"
puts fails.map{|f|f.inspect}
puts "#{fails.size} / #{num_tests} FAIL"
end