{"id":19529015,"url":"https://github.com/myint/cram","last_synced_at":"2025-04-26T11:34:11.793Z","repository":{"id":7412881,"uuid":"8745290","full_name":"myint/cram","owner":"myint","description":"Testing framework for command-line applications","archived":false,"fork":false,"pushed_at":"2022-04-25T02:36:16.000Z","size":462,"stargazers_count":7,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-04-09T19:47:09.254Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://bitbucket.org/brodie/cram","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/myint.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"COPYING.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-03-13T04:57:19.000Z","updated_at":"2020-03-13T02:20:44.000Z","dependencies_parsed_at":"2022-08-28T01:23:31.054Z","dependency_job_id":null,"html_url":"https://github.com/myint/cram","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/myint%2Fcram","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/myint%2Fcram/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/myint%2Fcram/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/myint%2Fcram/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/myint","download_url":"https://codeload.github.com/myint/cram/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224033235,"owners_count":17244556,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T01:21:30.266Z","updated_at":"2024-11-11T01:21:31.432Z","avatar_url":"https://github.com/myint.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"======================\n Cram: It's test time\n======================\n\n.. image:: https://travis-ci.org/myint/cram.svg?branch=master\n    :target: https://travis-ci.org/myint/cram\n    :alt: Build status\n\nCram is a functional testing framework for command line applications\nbased on Mercurial_'s `unified test format`_.\n\nCram tests look like snippets of interactive shell sessions. Cram runs\neach command and compares the command output in the test with the\ncommand's actual output.\n\nHere's a snippet from `Cram's own test suite`_::\n\n    The $PYTHON environment variable should be set when running this test\n    from Python.\n\n      $ [ -n \"$PYTHON\" ] || PYTHON=\"`which python`\"\n      $ if [ -n \"$COVERAGE\" ]; then\n      \u003e   coverage erase\n      \u003e   alias cram=\"`which coverage` run --branch -a $TESTDIR/../cram.py\"\n      \u003e else\n      \u003e   alias cram=\"$PYTHON $TESTDIR/../cram.py\"\n      \u003e fi\n      $ command -v md5 \u003e /dev/null || alias md5=md5sum\n\n    Usage:\n\n      $ cram -h\n      [Uu]sage: cram \\[OPTIONS\\] TESTS\\.\\.\\. (re)\n\n      [Oo]ptions: (re)\n        -h, --help          show this help message and exit\n        -V, --version       show version information and exit\n        -q, --quiet         don't print diffs\n        -v, --verbose       show filenames and test status\n        -i, --interactive   interactively merge changed test output\n        -y, --yes           answer yes to all questions\n        -n, --no            answer no to all questions\n        -E, --preserve-env  don't reset common environment variables\n        --keep-tmpdir       keep temporary directories\n        --shell=PATH        shell to use for running tests\n        --indent=NUM        number of spaces to use for indentation\n\nThe format in a nutshell:\n\n* Cram tests use the ``.t`` file extension.\n\n* Lines beginning with two spaces, a dollar sign, and a space are run\n  in the shell.\n\n* Lines beginning with two spaces, a greater than sign, and a space\n  allow multi-line commands.\n\n* All other lines beginning with two spaces are considered command\n  output.\n\n* Output lines ending with a space and the keyword ``(re)`` are\n  matched as `Perl-compatible regular expressions`_.\n\n* Lines ending with a space and the keyword ``(glob)`` are matched\n  with a glob-like syntax. The only special characters supported are\n  ``*`` and ``?``. Both characters can be escaped using ``\\``, and the\n  backslash can be escaped itself.\n\n* Output lines ending with either of the above keywords are always\n  first matched literally with actual command output.\n\n* Lines ending with a space and the keyword ``(no-eol)`` will match\n  actual output that doesn't end in a newline.\n\n* Actual output lines containing unprintable characters are escaped\n  and suffixed with a space and the keyword ``(esc)``. Lines matching\n  unprintable output must also contain the keyword.\n\n* Anything else is a comment.\n\n.. _Mercurial: http://mercurial.selenic.com/\n.. _unified test format: http://www.selenic.com/blog/?p=663\n.. _Cram's own test suite: http://bitbucket.org/brodie/cram/src/tip/tests/cram.t\n.. _Perl-compatible regular expressions: http://en.wikipedia.org/wiki/Perl_Compatible_Regular_Expressions\n\n\nDownload\n--------\n\n* cram-0.5.tar.gz_ (22 KB, requires Python 2.4-2.7 or Python 3.1-3.2)\n\n.. _cram-0.5.tar.gz: http://bitheap.org/cram/cram-0.5.tar.gz\n\nInstallation\n------------\n\nYou can use pip_ to install Cram::\n\n    $ pip install cram\n\nOr you can install Cram the old fashioned way::\n\n    $ wget http://bitheap.org/cram/cram-0.5.tar.gz\n    $ tar zxvf cram-0.5.tar.gz\n    $ cd cram-0.5.tar.gz\n    $ python setup.py install\n\n.. _pip: http://pypi.python.org/pypi/pip\n\n\nUsage\n-----\n\nCram will print a dot for each passing test. If a test fails, a\n`unified context diff`_ is printed showing the test's expected output\nand the actual output. Skipped tests (empty tests and tests that exit\nwith return code ``80``) are marked with ``s`` instead of a dot.\n\nFor example, if we run Cram on `its own example tests`_::\n\n    .s.!\n    --- /home/brodie/src/cram/examples/fail.t\n    +++ /home/brodie/src/cram/examples/fail.t.err\n    @@ -3,21 +3,22 @@\n       $ echo 1\n       1\n       $ echo 1\n    -  2\n    +  1\n       $ echo 1\n       1\n\n     Invalid regex:\n\n       $ echo 1\n    -  +++ (re)\n    +  1\n\n     Offset regular expression:\n\n       $ printf 'foo\\nbar\\nbaz\\n\\n1\\nA\\n@\\n'\n       foo\n    +  bar\n       baz\n\n       \\d (re)\n       [A-Z] (re)\n    -  #\n    +  @\n    s.\n    # Ran 6 tests, 2 skipped, 1 failed.\n\nCram will also write the test with its actual output to\n``examples/fail.t.err``.\n\nWhen you're first writing a test, you might just write the commands\nand run the test to see what happens. If you run Cram with ``-i`` or\n``--interactive``, you'll be prompted to merge the actual output back\ninto the test. This makes it easy to quickly prototype new tests.\n\nYou can specify a default set of options by creating a ``.cramrc``\nfile. For example::\n\n    [cram]\n    verbose = True\n    indent = 4\n\nIs the same as invoking Cram with ``--verbose`` and ``--indent=4``.\n\nTo change what configuration file Cram loads, you can set the\n``CRAMRC`` environment variable. You can also specify command line\noptions in the ``CRAM`` environment variable.\n\nNote that the following environment variables are reset before tests\nare run:\n\n* ``TMPDIR``, ``TEMP``, and ``TMP`` are set to the test runner's\n  ``tmp`` directory.\n\n* ``LANG``, ``LC_ALL``, and ``LANGUAGE`` are set to ``C``.\n\n* ``TZ`` is set to ``GMT``.\n\n* ``COLUMNS`` is set to ``80``.\n\n* ``CDPATH`` and ``GREP_OPTIONS`` are set to an empty string.\n\nCram also provides the following environment variables to tests:\n\n* ``CRAMTMP``, set to the test runner's temporary directory.\n\n* ``TESTDIR``, set to the directory containing the test file.\n\n.. _unified context diff: http://en.wikipedia.org/wiki/Diff#Unified_format\n.. _its own example tests: http://bitbucket.org/brodie/cram/src/tip/examples/\n\n\nNews\n----\n\nVersion 0.6\n```````````\n* Added support for specifying options in ``.cramrc`` (configurable\n  with the ``CRAMRC`` environment variable).\n\n* Added a ``--shell`` option to change the shell tests are run\n  with. Contributed by `Kamil Kisiel`_.\n\n* Added the long option ``--preserve-env`` for ``-E``.\n\n.. _Kamil Kisiel: http://kamilkisiel.net/\n\nVersion 0.5 (Jan. 8, 2011)\n``````````````````````````\n* **The test format has changed:** Matching output not ending in a\n  newline now requires the ``(no-eol)`` keyword instead of ending the\n  line in ``%``.\n\n* Matching output containing unprintable characters now requires the\n  ``(esc)`` keyword. Real output containing unprintable characters\n  will automatically receive ``(esc)``.\n\n* If an expected line matches its real output line exactly, special\n  matching like ``(re)`` or ``(glob)`` will be ignored.\n\n* Regular expressions ending in a trailing backslash are now\n  considered invalid.\n\n* Added an ``--indent`` option for changing the default amount of\n  indentation required to specify commands and output.\n\n* Added support for specifying command line options in the ``CRAM``\n  environment variable.\n\n* The ``--quiet`` and ``--verbose`` options can now be used together.\n\n* When running Cram under Python 3, Unicode-specific line break\n  characters will no longer be parsed as newlines.\n\n* Tests are no longer required to end in a trailing newline.\n\nVersion 0.4 (Sep. 28, 2010)\n```````````````````````````\n* **The test format has changed:** Output lines containing regular\n  expressions must now end in ``(re)`` or they'll be matched\n  literally. Lines ending with keywords are matched literally first,\n  however.\n\n* Regular expressions are now matched from beginning to end. In other\n  words ``\\d (re)`` is matched as ``^\\d$``.\n\n* In addition to ``(re)``, ``(glob)`` has been added. It supports\n  ``*``, ``?``, and escaping both characters (and backslashes) using\n  ``\\``.\n\n* **Environment settings have changed:** The ``-D`` flag has been\n  removed, ``$TESTDIR`` is now set to the directory containing the\n  ``.t`` file, and ``$CRAMTMP`` is set to the test runner's temporary\n  directory.\n\n* ``-i``/``--interactive`` now requires ``patch(1)``. Instead of\n  ``.err`` files replacing ``.t`` files during merges, diffs are\n  applied using ``patch(1)``. This prevents matching regular\n  expressions and globs from getting clobbered.\n\n* Previous ``.err`` files are now removed when tests pass.\n\n* Cram now exits with return code ``1`` if any tests failed.\n\n* If a test exits with return code ``80``, it's considered a skipped a\n  test. This is useful for intentionally disabling tests when they\n  only work on certain platforms or in certain settings.\n\n* The number of tests, the number of skipped tests, and the number of\n  failed tests are now printed after all tests are finished.\n\n* Added ``-q``/``--quiet`` to suppress diff output.\n\n* Added `contrib/cram.vim`_ syntax file for Vim. Contributed by `Steve\n  Losh`_.\n\n.. _contrib/cram.vim: http://bitbucket.org/brodie/cram/src/tip/contrib/cram.vim\n.. _Steve Losh: http://stevelosh.com/\n\nVersion 0.3 (Sep. 20, 2010)\n```````````````````````````\n* Implemented resetting of common environment variables. This behavior\n  can be disabled using the ``-E`` flag.\n\n* Changed the test runner to first make its own overall random\n  temporary directory, make ``tmp`` inside of it and set ``TMPDIR``,\n  etc. to its path, and run each test with a random temporary working\n  directory inside of that.\n\n* Added ``--keep-tmpdir``. Temporary directories are named by test\n  filename (along with a random string).\n\n* Added ``-i``/``--interactive`` to merge actual output back to into\n  tests interactively.\n\n* Added ability to match command output not ending in a newline by\n  suffixing output in the test with ``%``.\n\nVersion 0.2 (Sep. 19, 2010)\n```````````````````````````\n* Changed the test runner to run tests with a random temporary working\n  directory.\n\nVersion 0.1 (Sep. 19, 2010)\n```````````````````````````\n* Initial release.\n\n\nDevelopment\n-----------\n\nDownload the official development repository using Mercurial_::\n\n    hg clone http://bitbucket.org/brodie/cram\n\nTest Cram using Cram::\n\n    make tests\n\nGet a test coverage report using coverage.py_::\n\n    make coverage\n\nVisit Bitbucket_ if you'd like to fork the project, watch for new\nchanges, or report issues.\n\n.. _Mercurial: http://mercurial.selenic.com/\n.. _coverage.py: http://nedbatchelder.com/code/coverage/\n.. _Bitbucket: http://bitbucket.org/brodie/cram\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmyint%2Fcram","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmyint%2Fcram","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmyint%2Fcram/lists"}