multimod-test.T 4.63 KB
Newer Older
1
2
3
4
5
6
7

-----------------------------------------------------------------------
--- 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.                                                 ---
-----------------------------------------------------------------------

8
9
10
-- global variables:
$stdin = ""
$expect = "pass"
rrt's avatar
rrt committed
11
12
$normalise_errmsg = False
$normalise_output = False
13

14
15
16
17
18
---------------------------------------------------------------
--- UTILITY FNs                                             ---
---------------------------------------------------------------

include ($confdir ++ "/" ++ $conffilename)
19
include ($confdir ++ "/../std-macros.T")
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

-- (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.

76
def simple_build_prog_WRK ( $_main, $_extra_args ) 
77
78
79
80
{
   $flags = guess_compiler_flags()
   $errname = qualify("comp.stderr")
   $exename = qualify("")  -- ie, the exe name == the test name
81

82
83
84
   rm_or_fail($errname)
   rm_or_fail($exename)
   rm_nofail(testdirify("*.o"))
rrt's avatar
rrt committed
85
   $cmd = "\"" ++ $tool ++ "\" " ++ $flags ++ " " ++ $_extra_args ++ " "
86
87
88
	  ++ (if defined $extra_hc_flags
		  then $extra_hc_flags 
		  else "")
89
          ++ " -o " ++ $exename ++ " " 
90
          ++ $_main ++ " >" ++ $errname ++ " 2>&1"
91
92
93
94
95
96
97
98
99
100
101
   $res = run $cmd
   return $res
}


---------------------------------------------------------------
--- CONDUCTING A COMPLETE TEST                              ---
---------------------------------------------------------------

-- Compile and run (should_run) style test

102
def multimod-compile( $mod, $extra_compile_args )
103
104
{
   pretest_cleanup()
105

106
107
108
109
110
   $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 )
111
        return False 
112
113
   else
	return True
114
   fi
115
}
116

117
118
119
def multimod-run-test ( $extra_run_args, 
                        $allowable_nonzero_exit_code )
{
120
121
122
123
124
125
   $exit_code = 
      if $allowable_nonzero_exit_code /= "" then 
	  $allowable_nonzero_exit_code 
      else "0"

   return simple_run_pgm( $extra_run_args, $exit_code )
126
127
128
129
130
131
132
133
134
135
136
}


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

--------------------------------------------------------------
-- top-level
-- Compile and run (should_run) style test

137
138
139
140
141
142
143
144
145
146
147
148
149
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
}

150
151
152
153
154
def mtr ( $extra_compile_args, 
          $extra_run_args, 
          $allowable_nonzero_exit_code )
{
   $test_passed 
155
156
157
158
      = multimod-compile( "Main", $extra_compile_args )
	&& multimod-run-test( $extra_run_args, 
                              $allowable_nonzero_exit_code )

159
160
161
162
163
   if ($expect == "pass") then
      expect pass
   else
      expect fail
   fi
164
165
166
167
168
169
170
171
   pass when $test_passed
   fail when otherwise
}


-----------------------------------------------------------------------
--- end                                             multimod-test.T ---
-----------------------------------------------------------------------