2013-11-09 09:09:26 +01:00
|
|
|
bats(1) -- Bash Automated Testing System
|
|
|
|
========================================
|
|
|
|
|
2013-11-10 23:03:38 +01:00
|
|
|
|
2013-11-09 09:09:26 +01:00
|
|
|
SYNOPSIS
|
|
|
|
--------
|
|
|
|
|
|
|
|
bats [-c] [-p | -t] <test> [<test> ...]
|
|
|
|
|
2013-11-10 23:03:38 +01:00
|
|
|
<test> is the path to a Bats test file, or the path to a directory
|
|
|
|
containing Bats test files.
|
|
|
|
|
2013-11-09 09:09:26 +01:00
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
-----------
|
|
|
|
|
2013-11-10 23:03:38 +01:00
|
|
|
Bats is a TAP-compliant testing framework for Bash. It provides a simple
|
|
|
|
way to verify that the UNIX programs you write behave as expected.
|
2013-11-09 09:09:26 +01:00
|
|
|
|
2013-11-10 23:03:38 +01:00
|
|
|
A Bats test file is a Bash script with special syntax for defining
|
|
|
|
test cases. Under the hood, each test case is just a function with a
|
|
|
|
description.
|
2013-11-09 09:09:26 +01:00
|
|
|
|
2013-11-10 23:03:38 +01:00
|
|
|
Test cases consist of standard shell commands. Bats makes use of
|
|
|
|
Bash's `errexit` (`set -e`) option when running test cases. If every
|
|
|
|
command in the test case exits with a `0` status code (success), the
|
|
|
|
test passes. In this way, each line is an assertion of truth.
|
2013-11-09 09:09:26 +01:00
|
|
|
|
2013-11-10 23:03:38 +01:00
|
|
|
See `bats`(7) for more information on writing Bats tests.
|
2013-11-09 09:09:26 +01:00
|
|
|
|
2013-11-10 23:03:38 +01:00
|
|
|
|
|
|
|
RUNNING TESTS
|
|
|
|
-------------
|
2013-11-09 09:09:26 +01:00
|
|
|
|
|
|
|
To run your tests, invoke the `bats` interpreter with a path to a test
|
|
|
|
file. The file's test cases are run sequentially and in isolation. If
|
|
|
|
all the test cases pass, `bats` exits with a `0` status code. If there
|
|
|
|
are any failures, `bats` exits with a `1` status code.
|
|
|
|
|
2013-11-10 23:03:38 +01:00
|
|
|
You can invoke the `bats` interpreter with multiple test file arguments,
|
|
|
|
or with a path to a directory containing multiple `.bats` files. Bats
|
|
|
|
will run each test file individually and aggregate the results. If any
|
|
|
|
test case fails, `bats` exits with a `1` status code.
|
2013-11-09 09:09:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
OPTIONS
|
|
|
|
-------
|
|
|
|
|
|
|
|
* `-c`, `--count`:
|
|
|
|
Count the number of test cases without running any tests
|
|
|
|
* `-h`, `--help`:
|
2013-11-10 23:03:38 +01:00
|
|
|
Display help message
|
2013-11-09 09:09:26 +01:00
|
|
|
* `-p`, `--pretty`:
|
|
|
|
Show results in pretty format (default for terminals)
|
|
|
|
* `-t`, `--tap`:
|
|
|
|
Show results in TAP format
|
|
|
|
* `-v`, `--version`:
|
|
|
|
Display the version number
|
|
|
|
|
|
|
|
|
2013-11-10 23:03:38 +01:00
|
|
|
OUTPUT
|
|
|
|
------
|
2013-11-09 09:09:26 +01:00
|
|
|
|
|
|
|
When you run Bats from a terminal, you'll see output as each test is
|
|
|
|
performed, with a check-mark next to the test's name if it passes or
|
|
|
|
an "X" if it fails.
|
|
|
|
|
|
|
|
$ bats addition.bats
|
|
|
|
✓ addition using bc
|
|
|
|
✓ addition using dc
|
|
|
|
|
|
|
|
2 tests, 0 failures
|
|
|
|
|
2013-11-10 23:03:38 +01:00
|
|
|
If Bats is not connected to a terminal--in other words, if you run it
|
|
|
|
from a continuous integration system or redirect its output to a
|
|
|
|
file--the results are displayed in human-readable, machine-parsable
|
|
|
|
TAP format. You can force TAP output from a terminal by invoking Bats
|
|
|
|
with the `--tap` option.
|
2013-11-09 09:09:26 +01:00
|
|
|
|
|
|
|
$ bats --tap addition.bats
|
|
|
|
1..2
|
|
|
|
ok 1 addition using bc
|
|
|
|
ok 2 addition using dc
|
|
|
|
|
|
|
|
|
2013-11-10 23:03:38 +01:00
|
|
|
EXIT STATUS
|
|
|
|
-----------
|
|
|
|
|
|
|
|
The `bats` interpreter exits with a value of `0` if all test cases pass,
|
|
|
|
or `1` if one or more test cases fail.
|
|
|
|
|
|
|
|
|
|
|
|
SEE ALSO
|
|
|
|
--------
|
|
|
|
|
|
|
|
Bats wiki: _https://github.com/sstephenson/bats/wiki/_
|
|
|
|
|
|
|
|
`bash`(1), `bats`(7)
|
|
|
|
|
|
|
|
|
2013-11-09 09:09:26 +01:00
|
|
|
COPYRIGHT
|
|
|
|
---------
|
|
|
|
|
2013-11-10 23:03:38 +01:00
|
|
|
(c) 2013 Sam Stephenson
|
2013-11-09 09:09:26 +01:00
|
|
|
|
2013-11-10 23:03:38 +01:00
|
|
|
Bats is released under the terms of an MIT-style license.
|
2013-11-09 09:09:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
|