bats test suite updated to the recent one
This commit is contained in:
parent
499ac79a86
commit
0a446ad46a
20
Makefile
20
Makefile
@ -255,7 +255,7 @@ endif
|
||||
|
||||
test: deps.bats
|
||||
DOCKERFILE=$(DOCKERFILE) IMAGE=$(IMAGE_NAME):$(VERSION) \
|
||||
./test/bats/bats test/asterisk.bats
|
||||
./test/bats/bin/bats --pretty ./test/asterisk.bats
|
||||
|
||||
|
||||
|
||||
@ -264,18 +264,18 @@ test: deps.bats
|
||||
# Usage:
|
||||
# make deps.bats [BATS_VER=]
|
||||
|
||||
BATS_VER ?= 0.4.0
|
||||
BATS_VER ?= 1.2.1
|
||||
|
||||
deps.bats:
|
||||
ifeq ($(wildcard $(PWD)/test/bats),)
|
||||
mkdir -p $(PWD)/test/bats/vendor
|
||||
wget https://github.com/sstephenson/bats/archive/v$(BATS_VER).tar.gz \
|
||||
-O $(PWD)/test/bats/vendor/bats.tar.gz
|
||||
tar -xzf $(PWD)/test/bats/vendor/bats.tar.gz \
|
||||
-C $(PWD)/test/bats/vendor
|
||||
rm -f $(PWD)/test/bats/vendor/bats.tar.gz
|
||||
ln -s $(PWD)/test/bats/vendor/bats-$(BATS_VER)/libexec/* \
|
||||
$(PWD)/test/bats/
|
||||
mkdir -p $(PWD)/test/bats
|
||||
wget https://github.com/bats-core/bats-core/archive/v$(BATS_VER).tar.gz \
|
||||
-O $(PWD)/test/bats/bats.tar.gz
|
||||
tar -xzf $(PWD)/test/bats/bats.tar.gz -C $(PWD)/test/bats
|
||||
$(PWD)/test/bats/bats-core-$(BATS_VER)/install.sh $(PWD)/test/bats
|
||||
rm -rf $(PWD)/test/bats/bats.tar.gz \
|
||||
$(PWD)/test/bats/bats-core-$(BATS_VER) \
|
||||
$(PWD)/test/bats/share
|
||||
endif
|
||||
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
/home/ak/Development/docker/pjsua/test/bats/vendor/bats-0.4.0/libexec/bats
|
@ -1 +0,0 @@
|
||||
/home/ak/Development/docker/pjsua/test/bats/vendor/bats-0.4.0/libexec/bats-exec-suite
|
@ -1 +0,0 @@
|
||||
/home/ak/Development/docker/pjsua/test/bats/vendor/bats-0.4.0/libexec/bats-exec-test
|
@ -1 +0,0 @@
|
||||
/home/ak/Development/docker/pjsua/test/bats/vendor/bats-0.4.0/libexec/bats-format-tap-stream
|
@ -1 +0,0 @@
|
||||
/home/ak/Development/docker/pjsua/test/bats/vendor/bats-0.4.0/libexec/bats-preprocess
|
3
test/bats/vendor/bats-0.4.0/.gitattributes
vendored
3
test/bats/vendor/bats-0.4.0/.gitattributes
vendored
@ -1,3 +0,0 @@
|
||||
* text=auto
|
||||
*.sh eol=lf
|
||||
libexec/* eol=lf
|
5
test/bats/vendor/bats-0.4.0/.travis.yml
vendored
5
test/bats/vendor/bats-0.4.0/.travis.yml
vendored
@ -1,5 +0,0 @@
|
||||
language: c
|
||||
script: bin/bats --tap test
|
||||
notifications:
|
||||
email:
|
||||
on_success: never
|
20
test/bats/vendor/bats-0.4.0/LICENSE
vendored
20
test/bats/vendor/bats-0.4.0/LICENSE
vendored
@ -1,20 +0,0 @@
|
||||
Copyright (c) 2014 Sam Stephenson
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
293
test/bats/vendor/bats-0.4.0/README.md
vendored
293
test/bats/vendor/bats-0.4.0/README.md
vendored
@ -1,293 +0,0 @@
|
||||
# Bats: Bash Automated Testing System
|
||||
|
||||
Bats is a [TAP](http://testanything.org)-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.
|
||||
|
||||
```bash
|
||||
#!/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 ]
|
||||
}
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
|
||||
## 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.
|
||||
|
||||
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).
|
||||
|
||||
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
|
||||
|
||||
### Test suites
|
||||
|
||||
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.
|
||||
|
||||
|
||||
## Writing tests
|
||||
|
||||
Each Bats test file is evaluated _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 more details about how Bats evaluates test files, see
|
||||
[Bats Evaluation Process](https://github.com/sstephenson/bats/wiki/Bats-Evaluation-Process)
|
||||
on the wiki.
|
||||
|
||||
### `run`: Test other commands
|
||||
|
||||
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.
|
||||
|
||||
```bash
|
||||
@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:
|
||||
|
||||
```bash
|
||||
@test "invoking foo without arguments prints usage" {
|
||||
run foo
|
||||
[ "$status" -eq 1 ]
|
||||
[ "${lines[0]}" = "usage: foo <filename>" ]
|
||||
}
|
||||
```
|
||||
|
||||
### `load`: Share common code
|
||||
|
||||
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
|
||||
|
||||
```bash
|
||||
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.
|
||||
|
||||
### `skip`: Easily skip tests
|
||||
|
||||
Tests can be skipped by using the `skip` command at the point in a
|
||||
test you wish to skip.
|
||||
|
||||
```bash
|
||||
@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:
|
||||
|
||||
```bash
|
||||
@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:
|
||||
|
||||
```bash
|
||||
@test "A test which should run" {
|
||||
if [ foo != bar ]; then
|
||||
skip "foo isn't bar"
|
||||
fi
|
||||
|
||||
run foo
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
```
|
||||
|
||||
### `setup` and `teardown`: Pre- and post-test hooks
|
||||
|
||||
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.
|
||||
|
||||
|
||||
## Installing Bats from source
|
||||
|
||||
Check out a copy of the Bats repository. Then, either add the Bats
|
||||
`bin` directory to your `$PATH`, or run the provided `install.sh`
|
||||
command with the location to the prefix in which you want to install
|
||||
Bats. For example, to install Bats into `/usr/local`,
|
||||
|
||||
$ git clone https://github.com/sstephenson/bats.git
|
||||
$ cd bats
|
||||
$ ./install.sh /usr/local
|
||||
|
||||
Note that you may need to run `install.sh` with `sudo` if you do not
|
||||
have permission to write to the installation prefix.
|
||||
|
||||
|
||||
## Support
|
||||
|
||||
The Bats source code repository is [hosted on
|
||||
GitHub](https://github.com/sstephenson/bats). There you can file bugs
|
||||
on the issue tracker or submit tested pull requests for review.
|
||||
|
||||
For real-world examples from open-source projects using Bats, see
|
||||
[Projects Using Bats](https://github.com/sstephenson/bats/wiki/Projects-Using-Bats)
|
||||
on the wiki.
|
||||
|
||||
To learn how to set up your editor for Bats syntax highlighting, see
|
||||
[Syntax Highlighting](https://github.com/sstephenson/bats/wiki/Syntax-Highlighting)
|
||||
on the wiki.
|
||||
|
||||
|
||||
## Version history
|
||||
|
||||
*0.4.0* (August 13, 2014)
|
||||
|
||||
* Improved the display of failing test cases. Bats now shows the
|
||||
source code of failing test lines, along with full stack traces
|
||||
including function names, filenames, and line numbers.
|
||||
* Improved the display of the pretty-printed test summary line to
|
||||
include the number of skipped tests, if any.
|
||||
* Improved the speed of the preprocessor, dramatically shortening test
|
||||
and suite startup times.
|
||||
* Added support for absolute pathnames to the `load` helper.
|
||||
* Added support for single-line `@test` definitions.
|
||||
* Added bats(1) and bats(7) manual pages.
|
||||
* Modified the `bats` command to default to TAP output when the `$CI`
|
||||
variable is set, to better support environments such as Travis CI.
|
||||
|
||||
*0.3.1* (October 28, 2013)
|
||||
|
||||
* Fixed an incompatibility with the pretty formatter in certain
|
||||
environments such as tmux.
|
||||
* Fixed a bug where the pretty formatter would crash if the first line
|
||||
of a test file's output was invalid TAP.
|
||||
|
||||
*0.3.0* (October 21, 2013)
|
||||
|
||||
* Improved formatting for tests run from a terminal. Failing tests
|
||||
are now colored in red, and the total number of failing tests is
|
||||
displayed at the end of the test run. When Bats is not connected to
|
||||
a terminal (e.g. in CI runs), or when invoked with the `--tap` flag,
|
||||
output is displayed in standard TAP format.
|
||||
* Added the ability to skip tests using the `skip` command.
|
||||
* Added a message to failing test case output indicating the file and
|
||||
line number of the statement that caused the test to fail.
|
||||
* Added "ad-hoc" test suite support. You can now invoke `bats` with
|
||||
multiple filename or directory arguments to run all the specified
|
||||
tests in aggregate.
|
||||
* Added support for test files with Windows line endings.
|
||||
* Fixed regular expression warnings from certain versions of Bash.
|
||||
* Fixed a bug running tests containing lines that begin with `-e`.
|
||||
|
||||
*0.2.0* (November 16, 2012)
|
||||
|
||||
* Added test suite support. The `bats` command accepts a directory
|
||||
name containing multiple test files to be run in aggregate.
|
||||
* Added the ability to count the number of test cases in a file or
|
||||
suite by passing the `-c` flag to `bats`.
|
||||
* Preprocessed sources are cached between test case runs in the same
|
||||
file for better performance.
|
||||
|
||||
*0.1.0* (December 30, 2011)
|
||||
|
||||
* Initial public release.
|
||||
|
||||
---
|
||||
|
||||
© 2014 Sam Stephenson. Bats is released under an MIT-style license;
|
||||
see `LICENSE` for details.
|
1
test/bats/vendor/bats-0.4.0/bin/bats
vendored
1
test/bats/vendor/bats-0.4.0/bin/bats
vendored
@ -1 +0,0 @@
|
||||
../libexec/bats
|
37
test/bats/vendor/bats-0.4.0/install.sh
vendored
37
test/bats/vendor/bats-0.4.0/install.sh
vendored
@ -1,37 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
resolve_link() {
|
||||
$(type -p greadlink readlink | head -1) "$1"
|
||||
}
|
||||
|
||||
abs_dirname() {
|
||||
local cwd="$(pwd)"
|
||||
local path="$1"
|
||||
|
||||
while [ -n "$path" ]; do
|
||||
cd "${path%/*}"
|
||||
local name="${path##*/}"
|
||||
path="$(resolve_link "$name" || true)"
|
||||
done
|
||||
|
||||
pwd
|
||||
cd "$cwd"
|
||||
}
|
||||
|
||||
PREFIX="$1"
|
||||
if [ -z "$1" ]; then
|
||||
{ echo "usage: $0 <prefix>"
|
||||
echo " e.g. $0 /usr/local"
|
||||
} >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BATS_ROOT="$(abs_dirname "$0")"
|
||||
mkdir -p "$PREFIX"/{bin,libexec,share/man/man{1,7}}
|
||||
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"
|
142
test/bats/vendor/bats-0.4.0/libexec/bats
vendored
142
test/bats/vendor/bats-0.4.0/libexec/bats
vendored
@ -1,142 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
version() {
|
||||
echo "Bats 0.4.0"
|
||||
}
|
||||
|
||||
usage() {
|
||||
version
|
||||
echo "Usage: bats [-c] [-p | -t] <test> [<test> ...]"
|
||||
}
|
||||
|
||||
help() {
|
||||
usage
|
||||
echo
|
||||
echo " <test> is the path to a Bats test file, or the path to a directory"
|
||||
echo " containing Bats test files."
|
||||
echo
|
||||
echo " -c, --count Count the number of test cases without running any tests"
|
||||
echo " -h, --help Display this help message"
|
||||
echo " -p, --pretty Show results in pretty format (default for terminals)"
|
||||
echo " -t, --tap Show results in TAP format"
|
||||
echo " -v, --version Display the version number"
|
||||
echo
|
||||
echo " For more information, see https://github.com/sstephenson/bats"
|
||||
echo
|
||||
}
|
||||
|
||||
resolve_link() {
|
||||
$(type -p greadlink readlink | head -1) "$1"
|
||||
}
|
||||
|
||||
abs_dirname() {
|
||||
local cwd="$(pwd)"
|
||||
local path="$1"
|
||||
|
||||
while [ -n "$path" ]; do
|
||||
cd "${path%/*}"
|
||||
local name="${path##*/}"
|
||||
path="$(resolve_link "$name" || true)"
|
||||
done
|
||||
|
||||
pwd
|
||||
cd "$cwd"
|
||||
}
|
||||
|
||||
expand_path() {
|
||||
{ cd "$(dirname "$1")" 2>/dev/null
|
||||
local dirname="$PWD"
|
||||
cd "$OLDPWD"
|
||||
echo "$dirname/$(basename "$1")"
|
||||
} || echo "$1"
|
||||
}
|
||||
|
||||
BATS_LIBEXEC="$(abs_dirname "$0")"
|
||||
export BATS_PREFIX="$(abs_dirname "$BATS_LIBEXEC")"
|
||||
export BATS_CWD="$(abs_dirname .)"
|
||||
export PATH="$BATS_LIBEXEC:$PATH"
|
||||
|
||||
options=()
|
||||
arguments=()
|
||||
for arg in "$@"; do
|
||||
if [ "${arg:0:1}" = "-" ]; then
|
||||
if [ "${arg:1:1}" = "-" ]; then
|
||||
options[${#options[*]}]="${arg:2}"
|
||||
else
|
||||
index=1
|
||||
while option="${arg:$index:1}"; do
|
||||
[ -n "$option" ] || break
|
||||
options[${#options[*]}]="$option"
|
||||
let index+=1
|
||||
done
|
||||
fi
|
||||
else
|
||||
arguments[${#arguments[*]}]="$arg"
|
||||
fi
|
||||
done
|
||||
|
||||
unset count_flag pretty
|
||||
[ -t 0 ] && [ -t 1 ] && pretty="1"
|
||||
[ -n "$CI" ] && pretty=""
|
||||
|
||||
for option in "${options[@]}"; do
|
||||
case "$option" in
|
||||
"h" | "help" )
|
||||
help
|
||||
exit 0
|
||||
;;
|
||||
"v" | "version" )
|
||||
version
|
||||
exit 0
|
||||
;;
|
||||
"c" | "count" )
|
||||
count_flag="-c"
|
||||
;;
|
||||
"t" | "tap" )
|
||||
pretty=""
|
||||
;;
|
||||
"p" | "pretty" )
|
||||
pretty="1"
|
||||
;;
|
||||
* )
|
||||
usage >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "${#arguments[@]}" -eq 0 ]; then
|
||||
usage >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
filenames=()
|
||||
for filename in "${arguments[@]}"; do
|
||||
if [ -d "$filename" ]; then
|
||||
shopt -s nullglob
|
||||
for suite_filename in "$(expand_path "$filename")"/*.bats; do
|
||||
filenames["${#filenames[@]}"]="$suite_filename"
|
||||
done
|
||||
shopt -u nullglob
|
||||
else
|
||||
filenames["${#filenames[@]}"]="$(expand_path "$filename")"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "${#filenames[@]}" -eq 1 ]; then
|
||||
command="bats-exec-test"
|
||||
else
|
||||
command="bats-exec-suite"
|
||||
fi
|
||||
|
||||
if [ -n "$pretty" ]; then
|
||||
extended_syntax_flag="-x"
|
||||
formatter="bats-format-tap-stream"
|
||||
else
|
||||
extended_syntax_flag=""
|
||||
formatter="cat"
|
||||
fi
|
||||
|
||||
set -o pipefail execfail
|
||||
exec "$command" $count_flag $extended_syntax_flag "${filenames[@]}" | "$formatter"
|
@ -1,55 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
count_only_flag=""
|
||||
if [ "$1" = "-c" ]; then
|
||||
count_only_flag=1
|
||||
shift
|
||||
fi
|
||||
|
||||
extended_syntax_flag=""
|
||||
if [ "$1" = "-x" ]; then
|
||||
extended_syntax_flag="-x"
|
||||
shift
|
||||
fi
|
||||
|
||||
trap "kill 0; exit 1" int
|
||||
|
||||
count=0
|
||||
for filename in "$@"; do
|
||||
let count+="$(bats-exec-test -c "$filename")"
|
||||
done
|
||||
|
||||
if [ -n "$count_only_flag" ]; then
|
||||
echo "$count"
|
||||
exit
|
||||
fi
|
||||
|
||||
echo "1..$count"
|
||||
status=0
|
||||
offset=0
|
||||
for filename in "$@"; do
|
||||
index=0
|
||||
{
|
||||
IFS= read -r # 1..n
|
||||
while IFS= read -r line; do
|
||||
case "$line" in
|
||||
"begin "* )
|
||||
let index+=1
|
||||
echo "${line/ $index / $(($offset + $index)) }"
|
||||
;;
|
||||
"ok "* | "not ok "* )
|
||||
[ -n "$extended_syntax_flag" ] || let index+=1
|
||||
echo "${line/ $index / $(($offset + $index)) }"
|
||||
[ "${line:0:6}" != "not ok" ] || status=1
|
||||
;;
|
||||
* )
|
||||
echo "$line"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
} < <( bats-exec-test $extended_syntax_flag "$filename" )
|
||||
offset=$(($offset + $index))
|
||||
done
|
||||
|
||||
exit "$status"
|
344
test/bats/vendor/bats-0.4.0/libexec/bats-exec-test
vendored
344
test/bats/vendor/bats-0.4.0/libexec/bats-exec-test
vendored
@ -1,344 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
set -E
|
||||
set -T
|
||||
|
||||
BATS_COUNT_ONLY=""
|
||||
if [ "$1" = "-c" ]; then
|
||||
BATS_COUNT_ONLY=1
|
||||
shift
|
||||
fi
|
||||
|
||||
BATS_EXTENDED_SYNTAX=""
|
||||
if [ "$1" = "-x" ]; then
|
||||
BATS_EXTENDED_SYNTAX="$1"
|
||||
shift
|
||||
fi
|
||||
|
||||
BATS_TEST_FILENAME="$1"
|
||||
if [ -z "$BATS_TEST_FILENAME" ]; then
|
||||
echo "usage: bats-exec <filename>" >&2
|
||||
exit 1
|
||||
elif [ ! -f "$BATS_TEST_FILENAME" ]; then
|
||||
echo "bats: $BATS_TEST_FILENAME does not exist" >&2
|
||||
exit 1
|
||||
else
|
||||
shift
|
||||
fi
|
||||
|
||||
BATS_TEST_DIRNAME="$(dirname "$BATS_TEST_FILENAME")"
|
||||
BATS_TEST_NAMES=()
|
||||
|
||||
load() {
|
||||
local name="$1"
|
||||
local filename
|
||||
|
||||
if [ "${name:0:1}" = "/" ]; then
|
||||
filename="${name}"
|
||||
else
|
||||
filename="$BATS_TEST_DIRNAME/${name}.bash"
|
||||
fi
|
||||
|
||||
[ -f "$filename" ] || {
|
||||
echo "bats: $filename does not exist" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
source "${filename}"
|
||||
}
|
||||
|
||||
run() {
|
||||
local e E T
|
||||
[[ ! "$-" =~ e ]] || e=1
|
||||
[[ ! "$-" =~ E ]] || E=1
|
||||
[[ ! "$-" =~ T ]] || T=1
|
||||
set +e
|
||||
set +E
|
||||
set +T
|
||||
output="$("$@" 2>&1)"
|
||||
status="$?"
|
||||
IFS=$'\n' lines=($output)
|
||||
[ -z "$e" ] || set -e
|
||||
[ -z "$E" ] || set -E
|
||||
[ -z "$T" ] || set -T
|
||||
}
|
||||
|
||||
setup() {
|
||||
true
|
||||
}
|
||||
|
||||
teardown() {
|
||||
true
|
||||
}
|
||||
|
||||
skip() {
|
||||
BATS_TEST_SKIPPED=${1:-1}
|
||||
BATS_TEST_COMPLETED=1
|
||||
exit 0
|
||||
}
|
||||
|
||||
bats_test_begin() {
|
||||
BATS_TEST_DESCRIPTION="$1"
|
||||
if [ -n "$BATS_EXTENDED_SYNTAX" ]; then
|
||||
echo "begin $BATS_TEST_NUMBER $BATS_TEST_DESCRIPTION" >&3
|
||||
fi
|
||||
setup
|
||||
}
|
||||
|
||||
bats_test_function() {
|
||||
local test_name="$1"
|
||||
BATS_TEST_NAMES["${#BATS_TEST_NAMES[@]}"]="$test_name"
|
||||
}
|
||||
|
||||
bats_capture_stack_trace() {
|
||||
BATS_PREVIOUS_STACK_TRACE=( "${BATS_CURRENT_STACK_TRACE[@]}" )
|
||||
BATS_CURRENT_STACK_TRACE=()
|
||||
|
||||
local test_pattern=" $BATS_TEST_NAME $BATS_TEST_SOURCE"
|
||||
local setup_pattern=" setup $BATS_TEST_SOURCE"
|
||||
local teardown_pattern=" teardown $BATS_TEST_SOURCE"
|
||||
|
||||
local frame
|
||||
local index=1
|
||||
|
||||
while frame="$(caller "$index")"; do
|
||||
BATS_CURRENT_STACK_TRACE["${#BATS_CURRENT_STACK_TRACE[@]}"]="$frame"
|
||||
if [[ "$frame" = *"$test_pattern" || \
|
||||
"$frame" = *"$setup_pattern" || \
|
||||
"$frame" = *"$teardown_pattern" ]]; then
|
||||
break
|
||||
else
|
||||
let index+=1
|
||||
fi
|
||||
done
|
||||
|
||||
BATS_SOURCE="$(bats_frame_filename "${BATS_CURRENT_STACK_TRACE[0]}")"
|
||||
BATS_LINENO="$(bats_frame_lineno "${BATS_CURRENT_STACK_TRACE[0]}")"
|
||||
}
|
||||
|
||||
bats_print_stack_trace() {
|
||||
local frame
|
||||
local index=1
|
||||
local count="${#@}"
|
||||
|
||||
for frame in "$@"; do
|
||||
local filename="$(bats_trim_filename "$(bats_frame_filename "$frame")")"
|
||||
local lineno="$(bats_frame_lineno "$frame")"
|
||||
|
||||
if [ $index -eq 1 ]; then
|
||||
echo -n "# ("
|
||||
else
|
||||
echo -n "# "
|
||||
fi
|
||||
|
||||
local fn="$(bats_frame_function "$frame")"
|
||||
if [ "$fn" != "$BATS_TEST_NAME" ]; then
|
||||
echo -n "from function \`$fn' "
|
||||
fi
|
||||
|
||||
if [ $index -eq $count ]; then
|
||||
echo "in test file $filename, line $lineno)"
|
||||
else
|
||||
echo "in file $filename, line $lineno,"
|
||||
fi
|
||||
|
||||
let index+=1
|
||||
done
|
||||
}
|
||||
|
||||
bats_print_failed_command() {
|
||||
local frame="$1"
|
||||
local status="$2"
|
||||
local filename="$(bats_frame_filename "$frame")"
|
||||
local lineno="$(bats_frame_lineno "$frame")"
|
||||
|
||||
local failed_line="$(bats_extract_line "$filename" "$lineno")"
|
||||
local failed_command="$(bats_strip_string "$failed_line")"
|
||||
echo -n "# \`${failed_command}' "
|
||||
|
||||
if [ $status -eq 1 ]; then
|
||||
echo "failed"
|
||||
else
|
||||
echo "failed with status $status"
|
||||
fi
|
||||
}
|
||||
|
||||
bats_frame_lineno() {
|
||||
local frame="$1"
|
||||
local lineno="${frame%% *}"
|
||||
echo "$lineno"
|
||||
}
|
||||
|
||||
bats_frame_function() {
|
||||
local frame="$1"
|
||||
local rest="${frame#* }"
|
||||
local fn="${rest%% *}"
|
||||
echo "$fn"
|
||||
}
|
||||
|
||||
bats_frame_filename() {
|
||||
local frame="$1"
|
||||
local rest="${frame#* }"
|
||||
local filename="${rest#* }"
|
||||
|
||||
if [ "$filename" = "$BATS_TEST_SOURCE" ]; then
|
||||
echo "$BATS_TEST_FILENAME"
|
||||
else
|
||||
echo "$filename"
|
||||
fi
|
||||
}
|
||||
|
||||
bats_extract_line() {
|
||||
local filename="$1"
|
||||
local lineno="$2"
|
||||
sed -n "${lineno}p" "$filename"
|
||||
}
|
||||
|
||||
bats_strip_string() {
|
||||
local string="$1"
|
||||
printf "%s" "$string" | sed -e "s/^[ "$'\t'"]*//" -e "s/[ "$'\t'"]*$//"
|
||||
}
|
||||
|
||||
bats_trim_filename() {
|
||||
local filename="$1"
|
||||
local length="${#BATS_CWD}"
|
||||
|
||||
if [ "${filename:0:length+1}" = "${BATS_CWD}/" ]; then
|
||||
echo "${filename:length+1}"
|
||||
else
|
||||
echo "$filename"
|
||||
fi
|
||||
}
|
||||
|
||||
bats_debug_trap() {
|
||||
if [ "$BASH_SOURCE" != "$1" ]; then
|
||||
bats_capture_stack_trace
|
||||
fi
|
||||
}
|
||||
|
||||
bats_error_trap() {
|
||||
BATS_ERROR_STATUS="$?"
|
||||
BATS_ERROR_STACK_TRACE=( "${BATS_PREVIOUS_STACK_TRACE[@]}" )
|
||||
trap - debug
|
||||
}
|
||||
|
||||
bats_teardown_trap() {
|
||||
trap "bats_exit_trap" exit
|
||||
local status=0
|
||||
teardown >>"$BATS_OUT" 2>&1 || status="$?"
|
||||
|
||||
if [ $status -eq 0 ]; then
|
||||
BATS_TEARDOWN_COMPLETED=1
|
||||
elif [ -n "$BATS_TEST_COMPLETED" ]; then
|
||||
BATS_ERROR_STATUS="$status"
|
||||
BATS_ERROR_STACK_TRACE=( "${BATS_CURRENT_STACK_TRACE[@]}" )
|
||||
fi
|
||||
|
||||
bats_exit_trap
|
||||
}
|
||||
|
||||
bats_exit_trap() {
|
||||
local status
|
||||
local skipped
|
||||
trap - err exit
|
||||
|
||||
skipped=""
|
||||
if [ -n "$BATS_TEST_SKIPPED" ]; then
|
||||
skipped=" # skip"
|
||||
if [ "1" != "$BATS_TEST_SKIPPED" ]; then
|
||||
skipped+=" ($BATS_TEST_SKIPPED)"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$BATS_TEST_COMPLETED" ] || [ -z "$BATS_TEARDOWN_COMPLETED" ]; then
|
||||
echo "not ok $BATS_TEST_NUMBER $BATS_TEST_DESCRIPTION" >&3
|
||||
bats_print_stack_trace "${BATS_ERROR_STACK_TRACE[@]}" >&3
|
||||
bats_print_failed_command "${BATS_ERROR_STACK_TRACE[${#BATS_ERROR_STACK_TRACE[@]}-1]}" "$BATS_ERROR_STATUS" >&3
|
||||
sed -e "s/^/# /" < "$BATS_OUT" >&3
|
||||
status=1
|
||||
else
|
||||
echo "ok ${BATS_TEST_NUMBER}${skipped} ${BATS_TEST_DESCRIPTION}" >&3
|
||||
status=0
|
||||
fi
|
||||
|
||||
rm -f "$BATS_OUT"
|
||||
exit "$status"
|
||||
}
|
||||
|
||||
bats_perform_tests() {
|
||||
echo "1..$#"
|
||||
test_number=1
|
||||
status=0
|
||||
for test_name in "$@"; do
|
||||
"$0" $BATS_EXTENDED_SYNTAX "$BATS_TEST_FILENAME" "$test_name" "$test_number" || status=1
|
||||
let test_number+=1
|
||||
done
|
||||
exit "$status"
|
||||
}
|
||||
|
||||
bats_perform_test() {
|
||||
BATS_TEST_NAME="$1"
|
||||
if [ "$(type -t "$BATS_TEST_NAME" || true)" = "function" ]; then
|
||||
BATS_TEST_NUMBER="$2"
|
||||
if [ -z "$BATS_TEST_NUMBER" ]; then
|
||||
echo "1..1"
|
||||
BATS_TEST_NUMBER="1"
|
||||
fi
|
||||
|
||||
BATS_TEST_COMPLETED=""
|
||||
BATS_TEARDOWN_COMPLETED=""
|
||||
trap "bats_debug_trap \"\$BASH_SOURCE\"" debug
|
||||
trap "bats_error_trap" err
|
||||
trap "bats_teardown_trap" exit
|
||||
"$BATS_TEST_NAME" >>"$BATS_OUT" 2>&1
|
||||
BATS_TEST_COMPLETED=1
|
||||
|
||||
else
|
||||
echo "bats: unknown test name \`$BATS_TEST_NAME'" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
if [ -z "$TMPDIR" ]; then
|
||||
BATS_TMPDIR="/tmp"
|
||||
else
|
||||
BATS_TMPDIR="${TMPDIR%/}"
|
||||
fi
|
||||
|
||||
BATS_TMPNAME="$BATS_TMPDIR/bats.$$"
|
||||
BATS_PARENT_TMPNAME="$BATS_TMPDIR/bats.$PPID"
|
||||
BATS_OUT="${BATS_TMPNAME}.out"
|
||||
|
||||
bats_preprocess_source() {
|
||||
BATS_TEST_SOURCE="${BATS_TMPNAME}.src"
|
||||
{ tr -d '\r' < "$BATS_TEST_FILENAME"; echo; } | bats-preprocess > "$BATS_TEST_SOURCE"
|
||||
trap "bats_cleanup_preprocessed_source" err exit
|
||||
trap "bats_cleanup_preprocessed_source; exit 1" int
|
||||
}
|
||||
|
||||
bats_cleanup_preprocessed_source() {
|
||||
rm -f "$BATS_TEST_SOURCE"
|
||||
}
|
||||
|
||||
bats_evaluate_preprocessed_source() {
|
||||
if [ -z "$BATS_TEST_SOURCE" ]; then
|
||||
BATS_TEST_SOURCE="${BATS_PARENT_TMPNAME}.src"
|
||||
fi
|
||||
source "$BATS_TEST_SOURCE"
|
||||
}
|
||||
|
||||
exec 3<&1
|
||||
|
||||
if [ "$#" -eq 0 ]; then
|
||||
bats_preprocess_source
|
||||
bats_evaluate_preprocessed_source
|
||||
|
||||
if [ -n "$BATS_COUNT_ONLY" ]; then
|
||||
echo "${#BATS_TEST_NAMES[@]}"
|
||||
else
|
||||
bats_perform_tests "${BATS_TEST_NAMES[@]}"
|
||||
fi
|
||||
else
|
||||
bats_evaluate_preprocessed_source
|
||||
bats_perform_test "$@"
|
||||
fi
|
@ -1,165 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# Just stream the TAP output (sans extended syntax) if tput is missing
|
||||
command -v tput >/dev/null || exec grep -v "^begin "
|
||||
|
||||
header_pattern='[0-9]+\.\.[0-9]+'
|
||||
IFS= read -r header
|
||||
|
||||
if [[ "$header" =~ $header_pattern ]]; then
|
||||
count="${header:3}"
|
||||
index=0
|
||||
failures=0
|
||||
skipped=0
|
||||
name=""
|
||||
count_column_width=$(( ${#count} * 2 + 2 ))
|
||||
else
|
||||
# If the first line isn't a TAP plan, print it and pass the rest through
|
||||
printf "%s\n" "$header"
|
||||
exec cat
|
||||
fi
|
||||
|
||||
update_screen_width() {
|
||||
screen_width="$(tput cols)"
|
||||
count_column_left=$(( $screen_width - $count_column_width ))
|
||||
}
|
||||
|
||||
trap update_screen_width WINCH
|
||||
update_screen_width
|
||||
|
||||
begin() {
|
||||
go_to_column 0
|
||||
printf_with_truncation $(( $count_column_left - 1 )) " %s" "$name"
|
||||
clear_to_end_of_line
|
||||
go_to_column $count_column_left
|
||||
printf "%${#count}s/${count}" "$index"
|
||||
go_to_column 1
|
||||
}
|
||||
|
||||
pass() {
|
||||
go_to_column 0
|
||||
printf " ✓ %s" "$name"
|
||||
advance
|
||||
}
|
||||
|
||||
skip() {
|
||||
local reason="$1"
|
||||
[ -z "$reason" ] || reason=": $reason"
|
||||
go_to_column 0
|
||||
printf " - %s (skipped%s)" "$name" "$reason"
|
||||
advance
|
||||
}
|
||||
|
||||
fail() {
|
||||
go_to_column 0
|
||||
set_color 1 bold
|
||||
printf " ✗ %s" "$name"
|
||||
advance
|
||||
}
|
||||
|
||||
log() {
|
||||
set_color 1
|
||||
printf " %s\n" "$1"
|
||||
clear_color
|
||||
}
|
||||
|
||||
summary() {
|
||||
printf "\n%d test%s" "$count" "$(plural "$count")"
|
||||
|
||||
printf ", %d failure%s" "$failures" "$(plural "$failures")"
|
||||
|
||||
if [ "$skipped" -gt 0 ]; then
|
||||
printf ", %d skipped" "$skipped"
|
||||
fi
|
||||
|
||||
printf "\n"
|
||||
}
|
||||
|
||||
printf_with_truncation() {
|
||||
local width="$1"
|
||||
shift
|
||||
local string="$(printf "$@")"
|
||||
|
||||
if [ "${#string}" -gt "$width" ]; then
|
||||
printf "%s..." "${string:0:$(( $width - 4 ))}"
|
||||
else
|
||||
printf "%s" "$string"
|
||||
fi
|
||||
}
|
||||
|
||||
go_to_column() {
|
||||
local column="$1"
|
||||
printf "\x1B[%dG" $(( $column + 1 ))
|
||||
}
|
||||
|
||||
clear_to_end_of_line() {
|
||||
printf "\x1B[K"
|
||||
}
|
||||
|
||||
advance() {
|
||||
clear_to_end_of_line
|
||||
echo
|
||||
clear_color
|
||||
}
|
||||
|
||||
set_color() {
|
||||
local color="$1"
|
||||
local weight="$2"
|
||||
printf "\x1B[%d;%dm" $(( 30 + $color )) "$( [ "$weight" = "bold" ] && echo 1 || echo 22 )"
|
||||
}
|
||||
|
||||
clear_color() {
|
||||
printf "\x1B[0m"
|
||||
}
|
||||
|
||||
plural() {
|
||||
[ "$1" -eq 1 ] || echo "s"
|
||||
}
|
||||
|
||||
_buffer=""
|
||||
|
||||
buffer() {
|
||||
_buffer="${_buffer}$("$@")"
|
||||
}
|
||||
|
||||
flush() {
|
||||
printf "%s" "$_buffer"
|
||||
_buffer=""
|
||||
}
|
||||
|
||||
finish() {
|
||||
flush
|
||||
printf "\n"
|
||||
}
|
||||
|
||||
trap finish EXIT
|
||||
|
||||
while IFS= read -r line; do
|
||||
case "$line" in
|
||||
"begin "* )
|
||||
let index+=1
|
||||
name="${line#* $index }"
|
||||
buffer begin
|
||||
flush
|
||||
;;
|
||||
"ok "* )
|
||||
skip_expr="ok $index # skip (\(([^)]*)\))?"
|
||||
if [[ "$line" =~ $skip_expr ]]; then
|
||||
let skipped+=1
|
||||
buffer skip "${BASH_REMATCH[2]}"
|
||||
else
|
||||
buffer pass
|
||||
fi
|
||||
;;
|
||||
"not ok "* )
|
||||
let failures+=1
|
||||
buffer fail
|
||||
;;
|
||||
"# "* )
|
||||
buffer log "${line:2}"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
buffer summary
|
@ -1,52 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
encode_name() {
|
||||
local name="$1"
|
||||
local result="test_"
|
||||
|
||||
if [[ ! "$name" =~ [^[:alnum:]\ _-] ]]; then
|
||||
name="${name//_/-5f}"
|
||||
name="${name//-/-2d}"
|
||||
name="${name// /_}"
|
||||
result+="$name"
|
||||
else
|
||||
local length="${#name}"
|
||||
local char i
|
||||
|
||||
for ((i=0; i<length; i++)); do
|
||||
char="${name:$i:1}"
|
||||
if [ "$char" = " " ]; then
|
||||
result+="_"
|
||||
elif [[ "$char" =~ [[:alnum:]] ]]; then
|
||||
result+="$char"
|
||||
else
|
||||
result+="$(printf -- "-%02x" \'"$char")"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
echo "$result"
|
||||
}
|
||||
|
||||
tests=()
|
||||
index=0
|
||||
pattern='^ *@test *([^ ].*) *\{ *(.*)$'
|
||||
|
||||
while IFS= read -r line; do
|
||||
let index+=1
|
||||
if [[ "$line" =~ $pattern ]]; then
|
||||
quoted_name="${BASH_REMATCH[1]}"
|
||||
body="${BASH_REMATCH[2]}"
|
||||
name="$(eval echo "$quoted_name")"
|
||||
encoded_name="$(encode_name "$name")"
|
||||
tests["${#tests[@]}"]="$encoded_name"
|
||||
echo "${encoded_name}() { bats_test_begin ${quoted_name} ${index}; ${body}"
|
||||
else
|
||||
printf "%s\n" "$line"
|
||||
fi
|
||||
done
|
||||
|
||||
for test_name in "${tests[@]}"; do
|
||||
echo "bats_test_function ${test_name}"
|
||||
done
|
10
test/bats/vendor/bats-0.4.0/man/Makefile
vendored
10
test/bats/vendor/bats-0.4.0/man/Makefile
vendored
@ -1,10 +0,0 @@
|
||||
RONN := ronn
|
||||
PAGES := bats.1 bats.7
|
||||
|
||||
all: $(PAGES)
|
||||
|
||||
bats.1: bats.1.ronn
|
||||
$(RONN) -r $<
|
||||
|
||||
bats.7: bats.7.ronn
|
||||
$(RONN) -r $<
|
5
test/bats/vendor/bats-0.4.0/man/README.md
vendored
5
test/bats/vendor/bats-0.4.0/man/README.md
vendored
@ -1,5 +0,0 @@
|
||||
Bats man pages are generated with [Ronn](http://rtomayko.github.io/ronn/).
|
||||
|
||||
After making changes to `bats.1.ronn` or `bats.7.ronn`, run `make` in
|
||||
this directory to generate `bats.1` and `bats.7`. **Do not edit the
|
||||
`bats.1` or `bats.7` files directly.**
|
101
test/bats/vendor/bats-0.4.0/man/bats.1
vendored
101
test/bats/vendor/bats-0.4.0/man/bats.1
vendored
@ -1,101 +0,0 @@
|
||||
.\" generated with Ronn/v0.7.3
|
||||
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
||||
.
|
||||
.TH "BATS" "1" "August 2014" "" ""
|
||||
.
|
||||
.SH "NAME"
|
||||
\fBbats\fR \- Bash Automated Testing System
|
||||
.
|
||||
.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
|
||||
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\.
|
||||
.
|
||||
.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
|
||||
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 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 "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
|
||||
.
|
||||
.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\. 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 "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 wiki: \fIhttps://github\.com/sstephenson/bats/wiki/\fR
|
||||
.
|
||||
.P
|
||||
\fBbash\fR(1), \fBbats\fR(7)
|
||||
.
|
||||
.SH "COPYRIGHT"
|
||||
(c) 2014 Sam Stephenson
|
||||
.
|
||||
.P
|
||||
Bats is released under the terms of an MIT\-style license\.
|
109
test/bats/vendor/bats-0.4.0/man/bats.1.ronn
vendored
109
test/bats/vendor/bats-0.4.0/man/bats.1.ronn
vendored
@ -1,109 +0,0 @@
|
||||
bats(1) -- Bash Automated Testing System
|
||||
========================================
|
||||
|
||||
|
||||
SYNOPSIS
|
||||
--------
|
||||
|
||||
bats [-c] [-p | -t] <test> [<test> ...]
|
||||
|
||||
<test> 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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
|
||||
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.
|
||||
|
||||
|
||||
OPTIONS
|
||||
-------
|
||||
|
||||
* `-c`, `--count`:
|
||||
Count the number of test cases without running any tests
|
||||
* `-h`, `--help`:
|
||||
Display 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
|
||||
|
||||
|
||||
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.
|
||||
|
||||
$ 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
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
COPYRIGHT
|
||||
---------
|
||||
|
||||
(c) 2014 Sam Stephenson
|
||||
|
||||
Bats is released under the terms of an MIT-style license.
|
||||
|
||||
|
||||
|
178
test/bats/vendor/bats-0.4.0/man/bats.7
vendored
178
test/bats/vendor/bats-0.4.0/man/bats.7
vendored
@ -1,178 +0,0 @@
|
||||
.\" 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 "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 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\.
|
||||
.
|
||||
.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 <filename>" ]
|
||||
}
|
||||
.
|
||||
.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"
|
||||
\fBbash\fR(1), \fBbats\fR(1)
|
156
test/bats/vendor/bats-0.4.0/man/bats.7.ronn
vendored
156
test/bats/vendor/bats-0.4.0/man/bats.7.ronn
vendored
@ -1,156 +0,0 @@
|
||||
bats(7) -- Bats test file format
|
||||
================================
|
||||
|
||||
|
||||
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 evaluated 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.
|
||||
|
||||
|
||||
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
|
||||
--------
|
||||
|
||||
`bash`(1), `bats`(1)
|
9
test/bats/vendor/bats-0.4.0/package.json
vendored
9
test/bats/vendor/bats-0.4.0/package.json
vendored
@ -1,9 +0,0 @@
|
||||
{
|
||||
"name": "bats",
|
||||
"version": "0.3.1",
|
||||
"description": "Bash Automated Testing System",
|
||||
"global": "true",
|
||||
"install": "./install.sh /usr/local",
|
||||
"scripts": [ "libexec/bats", "libexec/bats-exec-suite", "libexec/bats-exec-test", "libexec/bats-format-tap-stream", "libexec/bats-preprocess", "bin/bats" ]
|
||||
}
|
||||
|
258
test/bats/vendor/bats-0.4.0/test/bats.bats
vendored
258
test/bats/vendor/bats-0.4.0/test/bats.bats
vendored
@ -1,258 +0,0 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
fixtures bats
|
||||
|
||||
@test "no arguments prints usage instructions" {
|
||||
run bats
|
||||
[ $status -eq 1 ]
|
||||
[ $(expr "${lines[1]}" : "Usage:") -ne 0 ]
|
||||
}
|
||||
|
||||
@test "-v and --version print version number" {
|
||||
run bats -v
|
||||
[ $status -eq 0 ]
|
||||
[ $(expr "$output" : "Bats [0-9][0-9.]*") -ne 0 ]
|
||||
}
|
||||
|
||||
@test "-h and --help print help" {
|
||||
run bats -h
|
||||
[ $status -eq 0 ]
|
||||
[ "${#lines[@]}" -gt 3 ]
|
||||
}
|
||||
|
||||
@test "invalid filename prints an error" {
|
||||
run bats nonexistent
|
||||
[ $status -eq 1 ]
|
||||
[ $(expr "$output" : ".*does not exist") -ne 0 ]
|
||||
}
|
||||
|
||||
@test "empty test file runs zero tests" {
|
||||
run bats "$FIXTURE_ROOT/empty.bats"
|
||||
[ $status -eq 0 ]
|
||||
[ $output = "1..0" ]
|
||||
}
|
||||
|
||||
@test "one passing test" {
|
||||
run bats "$FIXTURE_ROOT/passing.bats"
|
||||
[ $status -eq 0 ]
|
||||
[ ${lines[0]} = "1..1" ]
|
||||
[ ${lines[1]} = "ok 1 a passing test" ]
|
||||
}
|
||||
|
||||
@test "summary passing tests" {
|
||||
run filter_control_sequences bats -p $FIXTURE_ROOT/passing.bats
|
||||
[ $status -eq 0 ]
|
||||
[ "${lines[1]}" = "1 test, 0 failures" ]
|
||||
}
|
||||
|
||||
@test "summary passing and skipping tests" {
|
||||
run filter_control_sequences bats -p $FIXTURE_ROOT/passing_and_skipping.bats
|
||||
[ $status -eq 0 ]
|
||||
[ "${lines[2]}" = "2 tests, 0 failures, 1 skipped" ]
|
||||
}
|
||||
|
||||
@test "summary passing and failing tests" {
|
||||
run filter_control_sequences bats -p $FIXTURE_ROOT/failing_and_passing.bats
|
||||
[ $status -eq 0 ]
|
||||
[ "${lines[4]}" = "2 tests, 1 failure" ]
|
||||
}
|
||||
|
||||
@test "summary passing, failing and skipping tests" {
|
||||
run filter_control_sequences bats -p $FIXTURE_ROOT/passing_failing_and_skipping.bats
|
||||
[ $status -eq 0 ]
|
||||
[ "${lines[5]}" = "3 tests, 1 failure, 1 skipped" ]
|
||||
}
|
||||
|
||||
@test "one failing test" {
|
||||
run bats "$FIXTURE_ROOT/failing.bats"
|
||||
[ $status -eq 1 ]
|
||||
[ "${lines[0]}" = '1..1' ]
|
||||
[ "${lines[1]}" = 'not ok 1 a failing test' ]
|
||||
[ "${lines[2]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/failing.bats, line 4)" ]
|
||||
[ "${lines[3]}" = "# \`eval \"( exit \${STATUS:-1} )\"' failed" ]
|
||||
}
|
||||
|
||||
@test "one failing and one passing test" {
|
||||
run bats "$FIXTURE_ROOT/failing_and_passing.bats"
|
||||
[ $status -eq 1 ]
|
||||
[ "${lines[0]}" = '1..2' ]
|
||||
[ "${lines[1]}" = 'not ok 1 a failing test' ]
|
||||
[ "${lines[2]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/failing_and_passing.bats, line 2)" ]
|
||||
[ "${lines[3]}" = "# \`false' failed" ]
|
||||
[ "${lines[4]}" = 'ok 2 a passing test' ]
|
||||
}
|
||||
|
||||
@test "failing test with significant status" {
|
||||
STATUS=2 run bats "$FIXTURE_ROOT/failing.bats"
|
||||
[ $status -eq 1 ]
|
||||
[ "${lines[3]}" = "# \`eval \"( exit \${STATUS:-1} )\"' failed with status 2" ]
|
||||
}
|
||||
|
||||
@test "failing helper function logs the test case's line number" {
|
||||
run bats "$FIXTURE_ROOT/failing_helper.bats"
|
||||
[ $status -eq 1 ]
|
||||
[ "${lines[1]}" = 'not ok 1 failing helper function' ]
|
||||
[ "${lines[2]}" = "# (from function \`failing_helper' in file $RELATIVE_FIXTURE_ROOT/test_helper.bash, line 6," ]
|
||||
[ "${lines[3]}" = "# in test file $RELATIVE_FIXTURE_ROOT/failing_helper.bats, line 5)" ]
|
||||
[ "${lines[4]}" = "# \`failing_helper' failed" ]
|
||||
}
|
||||
|
||||
@test "test environments are isolated" {
|
||||
run bats "$FIXTURE_ROOT/environment.bats"
|
||||
[ $status -eq 0 ]
|
||||
}
|
||||
|
||||
@test "setup is run once before each test" {
|
||||
rm -f "$TMP/setup.log"
|
||||
run bats "$FIXTURE_ROOT/setup.bats"
|
||||
[ $status -eq 0 ]
|
||||
run cat "$TMP/setup.log"
|
||||
[ ${#lines[@]} -eq 3 ]
|
||||
}
|
||||
|
||||
@test "teardown is run once after each test, even if it fails" {
|
||||
rm -f "$TMP/teardown.log"
|
||||
run bats "$FIXTURE_ROOT/teardown.bats"
|
||||
[ $status -eq 1 ]
|
||||
run cat "$TMP/teardown.log"
|
||||
[ ${#lines[@]} -eq 3 ]
|
||||
}
|
||||
|
||||
@test "setup failure" {
|
||||
run bats "$FIXTURE_ROOT/failing_setup.bats"
|
||||
[ $status -eq 1 ]
|
||||
[ "${lines[1]}" = 'not ok 1 truth' ]
|
||||
[ "${lines[2]}" = "# (from function \`setup' in test file $RELATIVE_FIXTURE_ROOT/failing_setup.bats, line 2)" ]
|
||||
[ "${lines[3]}" = "# \`false' failed" ]
|
||||
}
|
||||
|
||||
@test "passing test with teardown failure" {
|
||||
PASS=1 run bats "$FIXTURE_ROOT/failing_teardown.bats"
|
||||
[ $status -eq 1 ]
|
||||
[ "${lines[1]}" = 'not ok 1 truth' ]
|
||||
[ "${lines[2]}" = "# (from function \`teardown' in test file $RELATIVE_FIXTURE_ROOT/failing_teardown.bats, line 2)" ]
|
||||
[ "${lines[3]}" = "# \`eval \"( exit \${STATUS:-1} )\"' failed" ]
|
||||
}
|
||||
|
||||
@test "failing test with teardown failure" {
|
||||
PASS=0 run bats "$FIXTURE_ROOT/failing_teardown.bats"
|
||||
[ $status -eq 1 ]
|
||||
[ "${lines[1]}" = 'not ok 1 truth' ]
|
||||
[ "${lines[2]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/failing_teardown.bats, line 6)" ]
|
||||
[ "${lines[3]}" = $'# `[ "$PASS" = "1" ]\' failed' ]
|
||||
}
|
||||
|
||||
@test "teardown failure with significant status" {
|
||||
PASS=1 STATUS=2 run bats "$FIXTURE_ROOT/failing_teardown.bats"
|
||||
[ $status -eq 1 ]
|
||||
[ "${lines[3]}" = "# \`eval \"( exit \${STATUS:-1} )\"' failed with status 2" ]
|
||||
}
|
||||
|
||||
@test "failing test file outside of BATS_CWD" {
|
||||
cd "$TMP"
|
||||
run bats "$FIXTURE_ROOT/failing.bats"
|
||||
[ $status -eq 1 ]
|
||||
[ "${lines[2]}" = "# (in test file $FIXTURE_ROOT/failing.bats, line 4)" ]
|
||||
}
|
||||
|
||||
@test "load sources scripts relative to the current test file" {
|
||||
run bats "$FIXTURE_ROOT/load.bats"
|
||||
[ $status -eq 0 ]
|
||||
}
|
||||
|
||||
@test "load aborts if the specified script does not exist" {
|
||||
HELPER_NAME="nonexistent" run bats "$FIXTURE_ROOT/load.bats"
|
||||
[ $status -eq 1 ]
|
||||
}
|
||||
|
||||
@test "load sources scripts by absolute path" {
|
||||
HELPER_NAME="${FIXTURE_ROOT}/test_helper.bash" run bats "$FIXTURE_ROOT/load.bats"
|
||||
[ $status -eq 0 ]
|
||||
}
|
||||
|
||||
@test "load aborts if the script, specified by an absolute path, does not exist" {
|
||||
HELPER_NAME="${FIXTURE_ROOT}/nonexistent" run bats "$FIXTURE_ROOT/load.bats"
|
||||
[ $status -eq 1 ]
|
||||
}
|
||||
|
||||
@test "output is discarded for passing tests and printed for failing tests" {
|
||||
run bats "$FIXTURE_ROOT/output.bats"
|
||||
[ $status -eq 1 ]
|
||||
[ "${lines[6]}" = '# failure stdout 1' ]
|
||||
[ "${lines[7]}" = '# failure stdout 2' ]
|
||||
[ "${lines[11]}" = '# failure stderr' ]
|
||||
}
|
||||
|
||||
@test "-c prints the number of tests" {
|
||||
run bats -c "$FIXTURE_ROOT/empty.bats"
|
||||
[ $status -eq 0 ]
|
||||
[ "$output" = "0" ]
|
||||
|
||||
run bats -c "$FIXTURE_ROOT/output.bats"
|
||||
[ $status -eq 0 ]
|
||||
[ "$output" = "4" ]
|
||||
}
|
||||
|
||||
@test "dash-e is not mangled on beginning of line" {
|
||||
run bats "$FIXTURE_ROOT/intact.bats"
|
||||
[ $status -eq 0 ]
|
||||
[ "${lines[1]}" = "ok 1 dash-e on beginning of line" ]
|
||||
}
|
||||
|
||||
@test "dos line endings are stripped before testing" {
|
||||
run bats "$FIXTURE_ROOT/dos_line.bats"
|
||||
[ $status -eq 0 ]
|
||||
}
|
||||
|
||||
@test "test file without trailing newline" {
|
||||
run bats "$FIXTURE_ROOT/without_trailing_newline.bats"
|
||||
[ $status -eq 0 ]
|
||||
[ "${lines[1]}" = "ok 1 truth" ]
|
||||
}
|
||||
|
||||
@test "skipped tests" {
|
||||
run bats "$FIXTURE_ROOT/skipped.bats"
|
||||
[ $status -eq 0 ]
|
||||
[ "${lines[1]}" = "ok 1 # skip a skipped test" ]
|
||||
[ "${lines[2]}" = "ok 2 # skip (a reason) a skipped test with a reason" ]
|
||||
}
|
||||
|
||||
@test "extended syntax" {
|
||||
run bats-exec-test -x "$FIXTURE_ROOT/failing_and_passing.bats"
|
||||
[ $status -eq 1 ]
|
||||
[ "${lines[1]}" = 'begin 1 a failing test' ]
|
||||
[ "${lines[2]}" = 'not ok 1 a failing test' ]
|
||||
[ "${lines[5]}" = 'begin 2 a passing test' ]
|
||||
[ "${lines[6]}" = 'ok 2 a passing test' ]
|
||||
}
|
||||
|
||||
@test "pretty and tap formats" {
|
||||
run bats --tap "$FIXTURE_ROOT/passing.bats"
|
||||
tap_output="$output"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
run bats --pretty "$FIXTURE_ROOT/passing.bats"
|
||||
pretty_output="$output"
|
||||
[ $status -eq 0 ]
|
||||
|
||||
[ "$tap_output" != "$pretty_output" ]
|
||||
}
|
||||
|
||||
@test "pretty formatter bails on invalid tap" {
|
||||
run bats --tap "$FIXTURE_ROOT/invalid_tap.bats"
|
||||
[ $status -eq 1 ]
|
||||
[ "${lines[0]}" = "This isn't TAP!" ]
|
||||
[ "${lines[1]}" = "Good day to you" ]
|
||||
}
|
||||
|
||||
@test "single-line tests" {
|
||||
run bats "$FIXTURE_ROOT/single_line.bats"
|
||||
[ $status -eq 1 ]
|
||||
[ "${lines[1]}" = 'ok 1 empty' ]
|
||||
[ "${lines[2]}" = 'ok 2 passing' ]
|
||||
[ "${lines[3]}" = 'ok 3 input redirection' ]
|
||||
[ "${lines[4]}" = 'not ok 4 failing' ]
|
||||
[ "${lines[5]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/single_line.bats, line 9)" ]
|
||||
[ "${lines[6]}" = $'# `@test "failing" { false; }\' failed' ]
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
@test "foo" {
|
||||
echo "foo"
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
@test "setting a variable" {
|
||||
variable=1
|
||||
[ $variable -eq 1 ]
|
||||
}
|
||||
|
||||
@test "variables do not persist across tests" {
|
||||
[ -z "$variable" ]
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
@test "a failing test" {
|
||||
true
|
||||
true
|
||||
eval "( exit ${STATUS:-1} )"
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
@test "a failing test" {
|
||||
false
|
||||
}
|
||||
|
||||
@test "a passing test" {
|
||||
true
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
load "test_helper"
|
||||
|
||||
@test "failing helper function" {
|
||||
true
|
||||
failing_helper
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
setup() {
|
||||
false
|
||||
}
|
||||
|
||||
@test "truth" {
|
||||
true
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
teardown() {
|
||||
eval "( exit ${STATUS:-1} )"
|
||||
}
|
||||
|
||||
@test "truth" {
|
||||
[ "$PASS" = "1" ]
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
@test "dash-e on beginning of line" {
|
||||
run cat - <<INPUT
|
||||
-e
|
||||
INPUT
|
||||
test "$output" = "-e"
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
echo "This isn't TAP!"
|
||||
echo "Good day to you"
|
||||
exit 1
|
||||
|
||||
@test "truth" {
|
||||
true
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
[ -n "$HELPER_NAME" ] || HELPER_NAME="test_helper"
|
||||
load "$HELPER_NAME"
|
||||
|
||||
@test "calling a loaded helper" {
|
||||
help_me
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
@test "success writing to stdout" {
|
||||
echo "success stdout 1"
|
||||
echo "success stdout 2"
|
||||
}
|
||||
|
||||
@test "success writing to stderr" {
|
||||
echo "success stderr" >&2
|
||||
}
|
||||
|
||||
@test "failure writing to stdout" {
|
||||
echo "failure stdout 1"
|
||||
echo "failure stdout 2"
|
||||
false
|
||||
}
|
||||
|
||||
@test "failure writing to stderr" {
|
||||
echo "failure stderr" >&2
|
||||
false
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
@test "a passing test" {
|
||||
true
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
@test "a passing test" {
|
||||
true
|
||||
}
|
||||
|
||||
@test "a failing test" {
|
||||
false
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
@test "a passing test" {
|
||||
true
|
||||
}
|
||||
|
||||
@test "a skipping test" {
|
||||
skip
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
@test "a passing test" {
|
||||
true
|
||||
}
|
||||
|
||||
@test "a skipping test" {
|
||||
skip
|
||||
}
|
||||
|
||||
@test "a failing test" {
|
||||
false
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
LOG="$TMP/setup.log"
|
||||
|
||||
setup() {
|
||||
echo "$BATS_TEST_NAME" >> "$LOG"
|
||||
}
|
||||
|
||||
@test "one" {
|
||||
[ "$(tail -n 1 "$LOG")" = "test_one" ]
|
||||
}
|
||||
|
||||
@test "two" {
|
||||
[ "$(tail -n 1 "$LOG")" = "test_two" ]
|
||||
}
|
||||
|
||||
@test "three" {
|
||||
[ "$(tail -n 1 "$LOG")" = "test_three" ]
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
@test "empty" { }
|
||||
|
||||
@test "passing" { true; }
|
||||
|
||||
@test "input redirection" { diff - <( echo hello ); } <<EOS
|
||||
hello
|
||||
EOS
|
||||
|
||||
@test "failing" { false; }
|
@ -1,7 +0,0 @@
|
||||
@test "a skipped test" {
|
||||
skip
|
||||
}
|
||||
|
||||
@test "a skipped test with a reason" {
|
||||
skip "a reason"
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
LOG="$TMP/teardown.log"
|
||||
|
||||
teardown() {
|
||||
echo "$BATS_TEST_NAME" >> "$LOG"
|
||||
}
|
||||
|
||||
@test "one" {
|
||||
true
|
||||
}
|
||||
|
||||
@test "two" {
|
||||
false
|
||||
}
|
||||
|
||||
@test "three" {
|
||||
true
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
help_me() {
|
||||
true
|
||||
}
|
||||
|
||||
failing_helper() {
|
||||
false
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
@test "truth" {
|
||||
true
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
@test "truth" {
|
||||
true
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
@test "more truth" {
|
||||
true
|
||||
}
|
||||
|
||||
@test "quasi-truth" {
|
||||
[ -z "$FLUNK" ]
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
@test "a passing test" {
|
||||
true
|
||||
}
|
64
test/bats/vendor/bats-0.4.0/test/suite.bats
vendored
64
test/bats/vendor/bats-0.4.0/test/suite.bats
vendored
@ -1,64 +0,0 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
fixtures suite
|
||||
|
||||
@test "running a suite with no test files" {
|
||||
run bats "$FIXTURE_ROOT/empty"
|
||||
[ $status -eq 0 ]
|
||||
[ $output = "1..0" ]
|
||||
}
|
||||
|
||||
@test "running a suite with one test file" {
|
||||
run bats "$FIXTURE_ROOT/single"
|
||||
[ $status -eq 0 ]
|
||||
[ ${lines[0]} = "1..1" ]
|
||||
[ ${lines[1]} = "ok 1 a passing test" ]
|
||||
}
|
||||
|
||||
@test "counting tests in a suite" {
|
||||
run bats -c "$FIXTURE_ROOT/single"
|
||||
[ $status -eq 0 ]
|
||||
[ $output -eq 1 ]
|
||||
|
||||
run bats -c "$FIXTURE_ROOT/multiple"
|
||||
[ $status -eq 0 ]
|
||||
[ $output -eq 3 ]
|
||||
}
|
||||
|
||||
@test "aggregated output of multiple tests in a suite" {
|
||||
run bats "$FIXTURE_ROOT/multiple"
|
||||
[ $status -eq 0 ]
|
||||
[ ${lines[0]} = "1..3" ]
|
||||
echo "$output" | grep "^ok . truth"
|
||||
echo "$output" | grep "^ok . more truth"
|
||||
echo "$output" | grep "^ok . quasi-truth"
|
||||
}
|
||||
|
||||
@test "a failing test in a suite results in an error exit code" {
|
||||
FLUNK=1 run bats "$FIXTURE_ROOT/multiple"
|
||||
[ $status -eq 1 ]
|
||||
[ ${lines[0]} = "1..3" ]
|
||||
echo "$output" | grep "^not ok . quasi-truth"
|
||||
}
|
||||
|
||||
@test "running an ad-hoc suite by specifying multiple test files" {
|
||||
run bats "$FIXTURE_ROOT/multiple/a.bats" "$FIXTURE_ROOT/multiple/b.bats"
|
||||
[ $status -eq 0 ]
|
||||
[ ${lines[0]} = "1..3" ]
|
||||
echo "$output" | grep "^ok . truth"
|
||||
echo "$output" | grep "^ok . more truth"
|
||||
echo "$output" | grep "^ok . quasi-truth"
|
||||
}
|
||||
|
||||
@test "extended syntax in suite" {
|
||||
FLUNK=1 run bats-exec-suite -x "$FIXTURE_ROOT/multiple/"*.bats
|
||||
[ $status -eq 1 ]
|
||||
[ "${lines[0]}" = "1..3" ]
|
||||
[ "${lines[1]}" = "begin 1 truth" ]
|
||||
[ "${lines[2]}" = "ok 1 truth" ]
|
||||
[ "${lines[3]}" = "begin 2 more truth" ]
|
||||
[ "${lines[4]}" = "ok 2 more truth" ]
|
||||
[ "${lines[5]}" = "begin 3 quasi-truth" ]
|
||||
[ "${lines[6]}" = "not ok 3 quasi-truth" ]
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
fixtures() {
|
||||
FIXTURE_ROOT="$BATS_TEST_DIRNAME/fixtures/$1"
|
||||
RELATIVE_FIXTURE_ROOT="$(bats_trim_filename "$FIXTURE_ROOT")"
|
||||
}
|
||||
|
||||
setup() {
|
||||
export TMP="$BATS_TEST_DIRNAME/tmp"
|
||||
}
|
||||
|
||||
filter_control_sequences() {
|
||||
"$@" | sed $'s,\x1b\\[[0-9;]*[a-zA-Z],,g'
|
||||
}
|
||||
|
||||
teardown() {
|
||||
[ -d "$TMP" ] && rm -f "$TMP"/*
|
||||
}
|
Loading…
Reference in New Issue
Block a user