vanilla-test.T 7.43 KB
Newer Older
1
2
-----------------------------------------------------------------------
--- Stuff to do with simple single-source-file tests.  We assume    ---
3
--- that the name of the test is to be used as the basename         ---
4
5
6
--- for everything.                                                 ---
-----------------------------------------------------------------------

7
8
-- global variables:
$stdin = ""
9
$expect = "pass"
10

11
12
13
14
15
16
---------------------------------------------------------------
-- Define the following things on the command line:
--
-- $verbose	print command lines
-- $accept	accept any changed output

17
18
19
20
21
---------------------------------------------------------------
--- UTILITY FNs                                             ---
---------------------------------------------------------------

include ($confdir ++ "/" ++ $conffilename)
22
include ($confdir ++ "/../std-macros.T")
23
24
25
26
27

---------------------------------------------------------------
--- COMPILATION                                             ---
---------------------------------------------------------------

28
29
30
31
32
-- Guess flags suitable for the compiler.
def guess_compiler_flags()
{
   if   $tool contains "ghc"
   then 
33
        return "-no-recomp -dcore-lint" 
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
   else 
   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
}

50
51
-- Build Main, and return the compiler result code.  Compilation
-- output goes into testname.comp.stderr.
52

53
def simple_build_Main_WRK ( $_extra_args, $compile_only ) 
54
55
{
   $flags = guess_compiler_flags()
56
57
   $errname = testnameWith("comp.stderr")
   $srcname = testnameWith("hs")
58
   rm_or_fail($errname)
59
60
61
62
   rm_or_fail($testname)

   $cmd = "cd " ++ $testdir ++ " && " ++ 
	  $tool ++ " " ++ $flags ++ " " ++ $_extra_args ++ " "
63
	  ++ (if defined $extra_hc_flags
64
		  then $extra_hc_flags 
65
66
		  else "")
          ++ (if defined $compile_to_hc && $compile_to_hc
67
68
69
		  then " -C "
	     	  else if $compile_only 
                  	then " -c " 
70
                  	else " -o " ++ $testname ++ " ")
71
          ++ $srcname ++ " &> " ++ $errname
72
   $res = runCmd($cmd)
73
74
75
   return $res
}

76
77
78
79
80
81

-- Check that the run.stdout file matches at least one spec'd stdout.
def check_stdout_ok()
{
   $r_stdout  = qualify("run.stdout")
   $s_stdout  = qualify("stdout")
82
83

   if   not ( exists($s_stdout) )
84
85
   then if ((contents $r_stdout) == "")
	   then return True
86
	   else say_fail_because_nonempty($r_stdout)
87
88
		return False
	fi
89
90
   fi

91
   return same($s_stdout, $r_stdout)
92
93
94
95
96
97
98
99
100
}


-- If there's any spec'd stderr files, check that the run.stderr matches it.
-- Check that the run.stdout file matches at least one spec'd stdout.
def check_stderr_ok()
{
   $r_stderr  = qualify("run.stderr")
   $s_stderr  = qualify("stderr")
101
102

   if   not ( exists($s_stderr) )
103
104
   then if ((contents $r_stderr) == "")
	   then return True
105
	   else say_fail_because_nonempty($r_stderr)
106
107
		return False
	fi
108
109
110
   fi

   return same($s_stderr, $r_stderr)
111
112
113
}


114
115
116
117
118
119
---------------------------------------------------------------
--- CONDUCTING A COMPLETE TEST                              ---
---------------------------------------------------------------

-- Compile and run (should_run) style test

120
121
122
def vanilla-run-test-actions ( $extra_compile_args, 
                               $extra_run_args, 
                               $allowable_nonzero_exit_code )
123
124
{
   pretest_cleanup()
125

126
   $res = simple_build_Main_WRK( $extra_compile_args, False )
127
128
129
130
131
132
   -- If the compiler barf'd, fail.
   if   $res /= "0" 
   then say_fail_because_compiler_barfd ( $res )
        return False 
   fi

133
134
135
136
137
138
   $exit_code = 
      if $allowable_nonzero_exit_code /= "" then 
	  $allowable_nonzero_exit_code 
      else "0"

   return simple_run_pgm( $extra_run_args, $exit_code )
139
140
}

141
142

-- Compile only (should_compile) style test.  Deemed to have
143
144
-- succeeded if the compiler returned zero AND (testname.comp.stderr
-- matches testname.stderr, if it exists, or is empty).
145

146
def vanilla-compok-test-actions ( $extra_compile_args )
147
148
149
{
   pretest_cleanup()
   $res = simple_build_Main_WRK ( $extra_compile_args, True )
150
151

   -- If the compiler barf'd, fail.
152
153
154
155
   if   $res /= "0" 
   then say_fail_because_compiler_barfd ( $res )
        return False 
   fi
156

157
158
159
   -- If there's an expected .stderr, presumably containing
   -- warnings, ensure the compiler produced the same.
   $actual_stderr   = qualify("comp.stderr")
160
   $expected_stderr = qualify("stderr")
161
162
163
164
   if   exists($expected_stderr)
   then $stderr_a = normalise_errmsg(contents($actual_stderr))
        $stderr_e = normalise_errmsg(contents($expected_stderr))
        if   $stderr_e /= $stderr_a
165
        then say_fail_because_noteq($expected_stderr, $actual_stderr)
166
             return False
167
        else return True
168
        fi
169
170
171
172
   fi

   -- There's no expected stderr, so just insist that the compiler
   -- produced nothing on stderr.
173
   if   (contents $actual_stderr) /= "" 
174
175
176
   then say_fail_because_nonempty($actual_stderr)
        return False
   fi
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198

   -- Must have succeeded.
   return True
}


-- Compile with expected fail (should_fail) style test.  Deemed to have
-- succeeded if the compiler returned nonzero AND testname.comp.stderr
-- equals testname.stderr.

def vanilla-compfail-test-actions ( $extra_compile_args )
{
   pretest_cleanup()
   $expected_stderr = qualify("stderr")

   -- Sanity check
   if   not(exists($expected_stderr)) 
   then framefail "should_fail: expected .stderr is missing" 
   fi

   $res = simple_build_Main_WRK ( $extra_compile_args, True )

199
200
   $actual_stderr = qualify("comp.stderr")
   $stderr_a = normalise_errmsg(contents($actual_stderr))
201
202
   $stderr_e = normalise_errmsg(contents($expected_stderr))

203
   if   $stderr_e /= $stderr_a
204
205
   then say_fail_because_noteq($expected_stderr, $actual_stderr)
        return False
206
207
208
   fi

   if $res /= "0" && $stderr_e == $stderr_a
209
210
   then
     return True
211
212
   else
     return False
213
214
215
216
217
218
219
220
221
   fi
}


---------------------------------------------------------------
--- TOP-LEVEL FNS                                           ---
---------------------------------------------------------------

--------------------------------------------------------------
222
-- top-level
223
224
-- Compile and run (should_run) style test

225
226
227
def vtr ( $extra_compile_args, 
          $extra_run_args, 
          $allowable_nonzero_exit_code )
228
229
{
   $test_passed 
230
231
232
      = vanilla-run-test-actions ( $extra_compile_args, 
                                   $extra_run_args, 
                                   $allowable_nonzero_exit_code )
233
234
235
236
237
   if ($expect == "pass") then
      expect pass
   else
      expect fail
   fi
238
239
240
   pass when $test_passed
   fail when otherwise
}
241

242
243
244
245
246

-- Compile only (should_compile) style test

def vtc ( $extra_compile_args )
{
247
248
249
250
251
252
253
   $test_passed = vanilla-compok-test-actions ( $extra_compile_args )

   if ($expect == "pass") then
      expect pass
   else
      expect fail
   fi
254
255
256
257
   pass when $test_passed
   fail when otherwise
}

258
259
260

-- Compile only, and expect failure (should_fail) style test

261
def vtcf ( $extra_compile_args )
262
{
263
264
265
266
267
268
269
   $test_passed = vanilla-compfail-test-actions ( $extra_compile_args )

   if ($expect == "pass") then
      expect pass
   else
      expect fail
   fi
270
271
272
273
274
275
   pass when $test_passed
   fail when otherwise
}



276
277
278
-----------------------------------------------------------------------
--- end                                              vanilla-test.T ---
-----------------------------------------------------------------------