diff options
author | Thomas Miedema <thomasmiedema@gmail.com> | 2015-03-06 20:17:41 +0100 |
---|---|---|
committer | Thomas Miedema <thomasmiedema@gmail.com> | 2015-03-06 20:17:56 +0100 |
commit | 91c11feacc4c66a7ebcf8a88ab1cb851ce48142a (patch) | |
tree | d5373e63461ff36836710fecfdb5565a68f7d49f /testsuite/driver | |
parent | 41df51d5a2b3dca9cc172e0b128a9f576fd4be05 (diff) | |
download | haskell-91c11feacc4c66a7ebcf8a88ab1cb851ce48142a.tar.gz |
testsuite: format commands using config dict
Summary:
Allow `cmd_wrapper` to return a format string that can refer to config values.
Very useful! This allows for many tests to be defined in pure Python, instead
of in an additional script or Makefile.
Example:
def Thpc(cmd):
return(cmd + ' && {hpc} report Thpc.tix')
test('Thpc', [cmd_wrapper(Thpc), only_ways['hpc']), compile_and_run, [''])
The `{hpc}` is replaced by the value of `config.hpc`. The result is that the
module `Thpc` first gets compiled, then the binary `Thpc` is run, and then the
`hpc report` command is run. The output of all of this is redirected
(and later appended) to Thpc.run.stdout/stderr as normally.
Reviewed By: austin
Differential Revision: https://phabricator.haskell.org/D706
Diffstat (limited to 'testsuite/driver')
-rw-r--r-- | testsuite/driver/testlib.py | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/testsuite/driver/testlib.py b/testsuite/driver/testlib.py index ac6d97cab4..a4e7d96404 100644 --- a/testsuite/driver/testlib.py +++ b/testsuite/driver/testlib.py @@ -1314,11 +1314,11 @@ def simple_run( name, way, prog, args ): stdin_comes_from = ' <' + use_stdin if opts.combined_output: - redirection = ' >' + run_stdout \ - + ' 2>&1' + redirection = ' > {} 2>&1'.format(run_stdout) + redirection_append = ' >> {} 2>&1'.format(run_stdout) else: - redirection = ' >' + run_stdout \ - + ' 2>' + run_stderr + redirection = ' > {} 2> {}'.format(run_stdout, run_stderr) + redirection_append = ' >> {} 2>> {}'.format(run_stdout, run_stderr) cmd = prog + ' ' + args + ' ' \ + my_rts_flags + ' ' \ @@ -1326,7 +1326,7 @@ def simple_run( name, way, prog, args ): + redirection if opts.cmd_wrapper != None: - cmd = opts.cmd_wrapper(cmd); + cmd = opts.cmd_wrapper(cmd) + redirection_append cmd = 'cd ' + opts.testdir + ' && ' + cmd @@ -1426,16 +1426,23 @@ def interpreter_run( name, way, extra_hc_opts, compile_only, top_mod ): if getTestOpts().outputdir != None: flags.extend(["-outputdir", getTestOpts().outputdir]) + if getTestOpts().combined_output: + redirection = ' > {} 2>&1'.format(outname) + redirection_append = ' >> {} 2>&1'.format(outname) + else: + redirection = ' > {} 2> {}'.format(outname, errname) + redirection_append = ' >> {} 2>> {}'.format(outname, errname) + cmd = "'" + config.compiler + "' " \ + ' '.join(flags) + ' ' \ + srcname + ' ' \ + ' '.join(config.way_flags(name)[way]) + ' ' \ + extra_hc_opts + ' ' \ + getTestOpts().extra_hc_opts + ' ' \ - + '<' + scriptname + ' 1>' + outname + ' 2>' + errname + + '<' + scriptname + redirection if getTestOpts().cmd_wrapper != None: - cmd = getTestOpts().cmd_wrapper(cmd); + cmd = getTestOpts().cmd_wrapper(cmd) + redirection_append; cmd = 'cd ' + getTestOpts().testdir + " && " + cmd @@ -1830,6 +1837,9 @@ def runCmd( cmd ): return r << 8 def runCmdFor( name, cmd, timeout_multiplier=1.0 ): + # Format cmd using config. Example: cmd='{hpc} report A.tix' + cmd = cmd.format(**config.__dict__) + if_verbose( 3, cmd ) r = 0 if config.os == 'mingw32': |