Commits

Brodie Rao committed 620f57a

A number of minor output changes.

* This adds -q/--quiet.

* Skipped tests are marked with 's' instead of nothing.

* Failing tests are marked with '!' before the diff instead of '.'
after.

* A report is printed at the end.

Comments (0)

Files changed (3)

   ``*``, ``?``, and escaping both characters (and backslashes) using
   ``\``.
 
+* Added ``-q/--quiet`` to suppress diff output.
+
+* The number of tests, the number of skipped tests, and the number of
+  failed tests are now printed after all tests are finished.
+
 Version 0.3 (Sep. 20, 2010)
 ```````````````````````````
 * Implemented resetting of common environment variables. This behavior
         elif answer and answer in answers.lower():
             return answer
 
-def run(paths, verbose=False, interactive=False, cwd=None, basetmp=None,
-        keeptmp=False, answer=None):
+def run(paths, quiet=False, verbose=False, interactive=False, cwd=None,
+        basetmp=None, keeptmp=False, answer=None):
     """Run tests in paths and yield output.
 
+    If quiet is True, diffs aren't yielded.
+
     If verbose is True, filenames and status information are yielded.
 
     If cwd is set, os.chdir(cwd) is called after each test is run.
         cwd = os.getcwd()
 
     seen = set()
+    skipped = 0
+    failed = 0
     for path in findtests(paths):
         if path in seen:
             continue
         if verbose:
             yield '%s: ' % path
         if not os.stat(abspath).st_size:
+            skipped += 1
             if verbose:
                 yield 'empty\n'
+            else:
+                yield 's'
         else:
             if basetmp:
                 tmpdir = tempfile.mkdtemp('', os.path.basename(path) + '-',
                     if not keeptmp:
                         shutil.rmtree(tmpdir)
             if diff:
+                failed += 1
                 if verbose:
                     yield 'failed\n'
                 else:
-                    yield '\n'
+                    yield '!'
+                    if not quiet:
+                        yield '\n'
                 errpath = abspath + '.err'
                 errfile = open(errpath, 'w')
                 try:
                         errfile.write(line)
                 finally:
                     errfile.close()
-                for line in diff:
-                    yield line
-                if interactive:
-                    if _prompt('Accept this change?', 'yN', answer) == 'y':
-                        shutil.copy(errpath, abspath)
-                        os.remove(errpath)
-                        if verbose:
-                            yield '%s: merged output\n' % path
-            elif verbose:
+                if not quiet:
+                    for line in diff:
+                        yield line
+                    if interactive:
+                        if _prompt('Accept this change?', 'yN', answer) == 'y':
+                            shutil.copy(errpath, abspath)
+                            os.remove(errpath)
+                            if verbose:
+                                yield '%s: merged output\n' % path
+            elif not verbose:
+                yield '.'
+            else:
                 yield 'passed\n'
-        if not verbose:
-            yield '.'
+    if not verbose:
+        yield '\n'
+    yield '# Ran %s tests, %s skipped, %s failed.\n' % (len(seen), skipped,
+                                                        failed)
 
 def main(args):
     """Main entry point.
     from optparse import OptionParser
 
     p = OptionParser(usage='cram [OPTIONS] TESTS...')
+    p.add_option('-q', '--quiet', action='store_true',
+                 help="don't print diffs")
     p.add_option('-v', '--verbose', action='store_true',
                  help='show filenames and test status')
     p.add_option('-i', '--interactive', action='store_true',
     p.add_option('-E', action='store_false',
                  dest='sterilize', default=True,
                  help="don't reset common environment variables")
+    opts, paths = p.parse_args(args)
 
-    opts, paths = p.parse_args(args)
-    if opts.yes and opts.no:
-        sys.stderr.write('options -y and -n are mutually exclusive\n')
-        return 2
+    conflicts = [('-y', opts.yes, '-n', opts.no),
+                 ('-q', opts.quiet, '-v', opts.verbose),
+                 ('-q', opts.quiet, '-i', opts.interactive)]
+    for s1, o1, s2, o2 in conflicts:
+        if o1 and o2:
+            sys.stderr.write('options %s and %s are mutually exclusive\n'
+                             % (s1, s2))
+            return 2
 
     if not paths:
         sys.stdout.write(p.get_usage())
-        return 1
+        return 2
 
     badpaths = [p for p in paths if not os.path.exists(p)]
     if badpaths:
         answer = None
 
     try:
-        for s in run(paths, opts.verbose, opts.interactive, oldcwd,
-                     basetmp, opts.keep_tmpdir, answer):
+        for s in run(paths, opts.quiet, opts.verbose, opts.interactive,
+                     oldcwd, basetmp, opts.keep_tmpdir, answer):
             sys.stdout.write(s)
             sys.stdout.flush()
         if not opts.verbose:
   
   [Oo]ptions: (re)
     -h, --help            show this help message and exit
+    -q, --quiet           don't print diffs
     -v, --verbose         show filenames and test status
     -i, --interactive     interactively merge changed test output
     -y, --yes             answer yes to all questions
     -E                    don't reset common environment variables
   $ cram
   [Uu]sage: cram \[OPTIONS\] TESTS\.\.\. (re)
-  [1]
+  [2]
   $ cram -y -n
   options -y and -n are mutually exclusive
   [2]
 Run cram examples:
 
   $ cram -D . examples examples/fail.t examples/.hidden.t
-  ...
+  .s.!
   \-\-\- .*/examples/fail\.t\s* (re)
   \+\+\+ .*/examples/fail\.t\.err\s* (re)
   @@ -3,21 +3,22 @@
      [A-Z] (re)
   -  #
   +  @
-  ..
+  .
+  # Ran 5 tests, 1 skipped, 1 failed.
+  
   $ md5 examples/fail.t examples/fail.t.err
   .*\b571651198f015382b002c3ceaafb14c2\b.* (re)
   .*\b89bd872bf755ac3f190cc647be3a6cc7\b.* (re)
   -  #
   +  @
   examples/test.t: passed
+  # Ran 5 tests, 1 skipped, 1 failed.
   $ md5 examples/fail.t examples/fail.t.err
   .*\b571651198f015382b002c3ceaafb14c2\b.* (re)
   .*\b89bd872bf755ac3f190cc647be3a6cc7\b.* (re)
 Interactive mode (don't merge):
 
   $ cram -n -D . -i examples/fail.t
-  
+  !
   \-\-\- .*/examples/fail\.t\s* (re)
   \+\+\+ .*/examples/fail\.t\.err\s* (re)
   @@ -3,21 +3,22 @@
   -  #
   +  @
   Accept this change? [yN] n
-  .
+  
+  # Ran 1 tests, 0 skipped, 1 failed.
+  
   $ md5 examples/fail.t examples/fail.t.err
   .*\b571651198f015382b002c3ceaafb14c2\b.* (re)
   .*\b89bd872bf755ac3f190cc647be3a6cc7\b.* (re)
 
   $ cp examples/fail.t examples/fail.t.orig
   $ cram -y -D . -i examples/fail.t
-  
+  !
   \-\-\- .*/examples/fail\.t\s* (re)
   \+\+\+ .*/examples/fail\.t\.err\s* (re)
   @@ -3,21 +3,22 @@
   -  #
   +  @
   Accept this change? [yN] y
-  .
+  
+  # Ran 1 tests, 0 skipped, 1 failed.
+  
   $ md5 examples/fail.t
   .*\b89bd872bf755ac3f190cc647be3a6cc7\b.* (re)
   $ mv examples/fail.t.orig examples/fail.t
      [A-Z] (re)
   -  #
   +  @
-  Accept this change? [yN] Accept this change? [yN] %
+  Accept this change? [yN] Accept this change? [yN] # Ran 1 tests, 0 skipped, 1 failed.
   $ md5 examples/fail.t examples/fail.t.err
   .*\b571651198f015382b002c3ceaafb14c2\b.* (re)
   .*\b89bd872bf755ac3f190cc647be3a6cc7\b.* (re)
      [A-Z] (re)
   -  #
   +  @
-  Accept this change? [yN] Accept this change? [yN] %
+  Accept this change? [yN] Accept this change? [yN] # Ran 1 tests, 0 skipped, 1 failed.
   $ md5 examples/fail.t examples/fail.t.err
   .*\b571651198f015382b002c3ceaafb14c2\b.* (re)
   .*\b89bd872bf755ac3f190cc647be3a6cc7\b.* (re)
   -  #
   +  @
   Accept this change? [yN] Accept this change? [yN] examples/fail.t: merged output
+  # Ran 1 tests, 0 skipped, 1 failed.
   $ md5 examples/fail.t
   .*\b89bd872bf755ac3f190cc647be3a6cc7\b.* (re)
   $ mv examples/fail.t.orig examples/fail.t
 Use temp dirs:
 
   $ cram examples
-  ...
+  .s.!
   \-\-\- .*/examples/fail\.t\s* (re)
   \+\+\+ .*/examples/fail\.t\.err\s* (re)
   @@ -3,21 +3,22 @@
      [A-Z] (re)
   -  #
   +  @
-  ..
+  .
+  # Ran 5 tests, 1 skipped, 1 failed.
+  
 
 Invalid -D directory:
 
   $ COLUMNS=4815162342; export COLUMNS
   $ GREP_OPTIONS=foo; export GREP_OPTIONS
   $ cram -E examples/env.t
-  
+  !
   \-\-\- .*/examples/env\.t\s* (re)
   \+\+\+ .*/examples/env\.t\.err\s* (re)
   @@ -7,13 +7,13 @@
      $ echo "$RUNDIR"
      .+ (re)
      $ echo "$TESTDIR"
-  .
+  
+  # Ran 1 tests, 0 skipped, 1 failed.
+  
 
 Cleanup: