summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2011-08-22 17:20:03 +0100
committerLars Wirzenius <liw@liw.fi>2011-08-22 17:20:03 +0100
commit81fab08682f9f442027021551403636943a0fa28 (patch)
treef30fc2926a65f8a2d30c17490d3ec725dbe8c7b6
parent3440a71bc3a9193c6ce48f30c58055b74c7c3e1c (diff)
downloadcmdtest-81fab08682f9f442027021551403636943a0fa28.tar.gz
Run foo.script instead of using foo.args, when script exists.
-rwxr-xr-xcmdtest10
-rw-r--r--cmdtest.py6
-rwxr-xr-xsort-tests/empty.script3
3 files changed, 13 insertions, 6 deletions
diff --git a/cmdtest b/cmdtest
index f2757f9..4d9f183 100755
--- a/cmdtest
+++ b/cmdtest
@@ -101,6 +101,7 @@ class CommandTester(cliapp.Application):
def add_to_env(self):
env = dict(os.environ)
env['DATADIR'] = self.datadir
+ env['COMMAND'] = self.settings['command']
return env
def run_test(self, test):
@@ -108,9 +109,12 @@ class CommandTester(cliapp.Application):
self.run_script(test.setup)
- argv = [self.settings['command']]
- if test.args:
- argv.extend(self.expand(self.lines(test.args)))
+ if test.script:
+ argv = [test.script]
+ else:
+ argv = [self.settings['command']]
+ if test.args:
+ argv.extend(self.expand(self.lines(test.args)))
stdin = self.cat(test.stdin or '/dev/null')
exit, out, err = self.runcmd_unchecked(argv,
diff --git a/cmdtest.py b/cmdtest.py
index 24372c4..0d1a84b 100644
--- a/cmdtest.py
+++ b/cmdtest.py
@@ -30,8 +30,8 @@ class TestDir(object):
'''Contain information about a directory of test cases.'''
- per_test_suffixes = ('args', 'stdin', 'stdout', 'stderr', 'exit',
- 'setup', 'teardown')
+ per_test_suffixes = ('args', 'script', 'stdin', 'stdout', 'stderr',
+ 'exit', 'setup', 'teardown')
def __init__(self):
self.setup = None
@@ -41,7 +41,7 @@ class TestDir(object):
self.teardown_once = None
def scan(self, dirname, filenames=None):
- filenames = filenames or os.listdir(dirname)
+ filenames = os.listdir(dirname) if filenames is None else filenames
script_names = ['setup_once', 'setup', 'teardown', 'teardown_once']
for name in script_names:
diff --git a/sort-tests/empty.script b/sort-tests/empty.script
new file mode 100755
index 0000000..fcd5074
--- /dev/null
+++ b/sort-tests/empty.script
@@ -0,0 +1,3 @@
+#!/bin/sh
+set -e
+sort "$@"