Source

cram /

Filename Size Date modified Message
examples
scripts
tests
90 B
17.6 KB
92 B
727 B
3.5 KB
224 B
6.3 KB
2.1 KB

Cram: It's test time

Cram is a functional testing framework for command line applications based on Mercurial's unified test format.

Here's a snippet from cram.t in Cram's own test suite:

The $PYTHON environment variable should be set when running this
test from Python.

  $ [ -n "$PYTHON" ] || PYTHON=python
  $ if [ -n "$COVERAGE" ]; then
  >   coverage erase
  >   alias cram='coverage run -a cram.py'
  > else
  >   alias cram="$PYTHON cram.py"
  > fi

Usage:

  $ cram -h
  [Uu]sage: cram \[OPTIONS\] TESTS\.\.\.

  [Oo]ptions:
    -h, --help     show this help message and exit
    -v, --verbose  Show filenames and test status
  $ cram
  [Uu]sage: cram \[OPTIONS\] TESTS\.\.\.
  [1]

The format in a nutshell:

  • Cram tests use the .t file extension.
  • Lines beginning with two spaces, a dollar sign, and a space are run in the shell.
  • Lines beginning with two spaces, a greater than sign, and a space allow multi-line commands.
  • All other lines beginning with two spaces are considered command output.
  • Command output in the test is first matched literally with the actual output. If it doesn't match, it's then compiled and matched as a Perl-compatible regular expression.
  • Anything else is a comment.

Download

Installation

You can use pip to install Cram:

$ sudo pip install cram

Or you can install Cram the old fashioned way:

$ wget http://bitheap.org/cram/cram-0.2.tar.gz
$ tar zxvf cram-0.1.tar.gz
$ cd cram-0.1.tar.gz
$ sudo python setup.py install

Usage

Cram will print a dot for each passing test. If a test fails, a unified context diff is printed showing the test's expected output and the actual output.

For example, if we run cram on its own example tests:

$ cram examples
..
--- examples/fail.t
+++ examples/fail.t.out
@@ -3,11 +3,11 @@
   $ echo 1
   1
   $ echo 1
-  2
+  1
   $ echo 1
   1

 Invalid regex:

   $ echo 1
-  +++
+  1
..

Cram will also write the test with its actual output to examples/fail.t.err. This makes it easy to merge output back into the test file using when writing a test for the first time. You can run diff examples/fail.t{,.err} and use patch -p0 to apply the patch.

Development

Download the official development repository using Mercurial:

hg clone http://bitbucket.org/brodie/cram

Test Cram using Cram:

make tests

Get a test coverage report using coverage.py:

make coverage

Visit Bitbucket if you'd like to fork the project, watch for new changes, or report issues.

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.