busser-bats 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +10 -0
- data/README.md +4 -2
- data/Rakefile +38 -0
- data/busser-bats.gemspec +1 -1
- data/lib/busser/bats/version.rb +1 -1
- data/lib/busser/runner_plugin/bats.rb +3 -13
- data/vendor/bats/.gitattributes +3 -0
- data/vendor/bats/LICENSE +20 -0
- data/vendor/bats/README.md +272 -0
- data/vendor/bats/VERSION.txt +1 -0
- data/vendor/bats/bin/bats +140 -0
- data/vendor/bats/install.sh +35 -0
- data/vendor/bats/libexec/bats +140 -0
- data/vendor/bats/libexec/bats-exec-suite +55 -0
- data/vendor/bats/libexec/bats-exec-test +205 -0
- data/vendor/bats/libexec/bats-format-tap-stream +158 -0
- data/vendor/bats/libexec/bats-preprocess +51 -0
- metadata +37 -48
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 18630d2d9565f35fc8ff4775d029ad7f673f2b27
|
4
|
+
data.tar.gz: 595d8d03ac3def1fb0bb04a2d3da5a6552aac118
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 63d6b127a618ea52cb66ec622460f81de14f7f22381049e5ac9ef0b79cf23d7f10bde35e501d2d77f61de211a09b134d4c489c11eb7738a882e44271773bd68c
|
7
|
+
data.tar.gz: 94435202e166dae20daafaefcb08552fb74f324d017eb323b6ed0bc5d724c1c80a2a5da5de6814bba19ab24555ab233bf17cb8683f637446a830a31859029e9f
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
## 0.2.0 / 2014-03-23
|
2
|
+
|
3
|
+
### Improvements
|
4
|
+
|
5
|
+
* Vendor a copy of Bats locally (v0.3.1) to speed & simplify plugin installations. ([@fnichol][])
|
6
|
+
|
7
|
+
|
1
8
|
## 0.1.0 / 2013-04-10
|
2
9
|
|
3
10
|
* Initial release
|
11
|
+
|
12
|
+
<!--- The following link definition list is generated by PimpMyChangelog --->
|
13
|
+
[@fnichol]: https://github.com/fnichol
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# <a name="title"></a> Busser::RunnerPlugin::Bats
|
2
2
|
|
3
|
-
[](https://travis-ci.org/test-kitchen/busser-bats)
|
4
|
+
[](https://codeclimate.com/github/test-kitchen/busser-bats)
|
5
5
|
|
6
6
|
A Busser runner plugin for [Bats][bats_site]
|
7
7
|
|
@@ -36,6 +36,8 @@ Created and maintained by [Fletcher Nichol][author] (<fnichol@nichol.ca>)
|
|
36
36
|
|
37
37
|
Apache 2.0 (see [LICENSE][license])
|
38
38
|
|
39
|
+
[Bats][bats_site] is released under an MIT-style license, copyright Sam Stephenson.
|
40
|
+
|
39
41
|
|
40
42
|
[author]: https://github.com/fnichol
|
41
43
|
[issues]: https://github.com/fnichol/busser-bats/issues
|
data/Rakefile
CHANGED
@@ -1,8 +1,46 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
require 'cucumber/rake/task'
|
3
3
|
require 'cane/rake_task'
|
4
|
+
require 'open-uri'
|
4
5
|
require 'tailor/rake_task'
|
5
6
|
|
7
|
+
namespace :bats do
|
8
|
+
|
9
|
+
version = ENV.fetch("BATS_VERSION", "v0.3.1")
|
10
|
+
url = "https://github.com/sstephenson/bats/archive/#{version}.tar.gz"
|
11
|
+
tarball = "tmp/bats-#{version}.tar.gz"
|
12
|
+
vendor = "vendor/bats"
|
13
|
+
|
14
|
+
desc "Vendors bats #{version} source code into gem codebase"
|
15
|
+
task :vendor => "#{vendor}/VERSION.txt"
|
16
|
+
|
17
|
+
directory File.dirname(tarball)
|
18
|
+
directory vendor
|
19
|
+
|
20
|
+
file tarball => File.dirname(tarball) do |t|
|
21
|
+
begin
|
22
|
+
src = open(url).binmode
|
23
|
+
dst = open(t.name, "wb")
|
24
|
+
IO.copy_stream(src, dst)
|
25
|
+
ensure
|
26
|
+
src.close
|
27
|
+
dst.close
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
file "#{vendor}/VERSION.txt" => [vendor, tarball] do |t|
|
32
|
+
abs_tarball = File.expand_path(tarball)
|
33
|
+
Dir.chdir(vendor) { sh "tar xzf #{abs_tarball} --strip-components=1" }
|
34
|
+
rm_rf "#{vendor}/test"
|
35
|
+
IO.write(t.name, url + "\n")
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "Clean up a vendored bats in preparation for a new vendored version"
|
39
|
+
task :clean do
|
40
|
+
rm_rf [vendor, tarball]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
6
44
|
Cucumber::Rake::Task.new(:features) do |t|
|
7
45
|
t.cucumber_opts = ['features', '-x', '--format progress']
|
8
46
|
end
|
data/busser-bats.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ['fnichol@nichol.ca']
|
11
11
|
spec.description = %q{A Busser runner plugin for Bats}
|
12
12
|
spec.summary = spec.description
|
13
|
-
spec.homepage = 'https://github.com/
|
13
|
+
spec.homepage = 'https://github.com/test-kitchen/busser-bats'
|
14
14
|
spec.license = 'Apache 2.0'
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
data/lib/busser/bats/version.rb
CHANGED
@@ -17,7 +17,6 @@
|
|
17
17
|
# limitations under the License.
|
18
18
|
|
19
19
|
require 'pathname'
|
20
|
-
require 'tmpdir'
|
21
20
|
|
22
21
|
require 'busser/runner_plugin'
|
23
22
|
|
@@ -28,19 +27,10 @@ require 'busser/runner_plugin'
|
|
28
27
|
class Busser::RunnerPlugin::Bats < Busser::RunnerPlugin::Base
|
29
28
|
|
30
29
|
postinstall do
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
extract_root = tmp_root.join("bats")
|
35
|
-
dest_path = vendor_path("bats")
|
36
|
-
|
37
|
-
empty_directory(extract_root)
|
38
|
-
get(tarball_url, tarball_file)
|
39
|
-
inside(extract_root) do
|
40
|
-
run!(%{gunzip -c "#{tarball_file}" | tar xf - --strip-components=1})
|
41
|
-
run!(%{./install.sh #{dest_path}})
|
30
|
+
inside(Pathname.new(__FILE__).dirname.join("../../../vendor/bats")) do
|
31
|
+
FileUtils.ln_sf("../libexec/bats", "bin/bats")
|
32
|
+
run!(%{./install.sh #{vendor_path("bats")}})
|
42
33
|
end
|
43
|
-
remove_dir(tmp_root)
|
44
34
|
end
|
45
35
|
|
46
36
|
def test
|
data/vendor/bats/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Sam Stephenson
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,272 @@
|
|
1
|
+
# Bats: Bash Automated Testing System
|
2
|
+
|
3
|
+
Bats is a [TAP](http://testanything.org/)-compliant testing framework
|
4
|
+
for Bash. It provides a simple way to verify that the UNIX programs
|
5
|
+
you write behave as expected.
|
6
|
+
|
7
|
+
A Bats test file is a Bash script with special syntax for defining
|
8
|
+
test cases. Under the hood, each test case is just a function with a
|
9
|
+
description.
|
10
|
+
|
11
|
+
```bash
|
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
|
+
Bats is most useful when testing software written in Bash, but you can
|
26
|
+
use it to test any UNIX program.
|
27
|
+
|
28
|
+
Test cases consist of standard shell commands. Bats makes use of
|
29
|
+
Bash's `errexit` (`set -e`) option when running test cases. If every
|
30
|
+
command in the test case exits with a `0` status code (success), the
|
31
|
+
test passes. In this way, each line is an assertion of truth.
|
32
|
+
|
33
|
+
## Running tests
|
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
|
+
When you run Bats from a terminal, you'll see output as each test is
|
41
|
+
performed, with a check-mark next to the test's name if it passes or
|
42
|
+
an "X" if it fails.
|
43
|
+
|
44
|
+
$ bats addition.bats
|
45
|
+
✓ addition using bc
|
46
|
+
✓ addition using dc
|
47
|
+
|
48
|
+
2 tests, 0 failures
|
49
|
+
|
50
|
+
If Bats is not connected to a terminal—in other words, if you
|
51
|
+
run it from a continuous integration system or redirect its output to
|
52
|
+
a file—the results are displayed in human-readable, machine-parsable
|
53
|
+
[TAP format](http://testanything.org/wiki/index.php/TAP_specification#THE_TAP_FORMAT).
|
54
|
+
You can force TAP output from a terminal by invoking Bats with the
|
55
|
+
`--tap` option.
|
56
|
+
|
57
|
+
$ bats --tap addition.bats
|
58
|
+
1..2
|
59
|
+
ok 1 addition using bc
|
60
|
+
ok 2 addition using dc
|
61
|
+
|
62
|
+
### Test suites
|
63
|
+
|
64
|
+
You can invoke the `bats` interpreter with multiple test file
|
65
|
+
arguments, or with a path to a directory containing multiple `.bats`
|
66
|
+
files. Bats will run each test file individually and aggregate the
|
67
|
+
results. If any test case fails, `bats` exits with a `1` status code.
|
68
|
+
|
69
|
+
## Writing tests
|
70
|
+
|
71
|
+
Each Bats test file is evaulated n+1 times, where _n_ is the number of
|
72
|
+
test cases in the file. The first run counts the number of test cases,
|
73
|
+
then iterates over the test cases and executes each one in its own
|
74
|
+
process.
|
75
|
+
|
76
|
+
For details about exactly how Bats evaluates test files, see [Bats
|
77
|
+
Evaluation Process](https://github.com/sstephenson/bats/wiki/Bats-Evaluation-Process)
|
78
|
+
on the wiki.
|
79
|
+
|
80
|
+
### The _run_ helper
|
81
|
+
|
82
|
+
Many Bats tests need to run a command and then make assertions about
|
83
|
+
its exit status and output. Bats includes a `run` helper that invokes
|
84
|
+
its arguments as a command, saves the exit status and output into
|
85
|
+
special global variables, and then returns with a `0` status code so
|
86
|
+
you can continue to make assertions in your test case.
|
87
|
+
|
88
|
+
For example, let's say you're testing that the `foo` command, when
|
89
|
+
passed a nonexistent filename, exits with a `1` status code and prints
|
90
|
+
an error message.
|
91
|
+
|
92
|
+
```bash
|
93
|
+
@test "invoking foo with a nonexistent file prints an error" {
|
94
|
+
run foo nonexistent_filename
|
95
|
+
[ "$status" -eq 1 ]
|
96
|
+
[ "$output" = "foo: no such file 'nonexistent_filename'" ]
|
97
|
+
}
|
98
|
+
```
|
99
|
+
|
100
|
+
The `$status` variable contains the status code of the command, and
|
101
|
+
the `$output` variable contains the combined contents of the command's
|
102
|
+
standard output and standard error streams.
|
103
|
+
|
104
|
+
A third special variable, the `$lines` array, is available for easily
|
105
|
+
accessing individual lines of output. For example, if you want to test
|
106
|
+
that invoking `foo` without any arguments prints usage information on
|
107
|
+
the first line:
|
108
|
+
|
109
|
+
```bash
|
110
|
+
@test "invoking foo without arguments prints usage" {
|
111
|
+
run foo
|
112
|
+
[ "$status" -eq 1 ]
|
113
|
+
[ "${lines[0]}" = "usage: foo <filename>" ]
|
114
|
+
}
|
115
|
+
```
|
116
|
+
|
117
|
+
### The _load_ command
|
118
|
+
|
119
|
+
You may want to share common code across multiple test files. Bats
|
120
|
+
includes a convenient `load` command for sourcing a Bash source file
|
121
|
+
relative to the location of the current test file. For example, if you
|
122
|
+
have a Bats test in `test/foo.bats`, the command
|
123
|
+
|
124
|
+
```bash
|
125
|
+
load test_helper
|
126
|
+
```
|
127
|
+
|
128
|
+
will source the script `test/test_helper.bash` in your test file. This
|
129
|
+
can be useful for sharing functions to set up your environment or load
|
130
|
+
fixtures.
|
131
|
+
|
132
|
+
### The _skip_ command
|
133
|
+
|
134
|
+
Tests can be skipped by using the `skip` command at the point in a
|
135
|
+
test you wish to skip.
|
136
|
+
|
137
|
+
```bash
|
138
|
+
@test "A test I don't want to execute for now" {
|
139
|
+
skip
|
140
|
+
run foo
|
141
|
+
[ "$status" -eq 0 ]
|
142
|
+
}
|
143
|
+
```
|
144
|
+
|
145
|
+
Optionally, you may include a reason for skipping:
|
146
|
+
|
147
|
+
```bash
|
148
|
+
@test "A test I don't want to execute for now" {
|
149
|
+
skip "This command will return zero soon, but not now"
|
150
|
+
run foo
|
151
|
+
[ "$status" -eq 0 ]
|
152
|
+
}
|
153
|
+
```
|
154
|
+
|
155
|
+
Or you can skip conditionally:
|
156
|
+
|
157
|
+
```bash
|
158
|
+
@test "A test which should run" {
|
159
|
+
if [ foo != bar ]; then
|
160
|
+
skip "foo isn't bar"
|
161
|
+
fi
|
162
|
+
|
163
|
+
run foo
|
164
|
+
[ "$status" -eq 0 ]
|
165
|
+
}
|
166
|
+
```
|
167
|
+
|
168
|
+
### Setup and teardown functions
|
169
|
+
|
170
|
+
You can define special `setup` and `teardown` functions which run
|
171
|
+
before and after each test case, respectively. Use these to load
|
172
|
+
fixtures, set up your environment, and clean up when you're done.
|
173
|
+
|
174
|
+
### Code outside of test cases
|
175
|
+
|
176
|
+
You can include code in your test file outside of `@test` functions.
|
177
|
+
For example, this may be useful if you want to check for dependencies
|
178
|
+
and fail immediately if they're not present. However, any output that
|
179
|
+
you print in code outside of `@test`, `setup` or `teardown` functions
|
180
|
+
must be redirected to `stderr` (`>&2`). Otherwise, the output may
|
181
|
+
cause Bats to fail by polluting the TAP stream on `stdout`.
|
182
|
+
|
183
|
+
### Special variables
|
184
|
+
|
185
|
+
There are several global variables you can use to introspect on Bats
|
186
|
+
tests:
|
187
|
+
|
188
|
+
* `$BATS_TEST_FILENAME` is the fully expanded path to the Bats test
|
189
|
+
file.
|
190
|
+
* `$BATS_TEST_DIRNAME` is the directory in which the Bats test file is
|
191
|
+
located.
|
192
|
+
* `$BATS_TEST_NAMES` is an array of function names for each test case.
|
193
|
+
* `$BATS_TEST_NAME` is the name of the function containing the current
|
194
|
+
test case.
|
195
|
+
* `$BATS_TEST_DESCRIPTION` is the description of the current test
|
196
|
+
case.
|
197
|
+
* `$BATS_TEST_NUMBER` is the (1-based) index of the current test case
|
198
|
+
in the test file.
|
199
|
+
* `$BATS_TMPDIR` is the location to a directory that may be used to
|
200
|
+
store temporary files.
|
201
|
+
|
202
|
+
## Installing Bats from source
|
203
|
+
|
204
|
+
Check out a copy of the Bats repository. Then, either add the Bats
|
205
|
+
`bin` directory to your `$PATH`, or run the provided `install.sh`
|
206
|
+
command with the location to the prefix in which you want to install
|
207
|
+
Bats. For example, to install Bats into `/usr/local`,
|
208
|
+
|
209
|
+
$ git clone https://github.com/sstephenson/bats.git
|
210
|
+
$ cd bats
|
211
|
+
$ ./install.sh /usr/local
|
212
|
+
|
213
|
+
Note that you may need to run `install.sh` with `sudo` if you do not
|
214
|
+
have permission to write to the installation prefix.
|
215
|
+
|
216
|
+
## Support
|
217
|
+
|
218
|
+
The Bats source code repository is [hosted on
|
219
|
+
GitHub](https://github.com/sstephenson/bats). There you can file bugs
|
220
|
+
on the issue tracker or submit tested pull requests for review.
|
221
|
+
|
222
|
+
For real-world examples from open-source projects using Bats, see
|
223
|
+
[Projects Using Bats](https://github.com/sstephenson/bats/wiki/Projects-Using-Bats)
|
224
|
+
on the wiki.
|
225
|
+
|
226
|
+
To learn how to set up your editor for Bats syntax highlighting, see
|
227
|
+
[Syntax Highlighting](https://github.com/sstephenson/bats/wiki/Syntax-Highlighting)
|
228
|
+
on the wiki.
|
229
|
+
|
230
|
+
### Version history
|
231
|
+
|
232
|
+
*0.3.1* (October 28, 2013)
|
233
|
+
|
234
|
+
* Fixed an incompatibility with the pretty formatter in certain
|
235
|
+
environments such as tmux.
|
236
|
+
* Fixed a bug where the pretty formatter would crash if the first line
|
237
|
+
of a test file's output was invalid TAP.
|
238
|
+
|
239
|
+
*0.3.0* (October 21, 2013)
|
240
|
+
|
241
|
+
* Improved formatting for tests run from a terminal. Failing tests
|
242
|
+
are now colored in red, and the total number of failing tests is
|
243
|
+
displayed at the end of the test run. When Bats is not connected to
|
244
|
+
a terminal (e.g. in CI runs), or when invoked with the `--tap` flag,
|
245
|
+
output is displayed in standard TAP format.
|
246
|
+
* Added the ability to skip tests using the `skip` command.
|
247
|
+
* Added a message to failing test case output indicating the file and
|
248
|
+
line number of the statement that caused the test to fail.
|
249
|
+
* Added "ad-hoc" test suite support. You can now invoke `bats` with
|
250
|
+
multiple filename or directory arguments to run all the specified
|
251
|
+
tests in aggregate.
|
252
|
+
* Added support for test files with Windows line endings.
|
253
|
+
* Fixed regular expression warnings from certain versions of Bash.
|
254
|
+
* Fixed a bug running tests containing lines that begin with `-e`.
|
255
|
+
|
256
|
+
*0.2.0* (November 16, 2012)
|
257
|
+
|
258
|
+
* Added test suite support. The `bats` command accepts a directory
|
259
|
+
name containing multiple test files to be run in aggregate.
|
260
|
+
* Added the ability to count the number of test cases in a file or
|
261
|
+
suite by passing the `-c` flag to `bats`.
|
262
|
+
* Preprocessed sources are cached between test case runs in the same
|
263
|
+
file for better performance.
|
264
|
+
|
265
|
+
*0.1.0* (December 30, 2011)
|
266
|
+
|
267
|
+
* Initial public release.
|
268
|
+
|
269
|
+
---
|
270
|
+
|
271
|
+
© 2013 Sam Stephenson. Bats is released under an MIT-style license;
|
272
|
+
see `LICENSE` for details.
|
@@ -0,0 +1 @@
|
|
1
|
+
https://github.com/sstephenson/bats/archive/v0.3.1.tar.gz
|
@@ -0,0 +1,140 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
set -e
|
3
|
+
|
4
|
+
version() {
|
5
|
+
echo "Bats 0.3.1"
|
6
|
+
}
|
7
|
+
|
8
|
+
usage() {
|
9
|
+
version
|
10
|
+
echo "Usage: bats [-c] [-p | -t] <test> [<test> ...]"
|
11
|
+
}
|
12
|
+
|
13
|
+
help() {
|
14
|
+
usage
|
15
|
+
echo
|
16
|
+
echo " <test> is the path to a Bats test file, or the path to a directory"
|
17
|
+
echo " containing Bats test files."
|
18
|
+
echo
|
19
|
+
echo " -c, --count Count the number of test cases without running any tests"
|
20
|
+
echo " -h, --help Display this help message"
|
21
|
+
echo " -p, --pretty Show results in pretty format (default for terminals)"
|
22
|
+
echo " -t, --tap Show results in TAP format"
|
23
|
+
echo " -v, --version Display the version number"
|
24
|
+
echo
|
25
|
+
echo " For more information, see https://github.com/sstephenson/bats"
|
26
|
+
echo
|
27
|
+
}
|
28
|
+
|
29
|
+
resolve_link() {
|
30
|
+
$(type -p greadlink readlink | head -1) "$1"
|
31
|
+
}
|
32
|
+
|
33
|
+
abs_dirname() {
|
34
|
+
local cwd="$(pwd)"
|
35
|
+
local path="$1"
|
36
|
+
|
37
|
+
while [ -n "$path" ]; do
|
38
|
+
cd "${path%/*}"
|
39
|
+
local name="${path##*/}"
|
40
|
+
path="$(resolve_link "$name" || true)"
|
41
|
+
done
|
42
|
+
|
43
|
+
pwd
|
44
|
+
cd "$cwd"
|
45
|
+
}
|
46
|
+
|
47
|
+
expand_path() {
|
48
|
+
{ cd "$(dirname "$1")" 2>/dev/null
|
49
|
+
local dirname="$PWD"
|
50
|
+
cd "$OLDPWD"
|
51
|
+
echo "$dirname/$(basename "$1")"
|
52
|
+
} || echo "$1"
|
53
|
+
}
|
54
|
+
|
55
|
+
BATS_LIBEXEC="$(abs_dirname "$0")"
|
56
|
+
export BATS_PREFIX="$(abs_dirname "$BATS_LIBEXEC")"
|
57
|
+
export PATH="$BATS_LIBEXEC:$PATH"
|
58
|
+
|
59
|
+
options=()
|
60
|
+
arguments=()
|
61
|
+
for arg in "$@"; do
|
62
|
+
if [ "${arg:0:1}" = "-" ]; then
|
63
|
+
if [ "${arg:1:1}" = "-" ]; then
|
64
|
+
options[${#options[*]}]="${arg:2}"
|
65
|
+
else
|
66
|
+
index=1
|
67
|
+
while option="${arg:$index:1}"; do
|
68
|
+
[ -n "$option" ] || break
|
69
|
+
options[${#options[*]}]="$option"
|
70
|
+
index=$(($index+1))
|
71
|
+
done
|
72
|
+
fi
|
73
|
+
else
|
74
|
+
arguments[${#arguments[*]}]="$arg"
|
75
|
+
fi
|
76
|
+
done
|
77
|
+
|
78
|
+
unset count_flag pretty
|
79
|
+
[ -t 0 ] && [ -t 1 ] && pretty="1"
|
80
|
+
|
81
|
+
for option in "${options[@]}"; do
|
82
|
+
case "$option" in
|
83
|
+
"h" | "help" )
|
84
|
+
help
|
85
|
+
exit 0
|
86
|
+
;;
|
87
|
+
"v" | "version" )
|
88
|
+
version
|
89
|
+
exit 0
|
90
|
+
;;
|
91
|
+
"c" | "count" )
|
92
|
+
count_flag="-c"
|
93
|
+
;;
|
94
|
+
"t" | "tap" )
|
95
|
+
pretty=""
|
96
|
+
;;
|
97
|
+
"p" | "pretty" )
|
98
|
+
pretty="1"
|
99
|
+
;;
|
100
|
+
* )
|
101
|
+
usage >&2
|
102
|
+
exit 1
|
103
|
+
;;
|
104
|
+
esac
|
105
|
+
done
|
106
|
+
|
107
|
+
if [ "${#arguments[@]}" -eq 0 ]; then
|
108
|
+
usage >&2
|
109
|
+
exit 1
|
110
|
+
fi
|
111
|
+
|
112
|
+
filenames=()
|
113
|
+
for filename in "${arguments[@]}"; do
|
114
|
+
if [ -d "$filename" ]; then
|
115
|
+
shopt -s nullglob
|
116
|
+
for suite_filename in "$(expand_path "$filename")"/*.bats; do
|
117
|
+
filenames["${#filenames[@]}"]="$suite_filename"
|
118
|
+
done
|
119
|
+
shopt -u nullglob
|
120
|
+
else
|
121
|
+
filenames["${#filenames[@]}"]="$(expand_path "$filename")"
|
122
|
+
fi
|
123
|
+
done
|
124
|
+
|
125
|
+
if [ "${#filenames[@]}" -eq 1 ]; then
|
126
|
+
command="bats-exec-test"
|
127
|
+
else
|
128
|
+
command="bats-exec-suite"
|
129
|
+
fi
|
130
|
+
|
131
|
+
if [ -n "$pretty" ]; then
|
132
|
+
extended_syntax_flag="-x"
|
133
|
+
formatter="bats-format-tap-stream"
|
134
|
+
else
|
135
|
+
extended_syntax_flag=""
|
136
|
+
formatter="cat"
|
137
|
+
fi
|
138
|
+
|
139
|
+
set -o pipefail execfail
|
140
|
+
exec "$command" $count_flag $extended_syntax_flag "${filenames[@]}" | "$formatter"
|