From 225440bb65c258fc5b178cb8462ddb7ae433ea6f Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sun, 10 Nov 2013 16:03:38 -0600 Subject: [PATCH] Update the man pages --- man/bats.1 | 37 ++++-- man/bats.1.html | 156 -------------------------- man/bats.1.ronn | 72 +++++++----- man/bats.7 | 69 +----------- man/bats.7.html | 290 ------------------------------------------------ man/bats.7.ronn | 73 ++---------- man/index.txt | 3 - 7 files changed, 88 insertions(+), 612 deletions(-) delete mode 100644 man/bats.1.html delete mode 100644 man/bats.7.html delete mode 100644 man/index.txt diff --git a/man/bats.1 b/man/bats.1 index f6455ab..34260d4 100644 --- a/man/bats.1 +++ b/man/bats.1 @@ -9,13 +9,22 @@ .SH "SYNOPSIS" bats [\-c] [\-p | \-t] \fItest\fR [\fItest\fR \.\.\.] . +.P +\fItest\fR is the path to a Bats test file, or the path to a directory containing Bats test files\. +. .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\. +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\. . -.SH "FILES" +.P +Test cases consist of standard shell commands\. Bats makes use of Bash\'s \fBerrexit\fR (\fBset \-e\fR) option when running test cases\. If every command in the test case exits with a \fB0\fR status code (success), the test passes\. In this way, each line is an assertion of truth\. +. +.P +See \fBbats\fR(7) for more information on writing Bats tests\. +. +.SH "RUNNING TESTS" 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 @@ -29,7 +38,7 @@ Count the number of test cases without running any tests . .TP \fB\-h\fR, \fB\-\-help\fR -Display this help message +Display help message . .TP \fB\-p\fR, \fB\-\-pretty\fR @@ -43,7 +52,7 @@ Show results in TAP format \fB\-v\fR, \fB\-\-version\fR Display the version number . -.SH "EXAMPLES" +.SH "OUTPUT" 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 @@ -61,7 +70,7 @@ $ bats addition\.bats .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\. +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 \fB\-\-tap\fR option\. . .IP "" 4 . @@ -76,11 +85,17 @@ ok 2 addition using dc . .IP "" 0 . -.SH "COPYRIGHT" -(c) 2013 Sam Stephenson\. -. -.P -Bats is released under an MIT\-style license +.SH "EXIT STATUS" +The \fBbats\fR interpreter exits with a value of \fB0\fR if all test cases pass, or \fB1\fR if one or more test cases fail\. . .SH "SEE ALSO" -bats(7) +Bats wiki: \fIhttps://github\.com/sstephenson/bats/wiki/\fR +. +.P +\fBbash\fR(1), \fBbats\fR(7) +. +.SH "COPYRIGHT" +(c) 2013 Sam Stephenson +. +.P +Bats is released under the terms of an MIT\-style license\. diff --git a/man/bats.1.html b/man/bats.1.html deleted file mode 100644 index 56f972a..0000000 --- a/man/bats.1.html +++ /dev/null @@ -1,156 +0,0 @@ - - - - - - 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 index 41e57b7..d31720e 100644 --- a/man/bats.1.ronn +++ b/man/bats.1.ronn @@ -1,34 +1,46 @@ bats(1) -- Bash Automated Testing System ======================================== + SYNOPSIS -------- bats [-c] [-p | -t] [ ...] + is the path to a Bats test file, or the path to a directory +containing Bats test files. + 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 a TAP-compliant testing framework for Bash. -It provides a simple way to verify that the UNIX programs you write behave as expected. +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. -Bats is most useful when testing software written in Bash, but you can use it to test any UNIX program. +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. + +See `bats`(7) for more information on writing Bats tests. -FILES ------ +RUNNING TESTS +------------- 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. +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 @@ -37,7 +49,7 @@ OPTIONS * `-c`, `--count`: Count the number of test cases without running any tests * `-h`, `--help`: - Display this help message + Display help message * `-p`, `--pretty`: Show results in pretty format (default for terminals) * `-t`, `--tap`: @@ -45,10 +57,9 @@ OPTIONS * `-v`, `--version`: Display the version number - -EXAMPLES --------- +OUTPUT +------ 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 @@ -60,12 +71,11 @@ an "X" if it fails. 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. +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 @@ -73,15 +83,27 @@ You can force TAP output from a terminal by invoking Bats with the ok 2 addition using dc -COPYRIGHT ---------- +EXIT STATUS +----------- -(c) 2013 Sam Stephenson. - -Bats is released under an MIT-style license +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(7) +Bats wiki: _https://github.com/sstephenson/bats/wiki/_ + +`bash`(1), `bats`(7) + + +COPYRIGHT +--------- + +(c) 2013 Sam Stephenson + +Bats is released under the terms of an MIT-style license. + + + diff --git a/man/bats.7 b/man/bats.7 index 449b570..47836ef 100644 --- a/man/bats.7 +++ b/man/bats.7 @@ -6,61 +6,6 @@ .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\. . @@ -87,10 +32,7 @@ A Bats test file is a Bash script with special syntax for defining test cases\. .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" +.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 @@ -120,7 +62,8 @@ A third special variable, the \fB$lines\fR array, is available for easily access . .nf -@test "invoking foo without arguments prints usage" { run foo +@test "invoking foo without arguments prints usage" { + run foo [ "$status" \-eq 1 ] [ "${lines[0]}" = "usage: foo " ] } @@ -129,7 +72,7 @@ A third special variable, the \fB$lines\fR array, is available for easily access . .IP "" 0 . -.SH "THE _LOAD_ COMMAND" +.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 @@ -145,7 +88,7 @@ load test_helper .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" +.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 @@ -232,4 +175,4 @@ There are several global variables you can use to introspect on Bats tests: .IP "" 0 . .SH "SEE ALSO" -bats(1) +\fBbash\fR(1), \fBbats\fR(1) diff --git a/man/bats.7.html b/man/bats.7.html deleted file mode 100644 index 668b15f..0000000 --- a/man/bats.7.html +++ /dev/null @@ -1,290 +0,0 @@ - - - - - - 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 index a24f189..e5377a4 100644 --- a/man/bats.7.ronn +++ b/man/bats.7.ronn @@ -1,58 +1,6 @@ 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 ----------- @@ -79,13 +27,9 @@ 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 ------------------- +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 @@ -112,14 +56,15 @@ 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 + @test "invoking foo without arguments prints usage" { + run foo [ "$status" -eq 1 ] [ "${lines[0]}" = "usage: foo " ] } -THE `_LOAD_` COMMAND ------------------- +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 @@ -133,8 +78,8 @@ can be useful for sharing functions to set up your environment or load fixtures. -THE `_SKIP_` COMMAND ------------------- +THE SKIP COMMAND +---------------- Tests can be skipped by using the `skip` command at the point in a test you wish to skip. @@ -208,4 +153,4 @@ store temporary files. SEE ALSO -------- -bats(1) +`bash`(1), `bats`(1) diff --git a/man/index.txt b/man/index.txt deleted file mode 100644 index 21f2ac7..0000000 --- a/man/index.txt +++ /dev/null @@ -1,3 +0,0 @@ -# manuals -bats(1) bats.1.ronn -bats(7) bats.7.ronn