Kamil Kisiel  committed 50957c1

Added --shell option to specify what shell to run tests with

  • Participants
  • Parent commits e8b1635

Comments (0)

Files changed (2)

     """Like the string-escape codec, but doesn't escape quotes"""
     return escapesub(lambda m: escapemap[], s[:-1]) + ' (esc)\n'
-def test(path, indent=2):
+def test(path, indent=2, shell='/bin/sh'):
     """Run test at path and return input, output, and diff.
     This returns a 3-tuple containing the following:
     abspath = os.path.abspath(path)
     env = os.environ.copy()
     env['TESTDIR'] = os.path.dirname(abspath)
-    p = subprocess.Popen(['/bin/sh', '-'], bufsize=-1, stdin=subprocess.PIPE,
+    p = subprocess.Popen([shell, '-'], bufsize=-1, stdin=subprocess.PIPE,
                          stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
                          universal_newlines=True, env=env,
                 == 'posix')
     return p.returncode == 0
 def run(paths, tmpdir, quiet=False, verbose=False, patchcmd=None, answer=None,
-        indent=2):
+        indent=2, shell='/bin/sh'):
     """Run tests in paths in tmpdir.
     If quiet is True, diffs aren't printed. If verbose is True,
-                refout, postout, diff = test(abspath, indent)
+                refout, postout, diff = test(abspath, indent, shell)
                  help="don't reset common environment variables")
     p.add_option('--keep-tmpdir', action='store_true',
                  help='keep temporary directories')
+    p.add_option('--shell', action='store', default='/bin/sh', metavar='PATH',
+                 help='shell to use for running tests')
     p.add_option('--indent', action='store', default=2, metavar='NUM',
                  type='int', help='number of spaces to use for indentation')
     opts, paths = p.parse_args(args)
         return run(paths, tmpdir, opts.quiet, opts.verbose, patchcmd, answer,
-                   opts.indent)
+                   opts.indent,
         if opts.keep_tmpdir:
             log('# Kept temporary directory: %s\n' % tmpdir)

File tests/cram.t

 The $PYTHON environment variable should be set when running this test
 from Python.
+  $ [ "$0" != "/bin/bash" ] || shopt -s expand_aliases
   $ [ -n "$PYTHON" ] || PYTHON="`which python`"
   $ if [ -n "$COVERAGE" ]; then
   >   coverage erase
   > fi
   $ command -v md5 > /dev/null || alias md5=md5sum
+Note: Bash doesn't expand aliases by default in non-interactive mode,
+so we enable it manually if the test is run with --shell=/bin/bash.
   $ cram -h
     -n, --no            answer no to all questions
     -E, --preserve-env  don't reset common environment variables
     --keep-tmpdir       keep temporary directories
+    --shell=PATH        shell to use for running tests
     --indent=NUM        number of spaces to use for indentation
   $ cram -V
   Cram CLI testing framework (version 0.5)
   .*\b7a23dfa85773c77648f619ad0f9df554\b.* (re)
   $ rm examples/fail.t.err
+Run examples with bash:
+  $ cram --shell=/bin/bash -q examples examples/fail.t
+  .s.!.s.
+  # Ran 7 tests, 2 skipped, 1 failed.
+  [1]
+  $ md5 examples/fail.t examples/fail.t.err
+  .*\b0f598c2b7b8ca5bcb8880e492ff6b452\b.* (re)
+  .*\b7a23dfa85773c77648f619ad0f9df554\b.* (re)
+  $ rm examples/fail.t.err
 Verbose mode:
   $ cram -q -v examples examples/fail.t