From b1eee9f455f677a9356495aae382d4879a6c5cc3 Mon Sep 17 00:00:00 2001 From: Jakukyo Friel Date: Sat, 9 Nov 2013 16:09:26 +0800 Subject: [PATCH] add Manpages - add bats.1 - add bats.7 - tweak install.sh to install manpages --- install.sh | 2 + man/bats.1 | 86 ++++++++++++++ man/bats.1.html | 156 ++++++++++++++++++++++++++ man/bats.1.ronn | 87 +++++++++++++++ man/bats.7 | 235 +++++++++++++++++++++++++++++++++++++++ man/bats.7.html | 290 ++++++++++++++++++++++++++++++++++++++++++++++++ man/bats.7.ronn | 211 +++++++++++++++++++++++++++++++++++ man/index.txt | 3 + 8 files changed, 1070 insertions(+) create mode 100644 man/bats.1 create mode 100644 man/bats.1.html create mode 100644 man/bats.1.ronn create mode 100644 man/bats.7 create mode 100644 man/bats.7.html create mode 100644 man/bats.7.ronn create mode 100644 man/index.txt diff --git a/install.sh b/install.sh index 8254168..413a569 100755 --- a/install.sh +++ b/install.sh @@ -31,5 +31,7 @@ BATS_ROOT="$(abs_dirname "$0")" mkdir -p "$PREFIX"/{bin,libexec} cp -R "$BATS_ROOT"/bin/* "$PREFIX"/bin cp -R "$BATS_ROOT"/libexec/* "$PREFIX"/libexec +cp "$BATS_ROOT"/man/bats.1 "$PREFIX"/share/man/man1 +cp "$BATS_ROOT"/man/bats.7 "$PREFIX"/share/man/man7 echo "Installed Bats to $PREFIX/bin/bats" diff --git a/man/bats.1 b/man/bats.1 new file mode 100644 index 0000000..f6455ab --- /dev/null +++ b/man/bats.1 @@ -0,0 +1,86 @@ +.\" generated with Ronn/v0.7.3 +.\" http://github.com/rtomayko/ronn/tree/0.7.3 +. +.TH "BATS" "1" "November 2013" "" "" +. +.SH "NAME" +\fBbats\fR \- Bash Automated Testing System +. +.SH "SYNOPSIS" +bats [\-c] [\-p | \-t] \fItest\fR [\fItest\fR \.\.\.] +. +.SH "DESCRIPTION" +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\. +. +.P +Bats is most useful when testing software written in Bash, but you can use it to test any UNIX program\. +. +.SH "FILES" +To run your tests, invoke the \fBbats\fR 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, \fBbats\fR exits with a \fB0\fR status code\. If there are any failures, \fBbats\fR exits with a \fB1\fR status code\. +. +.P +You can invoke the \fBbats\fR interpreter with multiple test file arguments, or with a path to a directory containing multiple \fB\.bats\fR files\. Bats will run each test file individually and aggregate the results\. If any test case fails, \fBbats\fR exits with a \fB1\fR status code\. +. +.SH "OPTIONS" +. +.TP +\fB\-c\fR, \fB\-\-count\fR +Count the number of test cases without running any tests +. +.TP +\fB\-h\fR, \fB\-\-help\fR +Display this help message +. +.TP +\fB\-p\fR, \fB\-\-pretty\fR +Show results in pretty format (default for terminals) +. +.TP +\fB\-t\fR, \fB\-\-tap\fR +Show results in TAP format +. +.TP +\fB\-v\fR, \fB\-\-version\fR +Display the version number +. +.SH "EXAMPLES" +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\. +. +.IP "" 4 +. +.nf + +$ bats addition\.bats + ✓ addition using bc + ✓ addition using dc + +2 tests, 0 failures +. +.fi +. +.IP "" 0 +. +.P +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 \fIhttp://testanything\.org/wiki/index\.php/TAP_specification#THE_TAP_FORMAT\fR\. You can force TAP output from a terminal by invoking Bats with the \fB\-\-tap\fR option\. +. +.IP "" 4 +. +.nf + +$ bats \-\-tap addition\.bats +1\.\.2 +ok 1 addition using bc +ok 2 addition using dc +. +.fi +. +.IP "" 0 +. +.SH "COPYRIGHT" +(c) 2013 Sam Stephenson\. +. +.P +Bats is released under an MIT\-style license +. +.SH "SEE ALSO" +bats(7) diff --git a/man/bats.1.html b/man/bats.1.html new file mode 100644 index 0000000..56f972a --- /dev/null +++ b/man/bats.1.html @@ -0,0 +1,156 @@ + + + + + + bats(1) - Bash Automated Testing System + + + + +
+ + + +
    +
  1. bats(1)
  2. +
  3. +
  4. bats(1)
  5. +
+ +

NAME

+

+ bats - Bash Automated Testing System +

+ +

SYNOPSIS

+ +

bats [-c] [-p | -t] test [test ...]

+ +

DESCRIPTION

+ +

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.

+ +

Bats is most useful when testing software written in Bash, but you can use it to test any UNIX program.

+ +

FILES

+ +

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.

+ +

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.

+ +

OPTIONS

+ +
+
-c, --count
Count the number of test cases without running any tests
+
-h, --help
Display this help message
+
-p, --pretty
Show results in pretty format (default for terminals)
+
-t, --tap
Show results in TAP format
+
-v, --version
Display the version number
+
+ + +

EXAMPLES

+ +

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
+
+ +

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.

+ +
$ bats --tap addition.bats
+1..2
+ok 1 addition using bc
+ok 2 addition using dc
+
+ + + +

(c) 2013 Sam Stephenson.

+ +

Bats is released under an MIT-style license

+ +

SEE ALSO

+ +

bats(7)

+ + +
    +
  1. +
  2. November 2013
  3. +
  4. bats(1)
  5. +
+ +
+ + diff --git a/man/bats.1.ronn b/man/bats.1.ronn new file mode 100644 index 0000000..41e57b7 --- /dev/null +++ b/man/bats.1.ronn @@ -0,0 +1,87 @@ +bats(1) -- Bash Automated Testing System +======================================== + +SYNOPSIS +-------- + +bats [-c] [-p | -t] [ ...] + + +DESCRIPTION +----------- + + +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. + +Bats is most useful when testing software written in Bash, but you can use it to test any UNIX program. + + +FILES +----- + +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. + +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. + + +OPTIONS +------- + + * `-c`, `--count`: + Count the number of test cases without running any tests + * `-h`, `--help`: + Display this help message + * `-p`, `--pretty`: + Show results in pretty format (default for terminals) + * `-t`, `--tap`: + Show results in TAP format + * `-v`, `--version`: + Display the version number + + +EXAMPLES +-------- + + +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 + +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](http://testanything.org/wiki/index.php/TAP_specification#THE_TAP_FORMAT). +You can force TAP output from a terminal by invoking Bats with the +`--tap` option. + + $ bats --tap addition.bats + 1..2 + ok 1 addition using bc + ok 2 addition using dc + + +COPYRIGHT +--------- + +(c) 2013 Sam Stephenson. + +Bats is released under an MIT-style license + + +SEE ALSO +-------- + +bats(7) diff --git a/man/bats.7 b/man/bats.7 new file mode 100644 index 0000000..449b570 --- /dev/null +++ b/man/bats.7 @@ -0,0 +1,235 @@ +.\" generated with Ronn/v0.7.3 +.\" http://github.com/rtomayko/ronn/tree/0.7.3 +. +.TH "BATS" "7" "November 2013" "" "" +. +.SH "NAME" +\fBbats\fR \- Bats test file format +. +.SH "SYNOPSIS" +. +.nf + +load test_helper + + +setup() { + # set up your environment + # run before and after each test case +} + +teardown() { + # clean up your environment + # run before and after each test case +} + + +code_outside_of_test_cases () { + # For example, check for dependencies + # and fail immediatelyif they\'re not present\. + # Output must be redirected to `stderr` (`>&2`) +} + + +@test "test description" { + run foo arguments + [ "$status" \-eq 1 ] + [ "$output" = "expected output" ] +} + +@test "test description" { + run foo arguments + [ "$status" \-eq 1 ] + [ "${lines[0]}" = "first line of expected output" ] +} + + +@test "A test I don\'t want to execute for now" { + skip "This command will return zero soon, but not now" + run foo + [ "$status" \-eq 0 ] +} + +@test "A test which should run" { + if [ foo != bar ]; then + skip "foo isn\'t bar" + fi + + run foo + [ "$status" \-eq 0 ] +} +. +.fi +. +.SH "DESCRIPTION" +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\. +. +.IP "" 4 +. +.nf + +#!/usr/bin/env bats + +@test "addition using bc" { + result="$(echo 2+2 | bc)" + [ "$result" \-eq 4 ] +} + +@test "addition using dc" { + result="$(echo 2 2+p | dc)" + [ "$result" \-eq 4 ] +} +. +.fi +. +.IP "" 0 +. +.P +Each Bats test file is evaulated n+1 times, where \fIn\fR is the number of test cases in the file\. The first run counts the number of test cases, then iterates over the test cases and executes each one in its own process\. +. +.P +For details about exactly how Bats evaluates test files, see Bats Evaluation Process: https://github\.com/sstephenson/bats/wiki/Bats\-Evaluation\-Process +. +.SH "THE _RUN_ HELPER" +Many Bats tests need to run a command and then make assertions about its exit status and output\. Bats includes a \fBrun\fR helper that invokes its arguments as a command, saves the exit status and output into special global variables, and then returns with a \fB0\fR status code so you can continue to make assertions in your test case\. +. +.P +For example, let\'s say you\'re testing that the \fBfoo\fR command, when passed a nonexistent filename, exits with a \fB1\fR status code and prints an error message\. +. +.IP "" 4 +. +.nf + +@test "invoking foo with a nonexistent file prints an error" { + run foo nonexistent_filename + [ "$status" \-eq 1 ] + [ "$output" = "foo: no such file \'nonexistent_filename\'" ] +} +. +.fi +. +.IP "" 0 +. +.P +The \fB$status\fR variable contains the status code of the command, and the \fB$output\fR variable contains the combined contents of the command\'s standard output and standard error streams\. +. +.P +A third special variable, the \fB$lines\fR array, is available for easily accessing individual lines of output\. For example, if you want to test that invoking \fBfoo\fR without any arguments prints usage information on the first line: +. +.IP "" 4 +. +.nf + +@test "invoking foo without arguments prints usage" { run foo + [ "$status" \-eq 1 ] + [ "${lines[0]}" = "usage: foo " ] +} +. +.fi +. +.IP "" 0 +. +.SH "THE _LOAD_ COMMAND" +You may want to share common code across multiple test files\. Bats includes a convenient \fBload\fR command for sourcing a Bash source file relative to the location of the current test file\. For example, if you have a Bats test in \fBtest/foo\.bats\fR, the command +. +.IP "" 4 +. +.nf + +load test_helper +. +.fi +. +.IP "" 0 +. +.P +will source the script \fBtest/test_helper\.bash\fR in your test file\. This can be useful for sharing functions to set up your environment or load fixtures\. +. +.SH "THE _SKIP_ COMMAND" +Tests can be skipped by using the \fBskip\fR command at the point in a test you wish to skip\. +. +.IP "" 4 +. +.nf + +@test "A test I don\'t want to execute for now" { + skip + run foo + [ "$status" \-eq 0 ] +} +. +.fi +. +.IP "" 0 +. +.P +Optionally, you may include a reason for skipping: +. +.IP "" 4 +. +.nf + +@test "A test I don\'t want to execute for now" { + skip "This command will return zero soon, but not now" + run foo + [ "$status" \-eq 0 ] +} +. +.fi +. +.IP "" 0 +. +.P +Or you can skip conditionally: +. +.IP "" 4 +. +.nf + +@test "A test which should run" { + if [ foo != bar ]; then + skip "foo isn\'t bar" + fi + + run foo + [ "$status" \-eq 0 ] +} +. +.fi +. +.IP "" 0 +. +.SH "SETUP AND TEARDOWN FUNCTIONS" +You can define special \fBsetup\fR and \fBteardown\fR functions which run before and after each test case, respectively\. Use these to load fixtures, set up your environment, and clean up when you\'re done\. +. +.SH "CODE OUTSIDE OF TEST CASES" +You can include code in your test file outside of \fB@test\fR functions\. For example, this may be useful if you want to check for dependencies and fail immediately if they\'re not present\. However, any output that you print in code outside of \fB@test\fR, \fBsetup\fR or \fBteardown\fR functions must be redirected to \fBstderr\fR (\fB>&2\fR)\. Otherwise, the output may cause Bats to fail by polluting the TAP stream on \fBstdout\fR\. +. +.SH "SPECIAL VARIABLES" +There are several global variables you can use to introspect on Bats tests: +. +.IP "\(bu" 4 +\fB$BATS_TEST_FILENAME\fR is the fully expanded path to the Bats test file\. +. +.IP "\(bu" 4 +\fB$BATS_TEST_DIRNAME\fR is the directory in which the Bats test file is located\. +. +.IP "\(bu" 4 +\fB$BATS_TEST_NAMES\fR is an array of function names for each test case\. +. +.IP "\(bu" 4 +\fB$BATS_TEST_NAME\fR is the name of the function containing the current test case\. +. +.IP "\(bu" 4 +\fB$BATS_TEST_DESCRIPTION\fR is the description of the current test case\. +. +.IP "\(bu" 4 +\fB$BATS_TEST_NUMBER\fR is the (1\-based) index of the current test case in the test file\. +. +.IP "\(bu" 4 +\fB$BATS_TMPDIR\fR is the location to a directory that may be used to store temporary files\. +. +.IP "" 0 +. +.SH "SEE ALSO" +bats(1) diff --git a/man/bats.7.html b/man/bats.7.html new file mode 100644 index 0000000..668b15f --- /dev/null +++ b/man/bats.7.html @@ -0,0 +1,290 @@ + + + + + + bats(7) - Bats test file format + + + + +
+ + + +
    +
  1. bats(7)
  2. +
  3. +
  4. bats(7)
  5. +
+ +

NAME

+

+ bats - Bats test file format +

+ +

SYNOPSIS

+ +
load test_helper
+
+
+setup() {
+  # set up your environment
+  # run before and after each test case
+}
+
+teardown() {
+  # clean up your environment
+  # run before and after each test case
+}
+
+
+code_outside_of_test_cases () {
+  # For example, check for dependencies 
+  # and fail immediatelyif they're not present.
+  # Output must be redirected to `stderr` (`>&2`)
+}
+
+
+@test "test description" {
+    run foo arguments
+    [ "$status" -eq 1 ]
+    [ "$output" = "expected output" ]
+}
+
+@test "test description" {
+  run foo arguments
+  [ "$status" -eq 1 ]
+  [ "${lines[0]}" = "first line of expected output" ]
+}
+
+
+@test "A test I don't want to execute for now" {
+  skip "This command will return zero soon, but not now"
+  run foo
+  [ "$status" -eq 0 ]
+}
+
+@test "A test which should run" {
+  if [ foo != bar ]; then
+    skip "foo isn't bar"
+  fi
+
+  run foo
+  [ "$status" -eq 0 ]
+}
+
+ +

DESCRIPTION

+ +

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.

+ +
#!/usr/bin/env bats
+
+@test "addition using bc" {
+  result="$(echo 2+2 | bc)"
+  [ "$result" -eq 4 ]
+}
+
+@test "addition using dc" {
+  result="$(echo 2 2+p | dc)"
+  [ "$result" -eq 4 ]
+}
+
+ +

Each Bats test file is evaulated n+1 times, where n is the number of +test cases in the file. The first run counts the number of test cases, +then iterates over the test cases and executes each one in its own +process.

+ +

For details about exactly how Bats evaluates test files, see +Bats Evaluation Process: +https://github.com/sstephenson/bats/wiki/Bats-Evaluation-Process

+ +

THE _RUN_ HELPER

+ +

Many Bats tests need to run a command and then make assertions about +its exit status and output. Bats includes a run helper that invokes +its arguments as a command, saves the exit status and output into +special global variables, and then returns with a 0 status code so +you can continue to make assertions in your test case.

+ +

For example, let's say you're testing that the foo command, when +passed a nonexistent filename, exits with a 1 status code and prints +an error message.

+ +
@test "invoking foo with a nonexistent file prints an error" {
+  run foo nonexistent_filename
+  [ "$status" -eq 1 ]
+  [ "$output" = "foo: no such file 'nonexistent_filename'" ]
+}
+
+ +

The $status variable contains the status code of the command, and +the $output variable contains the combined contents of the command's +standard output and standard error streams.

+ +

A third special variable, the $lines array, is available for easily +accessing individual lines of output. For example, if you want to test +that invoking foo without any arguments prints usage information on +the first line:

+ +
@test "invoking foo without arguments prints usage" { run foo
+  [ "$status" -eq 1 ]
+  [ "${lines[0]}" = "usage: foo <filename>" ]
+}
+
+ +

THE _LOAD_ COMMAND

+ +

You may want to share common code across multiple test files. Bats +includes a convenient load command for sourcing a Bash source file +relative to the location of the current test file. For example, if you +have a Bats test in test/foo.bats, the command

+ +
load test_helper
+
+ +

will source the script test/test_helper.bash in your test file. This +can be useful for sharing functions to set up your environment or load +fixtures.

+ +

THE _SKIP_ COMMAND

+ +

Tests can be skipped by using the skip command at the point in a +test you wish to skip.

+ +
@test "A test I don't want to execute for now" {
+  skip
+  run foo
+  [ "$status" -eq 0 ]
+}
+
+ +

Optionally, you may include a reason for skipping:

+ +
@test "A test I don't want to execute for now" {
+  skip "This command will return zero soon, but not now"
+  run foo
+  [ "$status" -eq 0 ]
+}
+
+ +

Or you can skip conditionally:

+ +
@test "A test which should run" {
+  if [ foo != bar ]; then
+    skip "foo isn't bar"
+  fi
+
+  run foo
+  [ "$status" -eq 0 ]
+}
+
+ +

SETUP AND TEARDOWN FUNCTIONS

+ +

You can define special setup and teardown functions which run +before and after each test case, respectively. Use these to load +fixtures, set up your environment, and clean up when you're done.

+ +

CODE OUTSIDE OF TEST CASES

+ +

You can include code in your test file outside of @test functions. +For example, this may be useful if you want to check for dependencies +and fail immediately if they're not present. However, any output that +you print in code outside of @test, setup or teardown functions +must be redirected to stderr (>&2). Otherwise, the output may +cause Bats to fail by polluting the TAP stream on stdout.

+ +

SPECIAL VARIABLES

+ +

There are several global variables you can use to introspect on Bats +tests:

+ +
    +
  • $BATS_TEST_FILENAME is the fully expanded path to the Bats test +file.
  • +
  • $BATS_TEST_DIRNAME is the directory in which the Bats test file is +located.
  • +
  • $BATS_TEST_NAMES is an array of function names for each test case.
  • +
  • $BATS_TEST_NAME is the name of the function containing the current +test case.
  • +
  • $BATS_TEST_DESCRIPTION is the description of the current test +case.
  • +
  • $BATS_TEST_NUMBER is the (1-based) index of the current test case +in the test file.
  • +
  • $BATS_TMPDIR is the location to a directory that may be used to +store temporary files.
  • +
+ + +

SEE ALSO

+ +

bats(1)

+ + +
    +
  1. +
  2. November 2013
  3. +
  4. bats(7)
  5. +
+ +
+ + diff --git a/man/bats.7.ronn b/man/bats.7.ronn new file mode 100644 index 0000000..a24f189 --- /dev/null +++ b/man/bats.7.ronn @@ -0,0 +1,211 @@ +bats(7) -- Bats test file format +================================ + +SYNOPSIS +-------- + + load test_helper + + + setup() { + # set up your environment + # run before and after each test case + } + + teardown() { + # clean up your environment + # run before and after each test case + } + + + code_outside_of_test_cases () { + # For example, check for dependencies + # and fail immediatelyif they're not present. + # Output must be redirected to `stderr` (`>&2`) + } + + + @test "test description" { + run foo arguments + [ "$status" -eq 1 ] + [ "$output" = "expected output" ] + } + + @test "test description" { + run foo arguments + [ "$status" -eq 1 ] + [ "${lines[0]}" = "first line of expected output" ] + } + + + @test "A test I don't want to execute for now" { + skip "This command will return zero soon, but not now" + run foo + [ "$status" -eq 0 ] + } + + @test "A test which should run" { + if [ foo != bar ]; then + skip "foo isn't bar" + fi + + run foo + [ "$status" -eq 0 ] + } + + +DESCRIPTION +----------- + +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. + + #!/usr/bin/env bats + + @test "addition using bc" { + result="$(echo 2+2 | bc)" + [ "$result" -eq 4 ] + } + + @test "addition using dc" { + result="$(echo 2 2+p | dc)" + [ "$result" -eq 4 ] + } + + +Each Bats test file is evaulated n+1 times, where _n_ is the number of +test cases in the file. The first run counts the number of test cases, +then iterates over the test cases and executes each one in its own +process. + +For details about exactly how Bats evaluates test files, see +Bats Evaluation Process: +https://github.com/sstephenson/bats/wiki/Bats-Evaluation-Process + + +THE `_RUN_` HELPER +------------------ + +Many Bats tests need to run a command and then make assertions about +its exit status and output. Bats includes a `run` helper that invokes +its arguments as a command, saves the exit status and output into +special global variables, and then returns with a `0` status code so +you can continue to make assertions in your test case. + +For example, let's say you're testing that the `foo` command, when +passed a nonexistent filename, exits with a `1` status code and prints +an error message. + + @test "invoking foo with a nonexistent file prints an error" { + run foo nonexistent_filename + [ "$status" -eq 1 ] + [ "$output" = "foo: no such file 'nonexistent_filename'" ] + } + +The `$status` variable contains the status code of the command, and +the `$output` variable contains the combined contents of the command's +standard output and standard error streams. + +A third special variable, the `$lines` array, is available for easily +accessing individual lines of output. For example, if you want to test +that invoking `foo` without any arguments prints usage information on +the first line: + + @test "invoking foo without arguments prints usage" { run foo + [ "$status" -eq 1 ] + [ "${lines[0]}" = "usage: foo " ] + } + + +THE `_LOAD_` COMMAND +------------------ + +You may want to share common code across multiple test files. Bats +includes a convenient `load` command for sourcing a Bash source file +relative to the location of the current test file. For example, if you +have a Bats test in `test/foo.bats`, the command + + load test_helper + +will source the script `test/test_helper.bash` in your test file. This +can be useful for sharing functions to set up your environment or load +fixtures. + + +THE `_SKIP_` COMMAND +------------------ + +Tests can be skipped by using the `skip` command at the point in a +test you wish to skip. + + @test "A test I don't want to execute for now" { + skip + run foo + [ "$status" -eq 0 ] + } + +Optionally, you may include a reason for skipping: + + @test "A test I don't want to execute for now" { + skip "This command will return zero soon, but not now" + run foo + [ "$status" -eq 0 ] + } + +Or you can skip conditionally: + + @test "A test which should run" { + if [ foo != bar ]; then + skip "foo isn't bar" + fi + + run foo + [ "$status" -eq 0 ] + } + + +SETUP AND TEARDOWN FUNCTIONS +---------------------------- + +You can define special `setup` and `teardown` functions which run +before and after each test case, respectively. Use these to load +fixtures, set up your environment, and clean up when you're done. + + +CODE OUTSIDE OF TEST CASES +-------------------------- + +You can include code in your test file outside of `@test` functions. +For example, this may be useful if you want to check for dependencies +and fail immediately if they're not present. However, any output that +you print in code outside of `@test`, `setup` or `teardown` functions +must be redirected to `stderr` (`>&2`). Otherwise, the output may +cause Bats to fail by polluting the TAP stream on `stdout`. + + +SPECIAL VARIABLES +----------------- + +There are several global variables you can use to introspect on Bats +tests: + +* `$BATS_TEST_FILENAME` is the fully expanded path to the Bats test +file. +* `$BATS_TEST_DIRNAME` is the directory in which the Bats test file is +located. +* `$BATS_TEST_NAMES` is an array of function names for each test case. +* `$BATS_TEST_NAME` is the name of the function containing the current +test case. +* `$BATS_TEST_DESCRIPTION` is the description of the current test +case. +* `$BATS_TEST_NUMBER` is the (1-based) index of the current test case +in the test file. +* `$BATS_TMPDIR` is the location to a directory that may be used to +store temporary files. + + +SEE ALSO +-------- + +bats(1) diff --git a/man/index.txt b/man/index.txt new file mode 100644 index 0000000..21f2ac7 --- /dev/null +++ b/man/index.txt @@ -0,0 +1,3 @@ +# manuals +bats(1) bats.1.ronn +bats(7) bats.7.ronn