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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
-----------------------------------------------------------------------
--- Stuff to do with multiple-source-file tests. We assume ---
--- that the name of the test is to be used as the basename ---
--- for everything. ---
-----------------------------------------------------------------------
-- global variables:
$stdin = ""
$expect = "pass"
$normalise_errmsg = False
$normalise_output = False
---------------------------------------------------------------
--- UTILITY FNs ---
---------------------------------------------------------------
include ($confdir ++ "/" ++ $conffilename)
include ($confdir ++ "/../std-macros.T")
-- (eg) "fooble" --> "testdir/fooble"
def testdirify ( $basename )
{
return $testdir ++ "/" ++ $basename
}
---------------------------------------------------------------
--- COMPILATION ---
---------------------------------------------------------------
-- Clean up prior to the test, so that we can't spuriously conclude
-- that it passed on the basis of old run outputs.
def pretest_cleanup()
{
rm_nofail(qualify("comp.stderr"))
rm_nofail(qualify("run.stderr"))
rm_nofail(qualify("run.stdout"))
-- simple_build_Main zaps the following:
-- objects
-- executable
-- not interested in the return code
}
-- Guess flags suitable for the compiler.
def guess_compiler_flags()
{
if $tool contains "ghc"
then
return "-no-recomp --make -dcore-lint" ++
" -i" ++ $testdir
else
-- Problem here is that nhc and hbc don't understand --make,
-- and we rely on it.
-- if $tool contains "nhc"
-- then
-- return "-an-nhc-specific-flag"
-- else
-- if $tool contains "hbc"
-- then
-- return ""
-- else
framefail ("Can't guess what kind of Haskell compiler " ++
"you're testing: $tool = " ++ $tool)
-- fi
-- fi
fi
}
-- Build Main, and return the compiler result code. Compilation
-- output goes into testname.comp.stderr. Source is assumed to
-- be in Main.hs or Main.lhs, and modules reachable from it.
def simple_build_prog_WRK ( $_main, $_extra_args )
{
$flags = guess_compiler_flags()
$errname = qualify("comp.stderr")
$exename = qualify("") -- ie, the exe name == the test name
rm_or_fail($errname)
rm_or_fail($exename)
rm_nofail(testdirify("*.o"))
$cmd = $tool ++ " " ++ $flags ++ " " ++ $_extra_args ++ " "
++ (if defined $extra_hc_flags
then $extra_hc_flags
else "")
++ " -o " ++ $exename ++ " "
++ $_main ++ " >" ++ $errname ++ " 2>&1"
$res = run $cmd
return $res
}
---------------------------------------------------------------
--- CONDUCTING A COMPLETE TEST ---
---------------------------------------------------------------
-- Compile and run (should_run) style test
def multimod-compile( $mod, $extra_compile_args )
{
pretest_cleanup()
$main = if $mod == "" then "Main" else $mod
$res = simple_build_prog_WRK( $main, $extra_compile_args )
if $res /= "0" then
say_fail_because_compiler_barfd ( $res )
return False
else
return True
fi
}
def multimod-run-test ( $extra_run_args,
$allowable_nonzero_exit_code )
{
$exit_code =
if $allowable_nonzero_exit_code /= "" then
$allowable_nonzero_exit_code
else "0"
return simple_run_pgm( $extra_run_args, $exit_code )
}
---------------------------------------------------------------
--- TOP-LEVEL FNS ---
---------------------------------------------------------------
--------------------------------------------------------------
-- top-level
-- Compile and run (should_run) style test
def mtc ( $mod, $extra_compile_args )
{
$test_passed = multimod-compile( $mod, $extra_compile_args )
if ($expect == "pass") then
expect pass
else
expect fail
fi
pass when $test_passed
fail when otherwise
}
def mtr ( $extra_compile_args,
$extra_run_args,
$allowable_nonzero_exit_code )
{
$test_passed
= multimod-compile( "Main", $extra_compile_args )
&& multimod-run-test( $extra_run_args,
$allowable_nonzero_exit_code )
if ($expect == "pass") then
expect pass
else
expect fail
fi
pass when $test_passed
fail when otherwise
}
-----------------------------------------------------------------------
--- end multimod-test.T ---
-----------------------------------------------------------------------
|