busser-bats 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,109 @@
1
+ bats(1) -- Bash Automated Testing System
2
+ ========================================
3
+
4
+
5
+ SYNOPSIS
6
+ --------
7
+
8
+ bats [-c] [-p | -t] <test> [<test> ...]
9
+
10
+ <test> is the path to a Bats test file, or the path to a directory
11
+ containing Bats test files.
12
+
13
+
14
+ DESCRIPTION
15
+ -----------
16
+
17
+ Bats is a TAP-compliant testing framework for Bash. It provides a simple
18
+ way to verify that the UNIX programs you write behave as expected.
19
+
20
+ A Bats test file is a Bash script with special syntax for defining
21
+ test cases. Under the hood, each test case is just a function with a
22
+ description.
23
+
24
+ Test cases consist of standard shell commands. Bats makes use of
25
+ Bash's `errexit` (`set -e`) option when running test cases. If every
26
+ command in the test case exits with a `0` status code (success), the
27
+ test passes. In this way, each line is an assertion of truth.
28
+
29
+ See `bats`(7) for more information on writing Bats tests.
30
+
31
+
32
+ RUNNING TESTS
33
+ -------------
34
+
35
+ To run your tests, invoke the `bats` interpreter with a path to a test
36
+ file. The file's test cases are run sequentially and in isolation. If
37
+ all the test cases pass, `bats` exits with a `0` status code. If there
38
+ are any failures, `bats` exits with a `1` status code.
39
+
40
+ You can invoke the `bats` interpreter with multiple test file arguments,
41
+ or with a path to a directory containing multiple `.bats` files. Bats
42
+ will run each test file individually and aggregate the results. If any
43
+ test case fails, `bats` exits with a `1` status code.
44
+
45
+
46
+ OPTIONS
47
+ -------
48
+
49
+ * `-c`, `--count`:
50
+ Count the number of test cases without running any tests
51
+ * `-h`, `--help`:
52
+ Display help message
53
+ * `-p`, `--pretty`:
54
+ Show results in pretty format (default for terminals)
55
+ * `-t`, `--tap`:
56
+ Show results in TAP format
57
+ * `-v`, `--version`:
58
+ Display the version number
59
+
60
+
61
+ OUTPUT
62
+ ------
63
+
64
+ When you run Bats from a terminal, you'll see output as each test is
65
+ performed, with a check-mark next to the test's name if it passes or
66
+ an "X" if it fails.
67
+
68
+ $ bats addition.bats
69
+ ✓ addition using bc
70
+ ✓ addition using dc
71
+
72
+ 2 tests, 0 failures
73
+
74
+ If Bats is not connected to a terminal--in other words, if you run it
75
+ from a continuous integration system or redirect its output to a
76
+ file--the results are displayed in human-readable, machine-parsable
77
+ TAP format. You can force TAP output from a terminal by invoking Bats
78
+ with the `--tap` option.
79
+
80
+ $ bats --tap addition.bats
81
+ 1..2
82
+ ok 1 addition using bc
83
+ ok 2 addition using dc
84
+
85
+
86
+ EXIT STATUS
87
+ -----------
88
+
89
+ The `bats` interpreter exits with a value of `0` if all test cases pass,
90
+ or `1` if one or more test cases fail.
91
+
92
+
93
+ SEE ALSO
94
+ --------
95
+
96
+ Bats wiki: _https://github.com/sstephenson/bats/wiki/_
97
+
98
+ `bash`(1), `bats`(7)
99
+
100
+
101
+ COPYRIGHT
102
+ ---------
103
+
104
+ (c) 2014 Sam Stephenson
105
+
106
+ Bats is released under the terms of an MIT-style license.
107
+
108
+
109
+
@@ -0,0 +1,178 @@
1
+ .\" generated with Ronn/v0.7.3
2
+ .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
+ .
4
+ .TH "BATS" "7" "November 2013" "" ""
5
+ .
6
+ .SH "NAME"
7
+ \fBbats\fR \- Bats test file format
8
+ .
9
+ .SH "DESCRIPTION"
10
+ 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\.
11
+ .
12
+ .IP "" 4
13
+ .
14
+ .nf
15
+
16
+ #!/usr/bin/env bats
17
+
18
+ @test "addition using bc" {
19
+ result="$(echo 2+2 | bc)"
20
+ [ "$result" \-eq 4 ]
21
+ }
22
+
23
+ @test "addition using dc" {
24
+ result="$(echo 2 2+p | dc)"
25
+ [ "$result" \-eq 4 ]
26
+ }
27
+ .
28
+ .fi
29
+ .
30
+ .IP "" 0
31
+ .
32
+ .P
33
+ Each Bats test file is evaluated 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\.
34
+ .
35
+ .SH "THE RUN HELPER"
36
+ 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\.
37
+ .
38
+ .P
39
+ 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\.
40
+ .
41
+ .IP "" 4
42
+ .
43
+ .nf
44
+
45
+ @test "invoking foo with a nonexistent file prints an error" {
46
+ run foo nonexistent_filename
47
+ [ "$status" \-eq 1 ]
48
+ [ "$output" = "foo: no such file \'nonexistent_filename\'" ]
49
+ }
50
+ .
51
+ .fi
52
+ .
53
+ .IP "" 0
54
+ .
55
+ .P
56
+ 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\.
57
+ .
58
+ .P
59
+ 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:
60
+ .
61
+ .IP "" 4
62
+ .
63
+ .nf
64
+
65
+ @test "invoking foo without arguments prints usage" {
66
+ run foo
67
+ [ "$status" \-eq 1 ]
68
+ [ "${lines[0]}" = "usage: foo <filename>" ]
69
+ }
70
+ .
71
+ .fi
72
+ .
73
+ .IP "" 0
74
+ .
75
+ .SH "THE LOAD COMMAND"
76
+ 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
77
+ .
78
+ .IP "" 4
79
+ .
80
+ .nf
81
+
82
+ load test_helper
83
+ .
84
+ .fi
85
+ .
86
+ .IP "" 0
87
+ .
88
+ .P
89
+ 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\.
90
+ .
91
+ .SH "THE SKIP COMMAND"
92
+ Tests can be skipped by using the \fBskip\fR command at the point in a test you wish to skip\.
93
+ .
94
+ .IP "" 4
95
+ .
96
+ .nf
97
+
98
+ @test "A test I don\'t want to execute for now" {
99
+ skip
100
+ run foo
101
+ [ "$status" \-eq 0 ]
102
+ }
103
+ .
104
+ .fi
105
+ .
106
+ .IP "" 0
107
+ .
108
+ .P
109
+ Optionally, you may include a reason for skipping:
110
+ .
111
+ .IP "" 4
112
+ .
113
+ .nf
114
+
115
+ @test "A test I don\'t want to execute for now" {
116
+ skip "This command will return zero soon, but not now"
117
+ run foo
118
+ [ "$status" \-eq 0 ]
119
+ }
120
+ .
121
+ .fi
122
+ .
123
+ .IP "" 0
124
+ .
125
+ .P
126
+ Or you can skip conditionally:
127
+ .
128
+ .IP "" 4
129
+ .
130
+ .nf
131
+
132
+ @test "A test which should run" {
133
+ if [ foo != bar ]; then
134
+ skip "foo isn\'t bar"
135
+ fi
136
+
137
+ run foo
138
+ [ "$status" \-eq 0 ]
139
+ }
140
+ .
141
+ .fi
142
+ .
143
+ .IP "" 0
144
+ .
145
+ .SH "SETUP AND TEARDOWN FUNCTIONS"
146
+ 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\.
147
+ .
148
+ .SH "CODE OUTSIDE OF TEST CASES"
149
+ 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\.
150
+ .
151
+ .SH "SPECIAL VARIABLES"
152
+ There are several global variables you can use to introspect on Bats tests:
153
+ .
154
+ .IP "\(bu" 4
155
+ \fB$BATS_TEST_FILENAME\fR is the fully expanded path to the Bats test file\.
156
+ .
157
+ .IP "\(bu" 4
158
+ \fB$BATS_TEST_DIRNAME\fR is the directory in which the Bats test file is located\.
159
+ .
160
+ .IP "\(bu" 4
161
+ \fB$BATS_TEST_NAMES\fR is an array of function names for each test case\.
162
+ .
163
+ .IP "\(bu" 4
164
+ \fB$BATS_TEST_NAME\fR is the name of the function containing the current test case\.
165
+ .
166
+ .IP "\(bu" 4
167
+ \fB$BATS_TEST_DESCRIPTION\fR is the description of the current test case\.
168
+ .
169
+ .IP "\(bu" 4
170
+ \fB$BATS_TEST_NUMBER\fR is the (1\-based) index of the current test case in the test file\.
171
+ .
172
+ .IP "\(bu" 4
173
+ \fB$BATS_TMPDIR\fR is the location to a directory that may be used to store temporary files\.
174
+ .
175
+ .IP "" 0
176
+ .
177
+ .SH "SEE ALSO"
178
+ \fBbash\fR(1), \fBbats\fR(1)
@@ -0,0 +1,156 @@
1
+ bats(7) -- Bats test file format
2
+ ================================
3
+
4
+
5
+ DESCRIPTION
6
+ -----------
7
+
8
+ A Bats test file is a Bash script with special syntax for defining
9
+ test cases. Under the hood, each test case is just a function with a
10
+ description.
11
+
12
+ #!/usr/bin/env bats
13
+
14
+ @test "addition using bc" {
15
+ result="$(echo 2+2 | bc)"
16
+ [ "$result" -eq 4 ]
17
+ }
18
+
19
+ @test "addition using dc" {
20
+ result="$(echo 2 2+p | dc)"
21
+ [ "$result" -eq 4 ]
22
+ }
23
+
24
+
25
+ Each Bats test file is evaluated n+1 times, where _n_ is the number of
26
+ test cases in the file. The first run counts the number of test cases,
27
+ then iterates over the test cases and executes each one in its own
28
+ process.
29
+
30
+
31
+ THE RUN HELPER
32
+ --------------
33
+
34
+ Many Bats tests need to run a command and then make assertions about
35
+ its exit status and output. Bats includes a `run` helper that invokes
36
+ its arguments as a command, saves the exit status and output into
37
+ special global variables, and then returns with a `0` status code so
38
+ you can continue to make assertions in your test case.
39
+
40
+ For example, let's say you're testing that the `foo` command, when
41
+ passed a nonexistent filename, exits with a `1` status code and prints
42
+ an error message.
43
+
44
+ @test "invoking foo with a nonexistent file prints an error" {
45
+ run foo nonexistent_filename
46
+ [ "$status" -eq 1 ]
47
+ [ "$output" = "foo: no such file 'nonexistent_filename'" ]
48
+ }
49
+
50
+ The `$status` variable contains the status code of the command, and
51
+ the `$output` variable contains the combined contents of the command's
52
+ standard output and standard error streams.
53
+
54
+ A third special variable, the `$lines` array, is available for easily
55
+ accessing individual lines of output. For example, if you want to test
56
+ that invoking `foo` without any arguments prints usage information on
57
+ the first line:
58
+
59
+ @test "invoking foo without arguments prints usage" {
60
+ run foo
61
+ [ "$status" -eq 1 ]
62
+ [ "${lines[0]}" = "usage: foo <filename>" ]
63
+ }
64
+
65
+
66
+ THE LOAD COMMAND
67
+ ----------------
68
+
69
+ You may want to share common code across multiple test files. Bats
70
+ includes a convenient `load` command for sourcing a Bash source file
71
+ relative to the location of the current test file. For example, if you
72
+ have a Bats test in `test/foo.bats`, the command
73
+
74
+ load test_helper
75
+
76
+ will source the script `test/test_helper.bash` in your test file. This
77
+ can be useful for sharing functions to set up your environment or load
78
+ fixtures.
79
+
80
+
81
+ THE SKIP COMMAND
82
+ ----------------
83
+
84
+ Tests can be skipped by using the `skip` command at the point in a
85
+ test you wish to skip.
86
+
87
+ @test "A test I don't want to execute for now" {
88
+ skip
89
+ run foo
90
+ [ "$status" -eq 0 ]
91
+ }
92
+
93
+ Optionally, you may include a reason for skipping:
94
+
95
+ @test "A test I don't want to execute for now" {
96
+ skip "This command will return zero soon, but not now"
97
+ run foo
98
+ [ "$status" -eq 0 ]
99
+ }
100
+
101
+ Or you can skip conditionally:
102
+
103
+ @test "A test which should run" {
104
+ if [ foo != bar ]; then
105
+ skip "foo isn't bar"
106
+ fi
107
+
108
+ run foo
109
+ [ "$status" -eq 0 ]
110
+ }
111
+
112
+
113
+ SETUP AND TEARDOWN FUNCTIONS
114
+ ----------------------------
115
+
116
+ You can define special `setup` and `teardown` functions which run
117
+ before and after each test case, respectively. Use these to load
118
+ fixtures, set up your environment, and clean up when you're done.
119
+
120
+
121
+ CODE OUTSIDE OF TEST CASES
122
+ --------------------------
123
+
124
+ You can include code in your test file outside of `@test` functions.
125
+ For example, this may be useful if you want to check for dependencies
126
+ and fail immediately if they're not present. However, any output that
127
+ you print in code outside of `@test`, `setup` or `teardown` functions
128
+ must be redirected to `stderr` (`>&2`). Otherwise, the output may
129
+ cause Bats to fail by polluting the TAP stream on `stdout`.
130
+
131
+
132
+ SPECIAL VARIABLES
133
+ -----------------
134
+
135
+ There are several global variables you can use to introspect on Bats
136
+ tests:
137
+
138
+ * `$BATS_TEST_FILENAME` is the fully expanded path to the Bats test
139
+ file.
140
+ * `$BATS_TEST_DIRNAME` is the directory in which the Bats test file is
141
+ located.
142
+ * `$BATS_TEST_NAMES` is an array of function names for each test case.
143
+ * `$BATS_TEST_NAME` is the name of the function containing the current
144
+ test case.
145
+ * `$BATS_TEST_DESCRIPTION` is the description of the current test
146
+ case.
147
+ * `$BATS_TEST_NUMBER` is the (1-based) index of the current test case
148
+ in the test file.
149
+ * `$BATS_TMPDIR` is the location to a directory that may be used to
150
+ store temporary files.
151
+
152
+
153
+ SEE ALSO
154
+ --------
155
+
156
+ `bash`(1), `bats`(1)
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "bats",
3
+ "version": "0.3.1",
4
+ "description": "Bash Automated Testing System",
5
+ "global": "true",
6
+ "install": "./install.sh /usr/local",
7
+ "scripts": [ "libexec/bats", "libexec/bats-exec-suite", "libexec/bats-exec-test", "libexec/bats-format-tap-stream", "libexec/bats-preprocess", "bin/bats" ]
8
+ }
9
+