Commit 4511bceb authored by simonmar's avatar simonmar
Browse files

[project @ 2001-08-22 13:59:54 by simonmar]

More tidyups and code sharing.
parent 0ae8de2e
......@@ -16,17 +16,6 @@ $expect = "pass"
include ($confdir ++ "/" ++ $conffilename)
include ($confdir ++ "/../std-macros.T")
-- (eg) "run.stdout" --> "testdir/testname.run.stdout"
def qualify ( $_filename_frag )
{
if $_filename_frag == ""
then
return $testdir ++ "/" ++ $testname
else
return $testdir ++ "/" ++ $testname ++ "." ++ $_filename_frag
fi
}
-- (eg) "fooble" --> "testdir/fooble"
def testdirify ( $basename )
{
......@@ -109,51 +98,6 @@ def simple_build_Main_WRK ( $_extra_args )
--- RUNNING, AND ASSESSING RUN RESULTS ---
---------------------------------------------------------------
-- Run testname. If testname.stdin exists, route input from that, else
-- from /dev/null. Route output to testname.run.stdout and
-- testname.run.stderr. Returns the exit code of the run.
def simple_run_main( $_extra_args )
{
-- figure out what to use for stdin
$devnull = "/dev/null"
if $stdin == "" then
$stdin = qualify("stdin")
fi
$use_stdin = if exists($stdin) then $stdin else $devnull
$run_stdout = qualify("run.stdout")
$run_stderr = qualify("run.stderr")
rm_or_fail($run_stdout)
rm_or_fail($run_stderr)
$cmd = qualify("")
++ " " ++ $_extra_args
++ " < " ++ $use_stdin
++ " > " ++ $run_stdout
++ " 2> " ++ $run_stderr
$res = runCmd($cmd)
return $res
}
-- returns True if both files exist and are identical.
def same ( $_file1, $_file2 )
{
if defined $verbose
then print "vanilla-test: comparing " ++ $_file1
++ " and " ++ $_file2
fi
$cts1 = contents($_file1)
$cts2 = contents($_file2)
$same = $cts1 == $cts2
if not($same) then
say_fail_because_noteq($_file1, $_file2)
fi
return $same
}
-- Check that the run.stdout file matches at least one spec'd stdout.
def check_stdout_ok()
{
......@@ -208,14 +152,12 @@ def multimod-run-test-actions ( $extra_compile_args,
return False
fi
$res = simple_run_main( $extra_run_args )
if $res /= "0" && $res /= $allowable_nonzero_exit_code
then print "multimod-test: unexpected exit code (" ++ $res
++ ") from testee"
return False
fi
$test_passed = check_stdout_ok() && check_stderr_ok()
return $test_passed
$exit_code =
if $allowable_nonzero_exit_code /= "" then
$allowable_nonzero_exit_code
else "0"
return simple_run_pgm( $extra_run_args, $exit_code )
}
......
$diff = "diff -c2"
$rm = "rm -f"
$cp = "cp"
-- -----------------------------------------------------------------------------
-- generic useful stuff
-- Gotta do some pretty basic stuff :)
def not ( $_bool )
{
......@@ -44,6 +46,42 @@ def rm_nofail ( $_files )
$res = runCmd($cmd)
}
-----------------------------------------------------------------------------
-- (eg) "run.stdout" --> "testdir/testname.run.stdout"
def qualify ( $_filename_frag )
{
if $_filename_frag == ""
then
return $testdir ++ "/" ++ $testname
else
return $testdir ++ "/" ++ $testname ++ "." ++ $_filename_frag
fi
}
def testnameWith ( $_filename_frag )
{
if $_filename_frag == ""
then
return $testname
else
return $testname ++ "." ++ $_filename_frag
fi
}
-- 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:
-- rm_nofail(qualify("o"))
-- rm_nofail(qualify(""))
-- not interested in the return code
}
-- Pipe an error message through normalise_errmsg.
def normalise_errmsg ( $errmsg )
{
......@@ -52,6 +90,22 @@ def normalise_errmsg ( $errmsg )
return $normd
}
-- returns True if both files are identical.
def same ( $_file1, $_file2 )
{
if defined $verbose
then print "vanilla-test: comparing " ++ $_file1
++ " and " ++ $_file2
fi
$cts1 = contents($_file1)
$cts2 = contents($_file2)
$same = $cts1 == $cts2
if not($same) then
say_fail_because_noteq($_file1, $_file2)
fi
return $same
}
-- Give hints as to why a test is failing.
def say_fail_because_noteq ( $filename1, $filename2 )
{
......@@ -76,6 +130,12 @@ def say_fail_because_nonempty ( $filename1 )
print ("--- end of " ++ $filename1)
}
def say_fail_because_exit_code_wrong ( $prg, $exit_code, $should_be )
{
print "--- FAIL because $prog had the wrong exit code (" ++
$exit_code ++ ", should be " ++ $should_be ++ ")"
}
def say_fail_because_compiler_barfd ( $res )
{
print "--- FAIL because the compiler returned non-zero exit code = " ++ $res
......@@ -85,3 +145,49 @@ def say_fail_because_compiler_barfd ( $res )
print contents(qualify("comp.stderr"))
fi
}
---------------------------------------------------------------
--- RUNNING, AND ASSESSING RUN RESULTS ---
---------------------------------------------------------------
-- Run testname. If testname.stdin exists, route input from that, else
-- from /dev/null. Route output to testname.run.stdout and
-- testname.run.stderr. Returns the exit code of the run.
def simple_run_pgm( $extra_args, $exit_code )
{
-- figure out what to use for stdin
$devnull = "/dev/null"
if $stdin /= "" then
$use_stdin = $stdin
else
$stdin = testnameWith("stdin")
$stdin_path = $testdir ++ "/" ++ $stdin
$use_stdin = if exists($stdin_path) then $stdin else $devnull
fi
$run_stdout = testnameWith("run.stdout")
$run_stderr = testnameWith("run.stderr")
rm_or_fail($run_stdout)
rm_or_fail($run_stderr)
$cmd = "cd " ++ $testdir ++ " && "
++ "./" ++ $testname ++ " " ++ $extra_args
++ " < " ++ $use_stdin
++ " > " ++ $run_stdout
++ " 2> " ++ $run_stderr
-- run the command
$res = runCmd($cmd)
-- check the exit code
if $res /= $exit_code then
say_fail_because_exit_code_wrong($testname, $res, $exit_code)
return False
fi
-- check the stdout and stderr outputs
$test_passed = check_stdout_ok() && check_stderr_ok()
return $test_passed
}
......@@ -21,44 +21,10 @@ $expect = "pass"
include ($confdir ++ "/" ++ $conffilename)
include ($confdir ++ "/../std-macros.T")
-- (eg) "run.stdout" --> "testdir/testname.run.stdout"
def qualify ( $_filename_frag )
{
if $_filename_frag == ""
then
return $testdir ++ "/" ++ $testname
else
return $testdir ++ "/" ++ $testname ++ "." ++ $_filename_frag
fi
}
def testnameWith ( $_filename_frag )
{
if $_filename_frag == ""
then
return $testname
else
return $testname ++ "." ++ $_filename_frag
fi
}
---------------------------------------------------------------
--- 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:
-- rm_nofail(qualify("o"))
-- rm_nofail(qualify(""))
-- not interested in the return code
}
-- Guess flags suitable for the compiler.
def guess_compiler_flags()
{
......@@ -107,58 +73,6 @@ def simple_build_Main_WRK ( $_extra_args, $compile_only )
}
---------------------------------------------------------------
--- RUNNING, AND ASSESSING RUN RESULTS ---
---------------------------------------------------------------
-- Run testname. If testname.stdin exists, route input from that, else
-- from /dev/null. Route output to testname.run.stdout and
-- testname.run.stderr. Returns the exit code of the run.
def simple_run_main( $_extra_args )
{
-- figure out what to use for stdin
$devnull = "/dev/null"
if $stdin /= "" then
$use_stdin = $stdin
else
$stdin = testnameWith("stdin")
$stdin_path = $testdir ++ "/" ++ $stdin
$use_stdin = if exists($stdin_path) then $stdin else $devnull
fi
$run_stdout = testnameWith("run.stdout")
$run_stderr = testnameWith("run.stderr")
rm_or_fail($run_stdout)
rm_or_fail($run_stderr)
$cmd = "cd " ++ $testdir ++ " && "
++ "./" ++ $testname ++ " " ++ $_extra_args
++ " < " ++ $use_stdin
++ " > " ++ $run_stdout
++ " 2> " ++ $run_stderr
$res = runCmd($cmd)
return $res
}
-- returns True if both files exist and are identical.
def same ( $_file1, $_file2 )
{
if defined $verbose
then print "vanilla-test: comparing " ++ $_file1
++ " and " ++ $_file2
fi
$cts1 = contents($_file1)
$cts2 = contents($_file2)
$same = $cts1 == $cts2
if not($same) then
say_fail_because_noteq($_file1, $_file2)
fi
return $same
}
-- Check that the run.stdout file matches at least one spec'd stdout.
def check_stdout_ok()
{
......@@ -215,14 +129,12 @@ def vanilla-run-test-actions ( $extra_compile_args,
return False
fi
$res = simple_run_main( $extra_run_args )
if $res /= "0" && $res /= $allowable_nonzero_exit_code
then print "vanilla-test: unexpected exit code (" ++ $res
++ ") from testee"
return False
fi
$test_passed = check_stdout_ok() && check_stderr_ok()
return $test_passed
$exit_code =
if $allowable_nonzero_exit_code /= "" then
$allowable_nonzero_exit_code
else "0"
return simple_run_pgm( $extra_run_args, $exit_code )
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment