diff options
author | Lars Wirzenius <liw@liw.fi> | 2011-12-30 11:55:39 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2011-12-30 11:55:39 +0000 |
commit | 05a891257ffe3711c8244e1e2975549a7a2f2969 (patch) | |
tree | b2eab553df038b5f40944ef8555a295f75044d67 | |
parent | 410ded65cee929b1871b9cf7bfb9545179f5e0a0 (diff) | |
download | cmdtest-05a891257ffe3711c8244e1e2975549a7a2f2969.tar.gz |
add TESTNAME to environment variable
Also, document SRCDIR in manpage, and add missing call to execute
per-test teardown script.
-rwxr-xr-x | cmdtest | 22 | ||||
-rw-r--r-- | cmdtest.1.in | 13 |
2 files changed, 25 insertions, 10 deletions
@@ -57,17 +57,17 @@ class CommandTester(cliapp.Application): errors = 0 self.setup_tempdir() - self.run_script(td.setup_once) + self.run_script('', td.setup_once) for test in td.tests: self.ts['test'] = test - self.run_script(td.setup) + self.run_script(test.name, td.setup) for e in self.run_test(test): logging.error(str(e)) self.ts.clear() self.output.write('%s\n' % str(e)) errors += 1 - self.run_script(td.teardown) - self.run_script(td.teardown_once) + self.run_script(test.name, td.teardown) + self.run_script('', td.teardown_once) self.cleanup_tempdir() ok = len(td.tests) - errors @@ -109,20 +109,21 @@ class CommandTester(cliapp.Application): logging.info('Removing temporary directory %s' % self.tempdir) shutil.rmtree(self.tempdir) - def run_script(self, script_name): + def run_script(self, test_name, script_name): if script_name: - self.runcmd([script_name], env=self.add_to_env()) + self.runcmd([script_name], env=self.add_to_env(test_name)) - def add_to_env(self): + def add_to_env(self, test_name): env = dict(os.environ) env['SRCDIR'] = os.getcwd() env['DATADIR'] = self.datadir + env['TESTNAME'] = test_name return env def run_test(self, test): logging.info('Test case: %s' % test.name) - self.run_script(test.setup) + self.run_script(test.name, test.setup) if test.script: argv = [test.script] @@ -137,14 +138,17 @@ class CommandTester(cliapp.Application): stdin = open(test.stdin, 'rb') else: stdin = None + env = self.add_to_env(test.name) exit, out, err = self.runcmd_unchecked(argv, - env=self.add_to_env(), + env=env, stdin=stdin, stdout=stdout, stderr=stderr) if stdin is not None: stdin.close() + self.run_script(test.name, test.teardown) + errors = [] stdout_diff_name = test.path_prefix + '.stdout-diff' diff --git a/cmdtest.1.in b/cmdtest.1.in index 4791bb1..c76f30c 100644 --- a/cmdtest.1.in +++ b/cmdtest.1.in @@ -117,10 +117,21 @@ it is treated as if it were empty. If the exit code file is missing, it is treated as if it specified an exit code of zero. .PP -The shell scripts may use the following environment variable: +The shell scripts may use the following environment variables: .TP .B DATADIR a temporary directory where files may be created by the test +.TP +.B TESTNAME +name of the current test (will be empty for +.B setup-once +and +.BR teardown-once ) +.TP +.B SRCDIR +directory from which +.B cmdtest +was launched .SH OPTIONS .SH EXAMPLE To test that the |