From 654212310fbfcbb0cd566918f3b5874b8554f108 Mon Sep 17 00:00:00 2001 From: Mazedur Rahman Date: Wed, 22 Feb 2017 08:02:30 +0000 Subject: [PATCH 1/8] WIP: Added two quick Dockerfiles to compare bin vs. src packaging --- Dockerfile.bin | 15 +++++++++++++++ Dockerfile.src | 11 +++++++++++ 2 files changed, 26 insertions(+) create mode 100644 Dockerfile.bin create mode 100644 Dockerfile.src diff --git a/Dockerfile.bin b/Dockerfile.bin new file mode 100644 index 0000000..416207e --- /dev/null +++ b/Dockerfile.bin @@ -0,0 +1,15 @@ +FROM python:3.4-slim + +RUN apt-get update -y \ + && apt-get install -y curl \ + && apt-get clean + +RUN mkdir -p ~/.clusterrunner/dist \ + && cd ~/.clusterrunner \ + && curl -L https://cloud.box.com/shared/static/2pl4pi6ykvrbb9d06t4m.tgz > clusterrunner.tgz \ + && tar -zxvf clusterrunner.tgz -C ./dist \ + && cp ./dist/conf/default_clusterrunner.conf clusterrunner.conf \ + && chmod 600 clusterrunner.conf \ + && rm -f clusterrunner.tgz + +ENTRYPOINT ["/root/.clusterrunner/dist/clusterrunner"] diff --git a/Dockerfile.src b/Dockerfile.src new file mode 100644 index 0000000..1b69e5b --- /dev/null +++ b/Dockerfile.src @@ -0,0 +1,11 @@ +FROM python:3.4-slim + +RUN apt-get update -y \ + && apt-get install -y gcc git \ + && apt-get clean + +ADD . /src + +RUN pip install --upgrade -r /src/requirements.txt + +ENTRYPOINT ["/src/main.py"] From 39e69a823f7d73a0246ecf9d982d3c2dc83bd9c2 Mon Sep 17 00:00:00 2001 From: Mazedur Rahman Date: Tue, 28 Feb 2017 08:30:46 +0000 Subject: [PATCH 2/8] WIP: Initial commit to Dockerize ClusterRunner --- Dockerfile.bin | 2 + Dockerfile.src | 2 + docker-compose-bin.yml | 11 + docker-compose-src.yml | 7 + docs/docker/README.md | 24 ++ run-cr | 60 +++ test/bats/fixtures/.gitignore | 1 + test/bats/helpers/assertions/LICENSE | 22 ++ test/bats/helpers/assertions/README.md | 170 +++++++++ test/bats/helpers/assertions/all.bash | 139 +++++++ test/bats/helpers/assertions/package.json | 45 +++ test/bats/helpers/assertions/test/assert.bats | 29 ++ .../assertions/test/assert_contains.bats | 29 ++ .../helpers/assertions/test/assert_equal.bats | 29 ++ .../assertions/test/assert_failure.bats | 57 +++ .../helpers/assertions/test/assert_line.bats | 52 +++ .../assertions/test/assert_output.bats | 43 +++ .../test/assert_output_contains.bats | 43 +++ .../assertions/test/assert_starts_with.bats | 47 +++ .../assertions/test/assert_success.bats | 58 +++ test/bats/helpers/assertions/test/flunk.bats | 36 ++ test/bats/helpers/assertions/test/refute.bats | 29 ++ .../assertions/test/refute_contains.bats | 29 ++ .../helpers/assertions/test/refute_equal.bats | 29 ++ .../helpers/assertions/test/refute_line.bats | 52 +++ .../test/refute_output_contains.bats | 43 +++ test/bats/run-cr.bats | 18 + test/bats/test_helper.bash | 18 + test/bats/tmp/.gitignore | 1 + vendor/bats/.travis.yml | 5 + vendor/bats/LICENSE | 20 + vendor/bats/README.md | 293 +++++++++++++++ vendor/bats/bin/bats | 1 + vendor/bats/install.sh | 37 ++ vendor/bats/libexec/bats | 142 +++++++ vendor/bats/libexec/bats-exec-suite | 55 +++ vendor/bats/libexec/bats-exec-test | 346 ++++++++++++++++++ vendor/bats/libexec/bats-format-tap-stream | 165 +++++++++ vendor/bats/libexec/bats-preprocess | 52 +++ vendor/bats/man/Makefile | 10 + vendor/bats/man/README.md | 5 + vendor/bats/man/bats.1 | 101 +++++ vendor/bats/man/bats.1.ronn | 109 ++++++ vendor/bats/man/bats.7 | 178 +++++++++ vendor/bats/man/bats.7.ronn | 156 ++++++++ vendor/bats/package.json | 8 + vendor/bats/test/bats.bats | 264 +++++++++++++ vendor/bats/test/fixtures/bats/dos_line.bats | 3 + vendor/bats/test/fixtures/bats/empty.bats | 0 .../bats/test/fixtures/bats/environment.bats | 8 + vendor/bats/test/fixtures/bats/failing.bats | 5 + .../fixtures/bats/failing_and_passing.bats | 7 + .../test/fixtures/bats/failing_helper.bats | 6 + .../test/fixtures/bats/failing_setup.bats | 7 + .../test/fixtures/bats/failing_teardown.bats | 7 + vendor/bats/test/fixtures/bats/intact.bats | 6 + .../bats/test/fixtures/bats/invalid_tap.bats | 7 + vendor/bats/test/fixtures/bats/load.bats | 6 + .../test/fixtures/bats/loop_keep_IFS.bats | 16 + vendor/bats/test/fixtures/bats/output.bats | 19 + vendor/bats/test/fixtures/bats/passing.bats | 3 + .../fixtures/bats/passing_and_failing.bats | 7 + .../fixtures/bats/passing_and_skipping.bats | 7 + .../bats/passing_failing_and_skipping.bats | 11 + vendor/bats/test/fixtures/bats/setup.bats | 17 + .../bats/test/fixtures/bats/single_line.bats | 9 + vendor/bats/test/fixtures/bats/skipped.bats | 7 + vendor/bats/test/fixtures/bats/teardown.bats | 17 + .../bats/test/fixtures/bats/test_helper.bash | 7 + .../bats/without_trailing_newline.bats | 3 + .../bats/test/fixtures/suite/empty/.gitkeep | 0 .../bats/test/fixtures/suite/multiple/a.bats | 3 + .../bats/test/fixtures/suite/multiple/b.bats | 7 + .../bats/test/fixtures/suite/single/test.bats | 3 + vendor/bats/test/suite.bats | 64 ++++ vendor/bats/test/test_helper.bash | 16 + 76 files changed, 3350 insertions(+) create mode 100644 docker-compose-bin.yml create mode 100644 docker-compose-src.yml create mode 100644 docs/docker/README.md create mode 100755 run-cr create mode 100644 test/bats/fixtures/.gitignore create mode 100644 test/bats/helpers/assertions/LICENSE create mode 100644 test/bats/helpers/assertions/README.md create mode 100644 test/bats/helpers/assertions/all.bash create mode 100644 test/bats/helpers/assertions/package.json create mode 100755 test/bats/helpers/assertions/test/assert.bats create mode 100755 test/bats/helpers/assertions/test/assert_contains.bats create mode 100755 test/bats/helpers/assertions/test/assert_equal.bats create mode 100755 test/bats/helpers/assertions/test/assert_failure.bats create mode 100755 test/bats/helpers/assertions/test/assert_line.bats create mode 100755 test/bats/helpers/assertions/test/assert_output.bats create mode 100755 test/bats/helpers/assertions/test/assert_output_contains.bats create mode 100755 test/bats/helpers/assertions/test/assert_starts_with.bats create mode 100755 test/bats/helpers/assertions/test/assert_success.bats create mode 100755 test/bats/helpers/assertions/test/flunk.bats create mode 100755 test/bats/helpers/assertions/test/refute.bats create mode 100644 test/bats/helpers/assertions/test/refute_contains.bats create mode 100755 test/bats/helpers/assertions/test/refute_equal.bats create mode 100755 test/bats/helpers/assertions/test/refute_line.bats create mode 100644 test/bats/helpers/assertions/test/refute_output_contains.bats create mode 100644 test/bats/run-cr.bats create mode 100644 test/bats/test_helper.bash create mode 100644 test/bats/tmp/.gitignore create mode 100644 vendor/bats/.travis.yml create mode 100644 vendor/bats/LICENSE create mode 100644 vendor/bats/README.md create mode 120000 vendor/bats/bin/bats create mode 100755 vendor/bats/install.sh create mode 100755 vendor/bats/libexec/bats create mode 100755 vendor/bats/libexec/bats-exec-suite create mode 100755 vendor/bats/libexec/bats-exec-test create mode 100755 vendor/bats/libexec/bats-format-tap-stream create mode 100755 vendor/bats/libexec/bats-preprocess create mode 100644 vendor/bats/man/Makefile create mode 100644 vendor/bats/man/README.md create mode 100644 vendor/bats/man/bats.1 create mode 100644 vendor/bats/man/bats.1.ronn create mode 100644 vendor/bats/man/bats.7 create mode 100644 vendor/bats/man/bats.7.ronn create mode 100644 vendor/bats/package.json create mode 100755 vendor/bats/test/bats.bats create mode 100644 vendor/bats/test/fixtures/bats/dos_line.bats create mode 100644 vendor/bats/test/fixtures/bats/empty.bats create mode 100644 vendor/bats/test/fixtures/bats/environment.bats create mode 100644 vendor/bats/test/fixtures/bats/failing.bats create mode 100644 vendor/bats/test/fixtures/bats/failing_and_passing.bats create mode 100644 vendor/bats/test/fixtures/bats/failing_helper.bats create mode 100644 vendor/bats/test/fixtures/bats/failing_setup.bats create mode 100644 vendor/bats/test/fixtures/bats/failing_teardown.bats create mode 100644 vendor/bats/test/fixtures/bats/intact.bats create mode 100644 vendor/bats/test/fixtures/bats/invalid_tap.bats create mode 100644 vendor/bats/test/fixtures/bats/load.bats create mode 100644 vendor/bats/test/fixtures/bats/loop_keep_IFS.bats create mode 100644 vendor/bats/test/fixtures/bats/output.bats create mode 100644 vendor/bats/test/fixtures/bats/passing.bats create mode 100644 vendor/bats/test/fixtures/bats/passing_and_failing.bats create mode 100644 vendor/bats/test/fixtures/bats/passing_and_skipping.bats create mode 100644 vendor/bats/test/fixtures/bats/passing_failing_and_skipping.bats create mode 100644 vendor/bats/test/fixtures/bats/setup.bats create mode 100644 vendor/bats/test/fixtures/bats/single_line.bats create mode 100644 vendor/bats/test/fixtures/bats/skipped.bats create mode 100644 vendor/bats/test/fixtures/bats/teardown.bats create mode 100644 vendor/bats/test/fixtures/bats/test_helper.bash create mode 100644 vendor/bats/test/fixtures/bats/without_trailing_newline.bats create mode 100644 vendor/bats/test/fixtures/suite/empty/.gitkeep create mode 100644 vendor/bats/test/fixtures/suite/multiple/a.bats create mode 100644 vendor/bats/test/fixtures/suite/multiple/b.bats create mode 100644 vendor/bats/test/fixtures/suite/single/test.bats create mode 100755 vendor/bats/test/suite.bats create mode 100644 vendor/bats/test/test_helper.bash diff --git a/Dockerfile.bin b/Dockerfile.bin index 416207e..6835e02 100644 --- a/Dockerfile.bin +++ b/Dockerfile.bin @@ -12,4 +12,6 @@ RUN mkdir -p ~/.clusterrunner/dist \ && chmod 600 clusterrunner.conf \ && rm -f clusterrunner.tgz +EXPOSE 43000 43001 + ENTRYPOINT ["/root/.clusterrunner/dist/clusterrunner"] diff --git a/Dockerfile.src b/Dockerfile.src index 1b69e5b..94ec236 100644 --- a/Dockerfile.src +++ b/Dockerfile.src @@ -8,4 +8,6 @@ ADD . /src RUN pip install --upgrade -r /src/requirements.txt +EXPOSE 43000 43001 + ENTRYPOINT ["/src/main.py"] diff --git a/docker-compose-bin.yml b/docker-compose-bin.yml new file mode 100644 index 0000000..4f0a0b6 --- /dev/null +++ b/docker-compose-bin.yml @@ -0,0 +1,11 @@ +version: "2.1" +services: + cluserrunner: + build: + context: . + dockerfile: Dockerfile.bin + image: yamaszone/clusterrunner:bin + ports: + - "43000:43000" + - "43001:43001" + diff --git a/docker-compose-src.yml b/docker-compose-src.yml new file mode 100644 index 0000000..2cfebb3 --- /dev/null +++ b/docker-compose-src.yml @@ -0,0 +1,7 @@ +version: "2.1" +services: + cluserrunner: + build: + dockerfile: Dockerfile.src + image: yamaszone/clusterrunner:src + diff --git a/docs/docker/README.md b/docs/docker/README.md new file mode 100644 index 0000000..49818d8 --- /dev/null +++ b/docs/docker/README.md @@ -0,0 +1,24 @@ +## TODO for Dockerization + +* User Guide/Docs in [Docker Hub](https://hub.docker.com/r/yamaszone/clusterrunner/) (Container usage scenarios with when and when not) +* Technical Docs (Workflow: DEV-TEST-STG-PROD, Build, Versioning, Support/Maintenance) +* Add more assertions for tests +* Add maintainer +* Lean-ify image (consider tiny base e.g. busybox, alpine, etc.) +* Reorganize directory structure (cleaner project root preferred) + +## Requirements + +* [Docker Engine](https://docs.docker.com/installation/) version 1.12.x+ +* [Docker Compose](https://docs.docker.com/compose/) version 1.11.x+ with API version 2.1 + + +## Prerequisite Setup + +#### Install docker-compose on CoreOS +```sh +$ sudo su - +$ curl -L https://github.com/docker/compose/releases/download/1.11.2/docker-compose-`uname -s`-`uname -m` > /opt/bin/docker-compose +$ chmod +x /opt/bin/docker-compose +``` + diff --git a/run-cr b/run-cr new file mode 100755 index 0000000..9fcc446 --- /dev/null +++ b/run-cr @@ -0,0 +1,60 @@ +#!/bin/bash + +# This script automates the workflow around packaging CR using Docker. + +# yamaszone should be replaced with official user +DR_USR=yamaszone +CR_BIN=$DR_USR/clusterrunner:bin +CR_SRC=$DR_USR/clusterrunner:src + +build_images(){ + # *-src.yml only overrides 'dockerfile:' flavor and corresponding 'image:' name + docker-compose -f docker-compose-bin.yml -f docker-compose-src.yml build +} + +push_images(){ + # Uses Docker Hub as default + docker push $CR_BIN + docker push $CR_SRC +} + +help(){ + echo "Usage:" + printf "\t bin\t\t: Run ClusterRunner from binary.\n" + printf "\t build\t\t: Build ClusterRunner Docker images.\n" + printf "\t help\t\t: Show this help.\n" + printf "\t push\t\t: Push ClusterRunner images to Docker Hub.\n" + printf "\t src\t\t: Run ClusterRunner from source.\n" + printf "\t test-bats\t: Run BATS tests to validate image builds.\n" + exit 0 +} + +if [[ -z $1 ]];then + help + exit 0 +fi +# Inputs to pass on to CR via this script; exclude $1 +INPUTS=`echo "${@:2}"` + +case $1 in + bin) + docker run --rm -v $PWD:/cr -w /cr $CR_BIN $INPUTS + ;; + build) + build_images + ;; + push) + push_images + ;; + src) + docker run --rm -v $PWD:/cr -w /cr $CR_SRC $INPUTS + ;; + test-bats) + # TechDebt: Could be a target in Makefile + # CoreOS doesn't come with Make; so staying within it's limits + vendor/bats/bin/bats test/bats/ + ;; + * | help) + help + ;; +esac diff --git a/test/bats/fixtures/.gitignore b/test/bats/fixtures/.gitignore new file mode 100644 index 0000000..0523022 --- /dev/null +++ b/test/bats/fixtures/.gitignore @@ -0,0 +1 @@ +#ignore diff --git a/test/bats/helpers/assertions/LICENSE b/test/bats/helpers/assertions/LICENSE new file mode 100644 index 0000000..80955a7 --- /dev/null +++ b/test/bats/helpers/assertions/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2015 Jason Karns + +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. + diff --git a/test/bats/helpers/assertions/README.md b/test/bats/helpers/assertions/README.md new file mode 100644 index 0000000..c9049c0 --- /dev/null +++ b/test/bats/helpers/assertions/README.md @@ -0,0 +1,170 @@ +# bats-assert +Assertion library for BATS (Bash Automated Testing System) + +## Installation + +Recommended installation is via git submodule. Assuming your project's bats +tests are in `test`: + +``` sh +git submodule add https://github.com/jasonkarns/bats-assert test/helpers/assertions +git commit -am 'added bats-assert module' +``` + +then in `test/test_helper.bash`: + +``` bash +load helpers/assertions/all +``` + +(Optionally configure [sparse-checkout](http://git-scm.com/docs/git-read-tree#_sparse_checkout) if you're concerned with all the non-essential files being in your repo) + +Also available as an [npm module](https://www.npmjs.com/package/bats-assert) if you're into that sort of thing. + +``` sh +npm install --save-dev bats-assert +``` + +then in `test/test_helper.bash`: + +``` bash +load ../node_modules/bats-assert/all +``` + +## Assertion API + +### flunk +forces a test failure with an optional message + +``` bash +flunk +# or +flunk "expected blue skies" +``` + +### assert +asserts command returns successfully + +``` bash +assert my-command +assert [ 2 -eq 2 ] +``` + +### refute +asserts command returns unsuccessfully + +``` bash +refute invalid-command +refute [ 2 -eq 3 ] +``` + +### assert_success +asserts successful exit `$status` with (optional) `$output` + +``` bash +run my-command + +assert_success +# or +assert_success "expected output" +``` + +### assert_failure +asserts unsuccessful exit `$status` with (optional) `$output` + +``` bash +run my-command + +assert_failure +# or +assert_failure "expected output" +``` + +### assert_equal +asserts equality + +``` bash +actual="$(my-command)" +expected="my results" + +assert_equal expected actual +``` + +### assert_contains +asserts x contains y + +``` +assert_contains foobar oo +``` + +### refute_contains +asserts x does not contain y + +``` +refute_contains foobar baz +``` + +### assert_starts_with +asserts x starts with y + +``` +assert_starts_with foobar foo +``` + +### assert_output +asserts `$output` + +``` +run my-command + +assert_output "my results" +``` + +### assert_output_contains +asserts `$output` contains argument + +``` +run my-command + +assert_output_contains "results" +``` + +### refute_output_contains +asserts `$output` does not contain argument + +``` +run my-command + +refute_output_contains "unicorn" +``` + +### assert_line +asserts `$output` contains given line (at optional line index) + +``` +run my-command + +assert_line "my results" +# or +assert_line 0 "my results" +``` + +### refute_line +asserts `$output` does *not* contain given line + +``` +run my-command + +refute_line "thirsty rando" +``` + +## Credits + +Assertion functions taken from the test_helpers of [rbenv][], [ruby-build][], +and [rbenv-aliases][]. Many thanks to their authors and contributors: [Sam +Stephenson](https://github.com/sstephenson), [Mislav +Marohnić](https://github.com/mislav), and [Tim Pope](https://github.com/tpope). + +[rbenv]:https://github.com/sstephenson/rbenv +[ruby-build]:https://github.com/sstephenson/ruby-build +[rbenv-aliases]:https://github.com/tpope/rbenv-aliases diff --git a/test/bats/helpers/assertions/all.bash b/test/bats/helpers/assertions/all.bash new file mode 100644 index 0000000..952064c --- /dev/null +++ b/test/bats/helpers/assertions/all.bash @@ -0,0 +1,139 @@ +flunk() { + { if [ "$#" -eq 0 ]; then cat - + else echo "$@" + fi + } | sed "s:${BATS_TMPDIR}:\${BATS_TMPDIR}:g" >&2 + return 1 +} + +assert() { + if ! "$@"; then + flunk "failed: $@" + fi +} + +refute() { + if "$@"; then + flunk "expected to fail: $@" + fi +} + +assert_success() { + if [ "$status" -ne 0 ]; then + { echo "command failed with exit status $status" + echo "output: $output" + } | flunk + elif [ "$#" -gt 0 ]; then + assert_output "$1" + fi +} + +assert_failure() { + if [ "$status" -eq 0 ]; then + flunk "expected failed exit status" + elif [ "$#" -gt 0 ]; then + assert_output "$1" + fi +} + +assert_equal() { + if [ "$1" != "$2" ]; then + { echo "expected: $1" + echo "actual: $2" + } | flunk + fi +} + +refute_equal() { + if [ "$1" = "$2" ]; then + flunk "unexpectedly equal: $1" + fi +} + +assert_not_equal() { + refute_equal "$@" +} + +assert_contains() { + local haystack="$1" + local needle="$2" + echo "$haystack" | $(type -p ggrep grep | head -1) -F "$needle" >/dev/null || { + { echo "expected: $haystack" + echo "to contain: $needle" + } | flunk + } +} + +refute_contains() { + local haystack="$1" + local needle="$2" + ! assert_contains "$haystack" "$needle" || { + { echo "expected: $haystack" + echo "not to contain: $needle" + } | flunk + } +} + +assert_starts_with() { + if [ "$1" = "${1#${2}}" ]; then + { echo "expected: $1" + echo "to start with: $2" + } | flunk + fi +} + +assert_output() { + local expected + if [ $# -eq 0 ]; then expected="$(cat -)" + else expected="$1" + fi + assert_equal "$expected" "$output" +} + +assert_output_contains() { + local expected + if [ $# -eq 0 ]; then expected="$(cat -)" + else expected="$1" + fi + assert_contains "$output" "$expected" +} + +refute_output_contains() { + local expected + if [ $# -eq 0 ]; then expected="$(cat -)" + else expected="$1" + fi + refute_contains "$output" "$expected" +} + +assert_line() { + if [ "$1" -ge 0 ] 2>/dev/null; then + assert_equal "$2" "${lines[$1]}" + else + local line + for line in "${lines[@]}"; do + if [ "$line" = "$1" ]; then return 0; fi + done + { echo "expected line: $1" + echo "to be found in:" + ( IFS=$'\n'; echo "${lines[*]}" ) + } | flunk + fi +} + +refute_line() { + if [ "$1" -ge 0 ] 2>/dev/null; then + refute_equal "$2" "${lines[$1]}" + else + local line + for line in "${lines[@]}"; do + if [ "$line" = "$1" ]; then + { echo "expected to not find line: $line" + echo "in:" + ( IFS=$'\n'; echo "${lines[*]}" ) + } | flunk + return $? # in case flunk didn't exit the loop + fi + done + fi +} diff --git a/test/bats/helpers/assertions/package.json b/test/bats/helpers/assertions/package.json new file mode 100644 index 0000000..ba3b471 --- /dev/null +++ b/test/bats/helpers/assertions/package.json @@ -0,0 +1,45 @@ +{ + "name": "bats-assert", + "version": "1.1.0", + "description": "Assertion library for BATS (Bash Automated Testing System)", + "author": "Mislav Marohnić (http://mislav.net)", + "contributors": [ + "Sam Stephenson (http://sstephenson.us/)", + "Jason Karns (http://jason.karns.name/)" + ], + "homepage": "https://github.com/jasonkarns/bats-assert#readme", + "repository": { + "type": "git", + "url": "https://github.com/jasonkarns/bats-assert.git" + }, + "bugs": { + "url": "https://github.com/jasonkarns/bats-assert/issues" + }, + "scripts": { + "test": "bats test" + }, + "main": "all.bash", + "files": [ + "all.bash" + ], + "directories": { + "test": "test" + }, + "peerDependencies": { + "bats": "^0.4.2" + }, + "devDependencies": { + "bats": "^0.4.2" + }, + "license": "MIT", + "keywords": [ + "bash", + "bats", + "assert", + "assertion", + "expectation", + "shell", + "test", + "unit" + ] +} diff --git a/test/bats/helpers/assertions/test/assert.bats b/test/bats/helpers/assertions/test/assert.bats new file mode 100755 index 0000000..2a86e96 --- /dev/null +++ b/test/bats/helpers/assertions/test/assert.bats @@ -0,0 +1,29 @@ +#!/usr/bin/env bats + +load ../all + +@test "assert should pass with successful command" { + set +e + assert "true" + status=$? + set -e + + test $status = 0 +} + +@test "assert should fail for failed commands" { + set +e + assert "false" + status=$? + set -e + + test $status = 1 +} + +@test "assert should emit failure message for failed commands" { + set +e + stderr=$( { assert "false"; } 2>&1 ) + set -e + + test "$stderr" = "failed: false" +} diff --git a/test/bats/helpers/assertions/test/assert_contains.bats b/test/bats/helpers/assertions/test/assert_contains.bats new file mode 100755 index 0000000..c79764f --- /dev/null +++ b/test/bats/helpers/assertions/test/assert_contains.bats @@ -0,0 +1,29 @@ +#!/usr/bin/env bats + +load ../all + +@test "assert_contains should pass when it matches" { + set +e + assert_contains foobar bar + status=$? + set -e + + test $status = 0 +} + +@test "assert_contains should fail when it doesn't match" { + set +e + assert_contains foo bar + status=$? + set -e + + test $status = 1 +} + +@test "assert_contains should emit error message when fails" { + set +e + stderr=$( { assert_contains foo bar; } 2>&1 ) + set -e + + test "$stderr" = $'expected: foo\nto contain: bar' +} diff --git a/test/bats/helpers/assertions/test/assert_equal.bats b/test/bats/helpers/assertions/test/assert_equal.bats new file mode 100755 index 0000000..4e7b24e --- /dev/null +++ b/test/bats/helpers/assertions/test/assert_equal.bats @@ -0,0 +1,29 @@ +#!/usr/bin/env bats + +load ../all + +@test "assert_equal should pass when equal" { + set +e + assert_equal foo foo + status=$? + set -e + + test $status = 0 +} + +@test "assert_equal should fail when not equal" { + set +e + assert_equal foo bar + status=$? + set -e + + test $status = 1 +} + +@test "assert_equal should emit message on failure" { + set +e + stderr=$( { assert_equal foo bar; } 2>&1 ) + set -e + + test "$stderr" = $'expected: foo\nactual: bar' +} diff --git a/test/bats/helpers/assertions/test/assert_failure.bats b/test/bats/helpers/assertions/test/assert_failure.bats new file mode 100755 index 0000000..34c2d58 --- /dev/null +++ b/test/bats/helpers/assertions/test/assert_failure.bats @@ -0,0 +1,57 @@ +#!/usr/bin/env bats + +load ../all + +setup() { + status=7 + output="my bad" +} + +@test "assert_failure should pass on non-zero \$status" { + set +e + assert_failure + status=$? + set -e + + test $status = 0 +} + +@test "assert_failure should fail on 0 \$status" { + status=0 + + set +e + assert_failure + status=$? + set -e + + test $status = 1 +} + +@test "assert_failure should emit message on failure" { + status=0 + + set +e + stderr=$( { assert_failure; } 2>&1 ) + set -e + + test "$stderr" = $'expected failed exit status' +} + +@test "assert_failure should pass when output matching argument" { + set +e + assert_failure "my bad" + status=$? + set -e + + test $status = 0 +} + +@test "assert_failure should fail when output doesn't match argument" { + set +e + stderr=$( { assert_failure "good job"; } 2>&1 ) + status=$? + set -e + + test $status = 1 + test "$stderr" = $'expected: good job\nactual: my bad' +} diff --git a/test/bats/helpers/assertions/test/assert_line.bats b/test/bats/helpers/assertions/test/assert_line.bats new file mode 100755 index 0000000..4c3e3e2 --- /dev/null +++ b/test/bats/helpers/assertions/test/assert_line.bats @@ -0,0 +1,52 @@ +#!/usr/bin/env bats + +load ../all + +setup() { + lines=('one fish' 'two fish' 'red fish' 'blue fish') +} + +@test "assert_line should pass when the given line is found" { + set +e + assert_line "red fish" + status=$? + set -e + + test $status = 0 +} + +@test "assert_line should fail when the given line isn't found" { + set +e + assert_line "green eggs and ham" + status=$? + set -e + + test $status = 1 +} + +@test "assert_line should emit error message when it fails" { + set +e + stderr=$( { assert_line "green eggs and ham"; } 2>&1 ) + set -e + + test "$stderr" = $'expected line: green eggs and ham\nto be found in:\none fish\ntwo fish\nred fish\nblue fish' +} + +@test "assert_line can match against a given line index" { + # success + set +e + assert_line 2 "red fish" + status=$? + set -e + + test $status = 0 + + # failure + set +e + stderr=$( { assert_line 0 "red fish"; } 2>&1 ) + status=$? + set -e + + test $status = 1 + test "$stderr" = $'expected: red fish\nactual: one fish' +} diff --git a/test/bats/helpers/assertions/test/assert_output.bats b/test/bats/helpers/assertions/test/assert_output.bats new file mode 100755 index 0000000..bec19f0 --- /dev/null +++ b/test/bats/helpers/assertions/test/assert_output.bats @@ -0,0 +1,43 @@ +#!/usr/bin/env bats + +load ../all + +setup() { + output=foo +} + +@test "assert_output should pass when it matches" { + set +e + assert_output foo + status=$? + set -e + + test $status = 0 +} + +@test "assert_output should fail when it doesn't match" { + set +e + assert_output bar + status=$? + set -e + + test $status = 1 +} + +@test "assert_output should emit error message when fails" { + set +e + stderr=$( { assert_output bar; } 2>&1 ) + set -e + + test "$stderr" = $'expected: bar\nactual: foo' +} + +@test "assert_output can take argument from STDIN" { + set +e + stderr=$( { echo bar | assert_output; } 2>&1 ) + status=$? + set -e + + test $status = 1 + test "$stderr" = $'expected: bar\nactual: foo' +} diff --git a/test/bats/helpers/assertions/test/assert_output_contains.bats b/test/bats/helpers/assertions/test/assert_output_contains.bats new file mode 100755 index 0000000..49eaf19 --- /dev/null +++ b/test/bats/helpers/assertions/test/assert_output_contains.bats @@ -0,0 +1,43 @@ +#!/usr/bin/env bats + +load ../all + +setup() { + output=foobar +} + +@test "assert_output_contains should pass when true" { + set +e + assert_output_contains bar + status=$? + set -e + + test $status = 0 +} + +@test "assert_output_contains should fail when it doesn't match" { + set +e + assert_output_contains baz + status=$? + set -e + + test $status = 1 +} + +@test "assert_output_contains should emit error message when fails" { + set +e + stderr=$( { assert_output_contains baz; } 2>&1 ) + set -e + + test "$stderr" = $'expected: foobar\nto contain: baz' +} + +@test "assert_output_contains can take argument from STDIN" { + set +e + stderr=$( { echo baz | assert_output_contains; } 2>&1 ) + status=$? + set -e + + test $status = 1 + test "$stderr" = $'expected: foobar\nto contain: baz' +} diff --git a/test/bats/helpers/assertions/test/assert_starts_with.bats b/test/bats/helpers/assertions/test/assert_starts_with.bats new file mode 100755 index 0000000..2d70875 --- /dev/null +++ b/test/bats/helpers/assertions/test/assert_starts_with.bats @@ -0,0 +1,47 @@ +#!/usr/bin/env bats + +load ../all + +@test "assert_starts_with should pass when it matches" { + set +e + assert_starts_with foobar foo + status=$? + set -e + + test $status = 0 +} + +@test "assert_starts_with should fail when it doesn't match" { + set +e + assert_starts_with foo bar + status=$? + set -e + + test $status = 1 +} + +@test "assert_starts_with should emit error message when fails" { + set +e + stderr=$( { assert_starts_with foo bar; } 2>&1 ) + set -e + + test "$stderr" = $'expected: foo\nto start with: bar' +} + +@test "assert_starts_with should not match empty string" { + set +e + assert_starts_with foo "" + status=$? + set -e + + test $status = 1 +} + +@test "assert_starts_with should match original string" { + set +e + assert_starts_with foo foo + status=$? + set -e + + test $status = 0 +} diff --git a/test/bats/helpers/assertions/test/assert_success.bats b/test/bats/helpers/assertions/test/assert_success.bats new file mode 100755 index 0000000..5a63c17 --- /dev/null +++ b/test/bats/helpers/assertions/test/assert_success.bats @@ -0,0 +1,58 @@ +#!/usr/bin/env bats + +load ../all + +setup() { + status=0 + output="good job" +} + +@test "assert_success should pass on 0 \$status" { + set +e + assert_success + status=$? + set -e + + test $status = 0 +} + +@test "assert_success should fail on non-zero \$status" { + status=1 + + set +e + assert_success + status=$? + set -e + + test $status = 1 +} + +@test "assert_success should emit message on failure" { + status=7 + output="my bad" + + set +e + stderr=$( { assert_success; } 2>&1 ) + set -e + + test "$stderr" = $'command failed with exit status 7\noutput: my bad' +} + +@test "assert_success should pass when output matches argument" { + set +e + assert_success "good job" + status=$? + set -e + + test $status = 0 +} + +@test "assert_success should fail when output doesn't match argument" { + set +e + stderr=$( { assert_success "my bad"; } 2>&1 ) + status=$? + set -e + + test $status = 1 + test "$stderr" = $'expected: my bad\nactual: good job' +} diff --git a/test/bats/helpers/assertions/test/flunk.bats b/test/bats/helpers/assertions/test/flunk.bats new file mode 100755 index 0000000..32d397d --- /dev/null +++ b/test/bats/helpers/assertions/test/flunk.bats @@ -0,0 +1,36 @@ +#!/usr/bin/env bats + +load ../all + +@test "flunk returns status code of 1" { + set +e + flunk msg + status=$? + set -e + + test $status = 1 +} + +@test "flunk emits the given message to STDERR" { + set +e + stderr=$( { flunk message; } 2>&1 ) + set -e + + test "$stderr" = "message" +} + +@test "flunk accepts error message on STDIN" { + set +e + stderr=$( { echo message | flunk; } 2>&1 ) + set -e + + test "$stderr" = "message" +} + +@test "flunk replaces \$BATS_TMPDIR" { + set +e + stderr=$( { flunk "bats tmpdir: $BATS_TMPDIR"; } 2>&1 ) + set -e + + test "$stderr" = "bats tmpdir: \${BATS_TMPDIR}" +} diff --git a/test/bats/helpers/assertions/test/refute.bats b/test/bats/helpers/assertions/test/refute.bats new file mode 100755 index 0000000..2c57681 --- /dev/null +++ b/test/bats/helpers/assertions/test/refute.bats @@ -0,0 +1,29 @@ +#!/usr/bin/env bats + +load ../all + +@test "refute should pass with failed command" { + set +e + refute "false" + status=$? + set -e + + test $status = 0 +} + +@test "refute should fail for successful commands" { + set +e + refute "true" + status=$? + set -e + + test $status = 1 +} + +@test "refute should emit failure message for successful commands" { + set +e + stderr=$( { refute "true"; } 2>&1 ) + set -e + + test "$stderr" = "succeeded: true" +} diff --git a/test/bats/helpers/assertions/test/refute_contains.bats b/test/bats/helpers/assertions/test/refute_contains.bats new file mode 100644 index 0000000..b8453d3 --- /dev/null +++ b/test/bats/helpers/assertions/test/refute_contains.bats @@ -0,0 +1,29 @@ +#!/usr/bin/env bats + +load ../all + +@test "refute_contains should pass when needle isn't found" { + set +e + refute_contains foobar baz + status=$? + set -e + + test $status = 0 +} + +@test "refute_contains should fail when needle is found" { + set +e + refute_contains foobar bar + status=$? + set -e + + test $status = 1 +} + +@test "refute_contains should emit error message when fails" { + set +e + stderr=$( { refute_contains foobar bar; } 2>&1 ) + set -e + + test "$stderr" = $'expected: foobar\nnot to contain: bar' +} diff --git a/test/bats/helpers/assertions/test/refute_equal.bats b/test/bats/helpers/assertions/test/refute_equal.bats new file mode 100755 index 0000000..885c03c --- /dev/null +++ b/test/bats/helpers/assertions/test/refute_equal.bats @@ -0,0 +1,29 @@ +#!/usr/bin/env bats + +load ../all + +@test "refute_equal should fail when equal" { + set +e + refute_equal foo foo + status=$? + set -e + + test $status = 1 +} + +@test "refute_equal should pass when not equal" { + set +e + refute_equal foo bar + status=$? + set -e + + test $status = 0 +} + +@test "refute_equal should emit message on failure" { + set +e + stderr=$( { refute_equal foo foo; } 2>&1 ) + set -e + + test "$stderr" = $'unexpectedly equal: foo' +} diff --git a/test/bats/helpers/assertions/test/refute_line.bats b/test/bats/helpers/assertions/test/refute_line.bats new file mode 100755 index 0000000..f41706d --- /dev/null +++ b/test/bats/helpers/assertions/test/refute_line.bats @@ -0,0 +1,52 @@ +#!/usr/bin/env bats + +load ../all + +setup() { + lines=('one fish' 'two fish' 'red fish' 'blue fish') +} + +@test "refute_line should fail when the given line is found" { + set +e + refute_line "red fish" + status=$? + set -e + + test $status = 1 +} + +@test "refute_line should pass when the given line isn't found" { + set +e + refute_line "green eggs and ham" + status=$? + set -e + + test $status = 0 +} + +@test "refute_line should emit error message when it fails" { + set +e + stderr=$( { refute_line "red fish"; } 2>&1 ) + set -e + + test "$stderr" = $'expected to not find line: red fish\nin:\none fish\ntwo fish\nred fish\nblue fish' +} + +@test "refute_line can match against a given line index" { + # success + set +e + refute_line 0 "red fish" + status=$? + set -e + + test $status = 0 + + # failure + set +e + stderr=$( { refute_line 2 "red fish"; } 2>&1 ) + status=$? + set -e + + test $status = 1 + test "$stderr" = $'unexpectedly equal: red fish' +} diff --git a/test/bats/helpers/assertions/test/refute_output_contains.bats b/test/bats/helpers/assertions/test/refute_output_contains.bats new file mode 100644 index 0000000..cb6bda1 --- /dev/null +++ b/test/bats/helpers/assertions/test/refute_output_contains.bats @@ -0,0 +1,43 @@ +#!/usr/bin/env bats + +load ../all + +setup() { + output=foobar +} + +@test "refute_output_contains should pass when output doesn't contain needle" { + set +e + refute_output_contains baz + status=$? + set -e + + test $status = 0 +} + +@test "refute_output_contains should fail when output contains needle" { + set +e + refute_output_contains bar + status=$? + set -e + + test $status = 1 +} + +@test "refute_output_contains should emit error message when fails" { + set +e + stderr=$( { refute_output_contains bar; } 2>&1 ) + set -e + + test "$stderr" = $'expected: foobar\nnot to contain: bar' +} + +@test "refute_output_contains can take argument from STDIN" { + set +e + stderr=$( { echo bar | refute_output_contains; } 2>&1 ) + status=$? + set -e + + test $status = 1 + test "$stderr" = $'expected: foobar\nnot to contain: bar' +} diff --git a/test/bats/run-cr.bats b/test/bats/run-cr.bats new file mode 100644 index 0000000..b662d40 --- /dev/null +++ b/test/bats/run-cr.bats @@ -0,0 +1,18 @@ +#!/usr/bin/env bats + +load test_helper + +@test "'run-cr' script displays help." { + run ./run-cr + assert_contains "$output" "Usage:" +} + +@test "CR-BIN: Help msg displayed by image built from binary." { + run ./run-cr bin -h + assert_contains "$output" "usage: clusterrunner" +} + +@test "CR-SRC: Help msg displayed by image built from source." { + run ./run-cr src -h + assert_contains "$output" "usage: main.py" +} diff --git a/test/bats/test_helper.bash b/test/bats/test_helper.bash new file mode 100644 index 0000000..8eb058b --- /dev/null +++ b/test/bats/test_helper.bash @@ -0,0 +1,18 @@ +load helpers/assertions/all + +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"/* +} diff --git a/test/bats/tmp/.gitignore b/test/bats/tmp/.gitignore new file mode 100644 index 0000000..0523022 --- /dev/null +++ b/test/bats/tmp/.gitignore @@ -0,0 +1 @@ +#ignore diff --git a/vendor/bats/.travis.yml b/vendor/bats/.travis.yml new file mode 100644 index 0000000..db06d9d --- /dev/null +++ b/vendor/bats/.travis.yml @@ -0,0 +1,5 @@ +language: c +script: bin/bats --tap test +notifications: + email: + on_success: never diff --git a/vendor/bats/LICENSE b/vendor/bats/LICENSE new file mode 100644 index 0000000..bac4eb2 --- /dev/null +++ b/vendor/bats/LICENSE @@ -0,0 +1,20 @@ +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. diff --git a/vendor/bats/README.md b/vendor/bats/README.md new file mode 100644 index 0000000..00c3105 --- /dev/null +++ b/vendor/bats/README.md @@ -0,0 +1,293 @@ +# 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 " ] +} +``` + +### `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. diff --git a/vendor/bats/bin/bats b/vendor/bats/bin/bats new file mode 120000 index 0000000..a50a884 --- /dev/null +++ b/vendor/bats/bin/bats @@ -0,0 +1 @@ +../libexec/bats \ No newline at end of file diff --git a/vendor/bats/install.sh b/vendor/bats/install.sh new file mode 100755 index 0000000..8bbdd16 --- /dev/null +++ b/vendor/bats/install.sh @@ -0,0 +1,37 @@ +#!/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 " + 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" diff --git a/vendor/bats/libexec/bats b/vendor/bats/libexec/bats new file mode 100755 index 0000000..71f392f --- /dev/null +++ b/vendor/bats/libexec/bats @@ -0,0 +1,142 @@ +#!/usr/bin/env bash +set -e + +version() { + echo "Bats 0.4.0" +} + +usage() { + version + echo "Usage: bats [-c] [-p | -t] [ ...]" +} + +help() { + usage + echo + echo " 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" diff --git a/vendor/bats/libexec/bats-exec-suite b/vendor/bats/libexec/bats-exec-suite new file mode 100755 index 0000000..29ab255 --- /dev/null +++ b/vendor/bats/libexec/bats-exec-suite @@ -0,0 +1,55 @@ +#!/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" diff --git a/vendor/bats/libexec/bats-exec-test b/vendor/bats/libexec/bats-exec-test new file mode 100755 index 0000000..8f3bd51 --- /dev/null +++ b/vendor/bats/libexec/bats-exec-test @@ -0,0 +1,346 @@ +#!/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 " >&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 oldIFS + [[ ! "$-" =~ e ]] || e=1 + [[ ! "$-" =~ E ]] || E=1 + [[ ! "$-" =~ T ]] || T=1 + set +e + set +E + set +T + output="$("$@" 2>&1)" + status="$?" + oldIFS=$IFS + IFS=$'\n' lines=($output) + [ -z "$e" ] || set -e + [ -z "$E" ] || set -E + [ -z "$T" ] || set -T + IFS=$oldIFS +} + +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 diff --git a/vendor/bats/libexec/bats-format-tap-stream b/vendor/bats/libexec/bats-format-tap-stream new file mode 100755 index 0000000..614768f --- /dev/null +++ b/vendor/bats/libexec/bats-format-tap-stream @@ -0,0 +1,165 @@ +#!/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 diff --git a/vendor/bats/libexec/bats-preprocess b/vendor/bats/libexec/bats-preprocess new file mode 100755 index 0000000..04297ed --- /dev/null +++ b/vendor/bats/libexec/bats-preprocess @@ -0,0 +1,52 @@ +#!/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 [ ...] + + 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. + + + diff --git a/vendor/bats/man/bats.7 b/vendor/bats/man/bats.7 new file mode 100644 index 0000000..d0836e5 --- /dev/null +++ b/vendor/bats/man/bats.7 @@ -0,0 +1,178 @@ +.\" 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 " ] +} +. +.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) diff --git a/vendor/bats/man/bats.7.ronn b/vendor/bats/man/bats.7.ronn new file mode 100644 index 0000000..7f6dd18 --- /dev/null +++ b/vendor/bats/man/bats.7.ronn @@ -0,0 +1,156 @@ +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 " ] + } + + +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) diff --git a/vendor/bats/package.json b/vendor/bats/package.json new file mode 100644 index 0000000..6bcff0c --- /dev/null +++ b/vendor/bats/package.json @@ -0,0 +1,8 @@ +{ + "name": "bats", + "version": "v0.4.0", + "description": "Bash Automated Testing System", + "install": "./install.sh ${PREFIX:-/usr/local}", + "scripts": [ "libexec/bats", "libexec/bats-exec-suite", "libexec/bats-exec-test", "libexec/bats-format-tap-stream", "libexec/bats-preprocess", "bin/bats" ] +} + diff --git a/vendor/bats/test/bats.bats b/vendor/bats/test/bats.bats new file mode 100755 index 0000000..f1aff29 --- /dev/null +++ b/vendor/bats/test/bats.bats @@ -0,0 +1,264 @@ +#!/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' ] +} + +@test "testing IFS not modified by run" { + run bats "$FIXTURE_ROOT/loop_keep_IFS.bats" + [ $status -eq 0 ] + [ "${lines[1]}" = "ok 1 loop_func" ] +} diff --git a/vendor/bats/test/fixtures/bats/dos_line.bats b/vendor/bats/test/fixtures/bats/dos_line.bats new file mode 100644 index 0000000..d04c17f --- /dev/null +++ b/vendor/bats/test/fixtures/bats/dos_line.bats @@ -0,0 +1,3 @@ +@test "foo" { + echo "foo" +} diff --git a/vendor/bats/test/fixtures/bats/empty.bats b/vendor/bats/test/fixtures/bats/empty.bats new file mode 100644 index 0000000..e69de29 diff --git a/vendor/bats/test/fixtures/bats/environment.bats b/vendor/bats/test/fixtures/bats/environment.bats new file mode 100644 index 0000000..8d3b984 --- /dev/null +++ b/vendor/bats/test/fixtures/bats/environment.bats @@ -0,0 +1,8 @@ +@test "setting a variable" { + variable=1 + [ $variable -eq 1 ] +} + +@test "variables do not persist across tests" { + [ -z "$variable" ] +} diff --git a/vendor/bats/test/fixtures/bats/failing.bats b/vendor/bats/test/fixtures/bats/failing.bats new file mode 100644 index 0000000..13be78c --- /dev/null +++ b/vendor/bats/test/fixtures/bats/failing.bats @@ -0,0 +1,5 @@ +@test "a failing test" { + true + true + eval "( exit ${STATUS:-1} )" +} diff --git a/vendor/bats/test/fixtures/bats/failing_and_passing.bats b/vendor/bats/test/fixtures/bats/failing_and_passing.bats new file mode 100644 index 0000000..5513a9b --- /dev/null +++ b/vendor/bats/test/fixtures/bats/failing_and_passing.bats @@ -0,0 +1,7 @@ +@test "a failing test" { + false +} + +@test "a passing test" { + true +} diff --git a/vendor/bats/test/fixtures/bats/failing_helper.bats b/vendor/bats/test/fixtures/bats/failing_helper.bats new file mode 100644 index 0000000..fb5726f --- /dev/null +++ b/vendor/bats/test/fixtures/bats/failing_helper.bats @@ -0,0 +1,6 @@ +load "test_helper" + +@test "failing helper function" { + true + failing_helper +} diff --git a/vendor/bats/test/fixtures/bats/failing_setup.bats b/vendor/bats/test/fixtures/bats/failing_setup.bats new file mode 100644 index 0000000..9a35587 --- /dev/null +++ b/vendor/bats/test/fixtures/bats/failing_setup.bats @@ -0,0 +1,7 @@ +setup() { + false +} + +@test "truth" { + true +} diff --git a/vendor/bats/test/fixtures/bats/failing_teardown.bats b/vendor/bats/test/fixtures/bats/failing_teardown.bats new file mode 100644 index 0000000..28eebf6 --- /dev/null +++ b/vendor/bats/test/fixtures/bats/failing_teardown.bats @@ -0,0 +1,7 @@ +teardown() { + eval "( exit ${STATUS:-1} )" +} + +@test "truth" { + [ "$PASS" = "1" ] +} diff --git a/vendor/bats/test/fixtures/bats/intact.bats b/vendor/bats/test/fixtures/bats/intact.bats new file mode 100644 index 0000000..c25c28c --- /dev/null +++ b/vendor/bats/test/fixtures/bats/intact.bats @@ -0,0 +1,6 @@ +@test "dash-e on beginning of line" { + run cat - <&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 +} diff --git a/vendor/bats/test/fixtures/bats/passing.bats b/vendor/bats/test/fixtures/bats/passing.bats new file mode 100644 index 0000000..e8182ce --- /dev/null +++ b/vendor/bats/test/fixtures/bats/passing.bats @@ -0,0 +1,3 @@ +@test "a passing test" { + true +} diff --git a/vendor/bats/test/fixtures/bats/passing_and_failing.bats b/vendor/bats/test/fixtures/bats/passing_and_failing.bats new file mode 100644 index 0000000..7b7d8ee --- /dev/null +++ b/vendor/bats/test/fixtures/bats/passing_and_failing.bats @@ -0,0 +1,7 @@ +@test "a passing test" { + true +} + +@test "a failing test" { + false +} diff --git a/vendor/bats/test/fixtures/bats/passing_and_skipping.bats b/vendor/bats/test/fixtures/bats/passing_and_skipping.bats new file mode 100644 index 0000000..88d74be --- /dev/null +++ b/vendor/bats/test/fixtures/bats/passing_and_skipping.bats @@ -0,0 +1,7 @@ +@test "a passing test" { + true +} + +@test "a skipping test" { + skip +} diff --git a/vendor/bats/test/fixtures/bats/passing_failing_and_skipping.bats b/vendor/bats/test/fixtures/bats/passing_failing_and_skipping.bats new file mode 100644 index 0000000..3c9f17f --- /dev/null +++ b/vendor/bats/test/fixtures/bats/passing_failing_and_skipping.bats @@ -0,0 +1,11 @@ +@test "a passing test" { + true +} + +@test "a skipping test" { + skip +} + +@test "a failing test" { + false +} diff --git a/vendor/bats/test/fixtures/bats/setup.bats b/vendor/bats/test/fixtures/bats/setup.bats new file mode 100644 index 0000000..3cc52cc --- /dev/null +++ b/vendor/bats/test/fixtures/bats/setup.bats @@ -0,0 +1,17 @@ +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" ] +} diff --git a/vendor/bats/test/fixtures/bats/single_line.bats b/vendor/bats/test/fixtures/bats/single_line.bats new file mode 100644 index 0000000..fc342d9 --- /dev/null +++ b/vendor/bats/test/fixtures/bats/single_line.bats @@ -0,0 +1,9 @@ +@test "empty" { } + +@test "passing" { true; } + +@test "input redirection" { diff - <( echo hello ); } <> "$LOG" +} + +@test "one" { + true +} + +@test "two" { + false +} + +@test "three" { + true +} diff --git a/vendor/bats/test/fixtures/bats/test_helper.bash b/vendor/bats/test/fixtures/bats/test_helper.bash new file mode 100644 index 0000000..530d034 --- /dev/null +++ b/vendor/bats/test/fixtures/bats/test_helper.bash @@ -0,0 +1,7 @@ +help_me() { + true +} + +failing_helper() { + false +} diff --git a/vendor/bats/test/fixtures/bats/without_trailing_newline.bats b/vendor/bats/test/fixtures/bats/without_trailing_newline.bats new file mode 100644 index 0000000..e3ace8b --- /dev/null +++ b/vendor/bats/test/fixtures/bats/without_trailing_newline.bats @@ -0,0 +1,3 @@ +@test "truth" { + true +} \ No newline at end of file diff --git a/vendor/bats/test/fixtures/suite/empty/.gitkeep b/vendor/bats/test/fixtures/suite/empty/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/vendor/bats/test/fixtures/suite/multiple/a.bats b/vendor/bats/test/fixtures/suite/multiple/a.bats new file mode 100644 index 0000000..fbc1f38 --- /dev/null +++ b/vendor/bats/test/fixtures/suite/multiple/a.bats @@ -0,0 +1,3 @@ +@test "truth" { + true +} diff --git a/vendor/bats/test/fixtures/suite/multiple/b.bats b/vendor/bats/test/fixtures/suite/multiple/b.bats new file mode 100644 index 0000000..bb965a4 --- /dev/null +++ b/vendor/bats/test/fixtures/suite/multiple/b.bats @@ -0,0 +1,7 @@ +@test "more truth" { + true +} + +@test "quasi-truth" { + [ -z "$FLUNK" ] +} diff --git a/vendor/bats/test/fixtures/suite/single/test.bats b/vendor/bats/test/fixtures/suite/single/test.bats new file mode 100644 index 0000000..e8182ce --- /dev/null +++ b/vendor/bats/test/fixtures/suite/single/test.bats @@ -0,0 +1,3 @@ +@test "a passing test" { + true +} diff --git a/vendor/bats/test/suite.bats b/vendor/bats/test/suite.bats new file mode 100755 index 0000000..5371686 --- /dev/null +++ b/vendor/bats/test/suite.bats @@ -0,0 +1,64 @@ +#!/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" ] +} diff --git a/vendor/bats/test/test_helper.bash b/vendor/bats/test/test_helper.bash new file mode 100644 index 0000000..84eee8c --- /dev/null +++ b/vendor/bats/test/test_helper.bash @@ -0,0 +1,16 @@ +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"/* +} From 7449a41c289020fd5f338962996b586b72b1e258 Mon Sep 17 00:00:00 2001 From: Mazedur Rahman Date: Fri, 10 Mar 2017 23:17:45 -0800 Subject: [PATCH 3/8] Added docs for users and developers --- docs/docker/README.md | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/docs/docker/README.md b/docs/docker/README.md index 49818d8..34a4bd1 100644 --- a/docs/docker/README.md +++ b/docs/docker/README.md @@ -1,24 +1,50 @@ ## TODO for Dockerization - -* User Guide/Docs in [Docker Hub](https://hub.docker.com/r/yamaszone/clusterrunner/) (Container usage scenarios with when and when not) -* Technical Docs (Workflow: DEV-TEST-STG-PROD, Build, Versioning, Support/Maintenance) * Add more assertions for tests * Add maintainer * Lean-ify image (consider tiny base e.g. busybox, alpine, etc.) * Reorganize directory structure (cleaner project root preferred) -## Requirements +## User Guide +#### Usage Scenarios +[ClusterRunner container](https://hub.docker.com/r/yamaszone/clusterrunner/) is a good choice if your application runtime environment supports [Docker Engine](https://docs.docker.com/engine/installation/). For example, if your application under test is running on macOS with Docker Engine installed, then you can easily use the ClusterRunner Docker container to run tests in parallel. +To see ClusterRunner CLI help, run the following command: -* [Docker Engine](https://docs.docker.com/installation/) version 1.12.x+ -* [Docker Compose](https://docs.docker.com/compose/) version 1.11.x+ with API version 2.1 +`docker run --rm -v /path/to/system/under/test:/sut -w /sut yamaszone/clusterrunner:bin -h` +See [Quick Start](http://www.clusterrunner.com/docs/quickstart/) guide to configure your project to use ClusterRunner. -## Prerequisite Setup +**NOTE**: ClusterRunner container is yet to add parallel testing support easily for applications that run as containers. -#### Install docker-compose on CoreOS +## Developer Guide +Currently we are maintaining two flavors of Dockerfiles for ClusterRunner: +* `Dockerfile.bin`: Build ClusterRunner image from binary with minimal image size +* `Dockerfile.src`: Build ClusterRunner image from source +In the future, we plan to maintain `Dockerfile.src` only after simplifying some dependencies mentioned [here](https://github.com/box/ClusterRunner/issues/328). + +#### Requirements +* [Docker Engine](https://docs.docker.com/engine/installation/) version 1.12.x+ +* [Docker Compose](https://docs.docker.com/compose/) version 1.11.x+ with API version 2.1 + +#### Requirements Setup +* Install docker-compose on CoreOS ```sh $ sudo su - $ curl -L https://github.com/docker/compose/releases/download/1.11.2/docker-compose-`uname -s`-`uname -m` > /opt/bin/docker-compose $ chmod +x /opt/bin/docker-compose ``` +* For other platforms, see instructions [here](https://docs.docker.com/compose/install/) +``` +$ curl -L "https://github.com/docker/compose/releases/download/1.11.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose +$ chmod +x /usr/local/bin/docker-compose +``` +#### Development/Test Workflow +We use `docker-compose` to maintain two flavors of Docker images: `docker-compose-bin.yml` for `Dockerfile.bin` and `docker-compose-src.yml` for `Dockerfile.src`. Project root contains a convenient script `run-cr` to easily build/test/push Docker images (see `./run-cr help`): +* Build + - Run `./run-cr build` to build both flavors of ClusterRunner containers +* Test + - Run `./run-cr test-bats` to run sanity tests for the ClusterRunner containers. We use lightweight [BATS](https://github.com/sstephenson/bats) framework to write automated tests (see `test/bats`) for the ClusterRunner images. +* Push + - Run `./run-cr push` to push ClusterRunner images to Docker Hub +* Image Versions + - Currently [ClusterRunner images](https://hub.docker.com/r/yamaszone/clusterrunner/tags/) are tagged as `bin` and `src`. To improve maintainability of these images, we will concatenate ClusterRunner versions with the container tags in the future. From bf009999be7ddd92955d68fe6fe7a1f89596b150 Mon Sep 17 00:00:00 2001 From: Mazedur Rahman Date: Sun, 12 Mar 2017 05:44:21 +0000 Subject: [PATCH 4/8] Installed BATS properly instead of adding it to the codebase --- run-cr | 24 +- vendor/bats/.travis.yml | 5 - vendor/bats/LICENSE | 20 - vendor/bats/README.md | 293 --------------- vendor/bats/bin/bats | 1 - vendor/bats/install.sh | 37 -- vendor/bats/libexec/bats | 142 ------- vendor/bats/libexec/bats-exec-suite | 55 --- vendor/bats/libexec/bats-exec-test | 346 ------------------ vendor/bats/libexec/bats-format-tap-stream | 165 --------- vendor/bats/libexec/bats-preprocess | 52 --- vendor/bats/man/Makefile | 10 - vendor/bats/man/README.md | 5 - vendor/bats/man/bats.1 | 101 ----- vendor/bats/man/bats.1.ronn | 109 ------ vendor/bats/man/bats.7 | 178 --------- vendor/bats/man/bats.7.ronn | 156 -------- vendor/bats/package.json | 8 - vendor/bats/test/bats.bats | 264 ------------- vendor/bats/test/fixtures/bats/dos_line.bats | 3 - vendor/bats/test/fixtures/bats/empty.bats | 0 .../bats/test/fixtures/bats/environment.bats | 8 - vendor/bats/test/fixtures/bats/failing.bats | 5 - .../fixtures/bats/failing_and_passing.bats | 7 - .../test/fixtures/bats/failing_helper.bats | 6 - .../test/fixtures/bats/failing_setup.bats | 7 - .../test/fixtures/bats/failing_teardown.bats | 7 - vendor/bats/test/fixtures/bats/intact.bats | 6 - .../bats/test/fixtures/bats/invalid_tap.bats | 7 - vendor/bats/test/fixtures/bats/load.bats | 6 - .../test/fixtures/bats/loop_keep_IFS.bats | 16 - vendor/bats/test/fixtures/bats/output.bats | 19 - vendor/bats/test/fixtures/bats/passing.bats | 3 - .../fixtures/bats/passing_and_failing.bats | 7 - .../fixtures/bats/passing_and_skipping.bats | 7 - .../bats/passing_failing_and_skipping.bats | 11 - vendor/bats/test/fixtures/bats/setup.bats | 17 - .../bats/test/fixtures/bats/single_line.bats | 9 - vendor/bats/test/fixtures/bats/skipped.bats | 7 - vendor/bats/test/fixtures/bats/teardown.bats | 17 - .../bats/test/fixtures/bats/test_helper.bash | 7 - .../bats/without_trailing_newline.bats | 3 - .../bats/test/fixtures/suite/empty/.gitkeep | 0 .../bats/test/fixtures/suite/multiple/a.bats | 3 - .../bats/test/fixtures/suite/multiple/b.bats | 7 - .../bats/test/fixtures/suite/single/test.bats | 3 - vendor/bats/test/suite.bats | 64 ---- vendor/bats/test/test_helper.bash | 16 - 48 files changed, 21 insertions(+), 2228 deletions(-) delete mode 100644 vendor/bats/.travis.yml delete mode 100644 vendor/bats/LICENSE delete mode 100644 vendor/bats/README.md delete mode 120000 vendor/bats/bin/bats delete mode 100755 vendor/bats/install.sh delete mode 100755 vendor/bats/libexec/bats delete mode 100755 vendor/bats/libexec/bats-exec-suite delete mode 100755 vendor/bats/libexec/bats-exec-test delete mode 100755 vendor/bats/libexec/bats-format-tap-stream delete mode 100755 vendor/bats/libexec/bats-preprocess delete mode 100644 vendor/bats/man/Makefile delete mode 100644 vendor/bats/man/README.md delete mode 100644 vendor/bats/man/bats.1 delete mode 100644 vendor/bats/man/bats.1.ronn delete mode 100644 vendor/bats/man/bats.7 delete mode 100644 vendor/bats/man/bats.7.ronn delete mode 100644 vendor/bats/package.json delete mode 100755 vendor/bats/test/bats.bats delete mode 100644 vendor/bats/test/fixtures/bats/dos_line.bats delete mode 100644 vendor/bats/test/fixtures/bats/empty.bats delete mode 100644 vendor/bats/test/fixtures/bats/environment.bats delete mode 100644 vendor/bats/test/fixtures/bats/failing.bats delete mode 100644 vendor/bats/test/fixtures/bats/failing_and_passing.bats delete mode 100644 vendor/bats/test/fixtures/bats/failing_helper.bats delete mode 100644 vendor/bats/test/fixtures/bats/failing_setup.bats delete mode 100644 vendor/bats/test/fixtures/bats/failing_teardown.bats delete mode 100644 vendor/bats/test/fixtures/bats/intact.bats delete mode 100644 vendor/bats/test/fixtures/bats/invalid_tap.bats delete mode 100644 vendor/bats/test/fixtures/bats/load.bats delete mode 100644 vendor/bats/test/fixtures/bats/loop_keep_IFS.bats delete mode 100644 vendor/bats/test/fixtures/bats/output.bats delete mode 100644 vendor/bats/test/fixtures/bats/passing.bats delete mode 100644 vendor/bats/test/fixtures/bats/passing_and_failing.bats delete mode 100644 vendor/bats/test/fixtures/bats/passing_and_skipping.bats delete mode 100644 vendor/bats/test/fixtures/bats/passing_failing_and_skipping.bats delete mode 100644 vendor/bats/test/fixtures/bats/setup.bats delete mode 100644 vendor/bats/test/fixtures/bats/single_line.bats delete mode 100644 vendor/bats/test/fixtures/bats/skipped.bats delete mode 100644 vendor/bats/test/fixtures/bats/teardown.bats delete mode 100644 vendor/bats/test/fixtures/bats/test_helper.bash delete mode 100644 vendor/bats/test/fixtures/bats/without_trailing_newline.bats delete mode 100644 vendor/bats/test/fixtures/suite/empty/.gitkeep delete mode 100644 vendor/bats/test/fixtures/suite/multiple/a.bats delete mode 100644 vendor/bats/test/fixtures/suite/multiple/b.bats delete mode 100644 vendor/bats/test/fixtures/suite/single/test.bats delete mode 100755 vendor/bats/test/suite.bats delete mode 100644 vendor/bats/test/test_helper.bash diff --git a/run-cr b/run-cr index 9fcc446..1635784 100755 --- a/run-cr +++ b/run-cr @@ -29,6 +29,23 @@ help(){ exit 0 } +install_bats(){ + # Install BATS framework if not installed already + type bats >/dev/null 2>&1 + if [[ "$?" -ne "0" ]]; then + git clone -b v0.4.0 https://github.com/sstephenson/bats.git /tmp/bats + OS_NAME=$(uname -a) + echo $OS_NAME + if [[ $OS_NAME == *"coreos"* ]]; then + cd /tmp/bats && sudo ./install.sh /opt + else + cd /tmp/bats && sudo ./install.sh /usr/local + fi + cd - + rm -rf /tmp/bats + fi +} + if [[ -z $1 ]];then help exit 0 @@ -49,10 +66,11 @@ case $1 in src) docker run --rm -v $PWD:/cr -w /cr $CR_SRC $INPUTS ;; + # TechDebt: Could be a target in Makefile + # CoreOS doesn't come with Make; so staying within it's limits test-bats) - # TechDebt: Could be a target in Makefile - # CoreOS doesn't come with Make; so staying within it's limits - vendor/bats/bin/bats test/bats/ + install_bats + bats test/bats/ ;; * | help) help diff --git a/vendor/bats/.travis.yml b/vendor/bats/.travis.yml deleted file mode 100644 index db06d9d..0000000 --- a/vendor/bats/.travis.yml +++ /dev/null @@ -1,5 +0,0 @@ -language: c -script: bin/bats --tap test -notifications: - email: - on_success: never diff --git a/vendor/bats/LICENSE b/vendor/bats/LICENSE deleted file mode 100644 index bac4eb2..0000000 --- a/vendor/bats/LICENSE +++ /dev/null @@ -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. diff --git a/vendor/bats/README.md b/vendor/bats/README.md deleted file mode 100644 index 00c3105..0000000 --- a/vendor/bats/README.md +++ /dev/null @@ -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 " ] -} -``` - -### `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. diff --git a/vendor/bats/bin/bats b/vendor/bats/bin/bats deleted file mode 120000 index a50a884..0000000 --- a/vendor/bats/bin/bats +++ /dev/null @@ -1 +0,0 @@ -../libexec/bats \ No newline at end of file diff --git a/vendor/bats/install.sh b/vendor/bats/install.sh deleted file mode 100755 index 8bbdd16..0000000 --- a/vendor/bats/install.sh +++ /dev/null @@ -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 " - 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" diff --git a/vendor/bats/libexec/bats b/vendor/bats/libexec/bats deleted file mode 100755 index 71f392f..0000000 --- a/vendor/bats/libexec/bats +++ /dev/null @@ -1,142 +0,0 @@ -#!/usr/bin/env bash -set -e - -version() { - echo "Bats 0.4.0" -} - -usage() { - version - echo "Usage: bats [-c] [-p | -t] [ ...]" -} - -help() { - usage - echo - echo " 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" diff --git a/vendor/bats/libexec/bats-exec-suite b/vendor/bats/libexec/bats-exec-suite deleted file mode 100755 index 29ab255..0000000 --- a/vendor/bats/libexec/bats-exec-suite +++ /dev/null @@ -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" diff --git a/vendor/bats/libexec/bats-exec-test b/vendor/bats/libexec/bats-exec-test deleted file mode 100755 index 8f3bd51..0000000 --- a/vendor/bats/libexec/bats-exec-test +++ /dev/null @@ -1,346 +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 " >&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 oldIFS - [[ ! "$-" =~ e ]] || e=1 - [[ ! "$-" =~ E ]] || E=1 - [[ ! "$-" =~ T ]] || T=1 - set +e - set +E - set +T - output="$("$@" 2>&1)" - status="$?" - oldIFS=$IFS - IFS=$'\n' lines=($output) - [ -z "$e" ] || set -e - [ -z "$E" ] || set -E - [ -z "$T" ] || set -T - IFS=$oldIFS -} - -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 diff --git a/vendor/bats/libexec/bats-format-tap-stream b/vendor/bats/libexec/bats-format-tap-stream deleted file mode 100755 index 614768f..0000000 --- a/vendor/bats/libexec/bats-format-tap-stream +++ /dev/null @@ -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 diff --git a/vendor/bats/libexec/bats-preprocess b/vendor/bats/libexec/bats-preprocess deleted file mode 100755 index 04297ed..0000000 --- a/vendor/bats/libexec/bats-preprocess +++ /dev/null @@ -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 [ ...] - - 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. - - - diff --git a/vendor/bats/man/bats.7 b/vendor/bats/man/bats.7 deleted file mode 100644 index d0836e5..0000000 --- a/vendor/bats/man/bats.7 +++ /dev/null @@ -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 " ] -} -. -.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) diff --git a/vendor/bats/man/bats.7.ronn b/vendor/bats/man/bats.7.ronn deleted file mode 100644 index 7f6dd18..0000000 --- a/vendor/bats/man/bats.7.ronn +++ /dev/null @@ -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 " ] - } - - -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) diff --git a/vendor/bats/package.json b/vendor/bats/package.json deleted file mode 100644 index 6bcff0c..0000000 --- a/vendor/bats/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "bats", - "version": "v0.4.0", - "description": "Bash Automated Testing System", - "install": "./install.sh ${PREFIX:-/usr/local}", - "scripts": [ "libexec/bats", "libexec/bats-exec-suite", "libexec/bats-exec-test", "libexec/bats-format-tap-stream", "libexec/bats-preprocess", "bin/bats" ] -} - diff --git a/vendor/bats/test/bats.bats b/vendor/bats/test/bats.bats deleted file mode 100755 index f1aff29..0000000 --- a/vendor/bats/test/bats.bats +++ /dev/null @@ -1,264 +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' ] -} - -@test "testing IFS not modified by run" { - run bats "$FIXTURE_ROOT/loop_keep_IFS.bats" - [ $status -eq 0 ] - [ "${lines[1]}" = "ok 1 loop_func" ] -} diff --git a/vendor/bats/test/fixtures/bats/dos_line.bats b/vendor/bats/test/fixtures/bats/dos_line.bats deleted file mode 100644 index d04c17f..0000000 --- a/vendor/bats/test/fixtures/bats/dos_line.bats +++ /dev/null @@ -1,3 +0,0 @@ -@test "foo" { - echo "foo" -} diff --git a/vendor/bats/test/fixtures/bats/empty.bats b/vendor/bats/test/fixtures/bats/empty.bats deleted file mode 100644 index e69de29..0000000 diff --git a/vendor/bats/test/fixtures/bats/environment.bats b/vendor/bats/test/fixtures/bats/environment.bats deleted file mode 100644 index 8d3b984..0000000 --- a/vendor/bats/test/fixtures/bats/environment.bats +++ /dev/null @@ -1,8 +0,0 @@ -@test "setting a variable" { - variable=1 - [ $variable -eq 1 ] -} - -@test "variables do not persist across tests" { - [ -z "$variable" ] -} diff --git a/vendor/bats/test/fixtures/bats/failing.bats b/vendor/bats/test/fixtures/bats/failing.bats deleted file mode 100644 index 13be78c..0000000 --- a/vendor/bats/test/fixtures/bats/failing.bats +++ /dev/null @@ -1,5 +0,0 @@ -@test "a failing test" { - true - true - eval "( exit ${STATUS:-1} )" -} diff --git a/vendor/bats/test/fixtures/bats/failing_and_passing.bats b/vendor/bats/test/fixtures/bats/failing_and_passing.bats deleted file mode 100644 index 5513a9b..0000000 --- a/vendor/bats/test/fixtures/bats/failing_and_passing.bats +++ /dev/null @@ -1,7 +0,0 @@ -@test "a failing test" { - false -} - -@test "a passing test" { - true -} diff --git a/vendor/bats/test/fixtures/bats/failing_helper.bats b/vendor/bats/test/fixtures/bats/failing_helper.bats deleted file mode 100644 index fb5726f..0000000 --- a/vendor/bats/test/fixtures/bats/failing_helper.bats +++ /dev/null @@ -1,6 +0,0 @@ -load "test_helper" - -@test "failing helper function" { - true - failing_helper -} diff --git a/vendor/bats/test/fixtures/bats/failing_setup.bats b/vendor/bats/test/fixtures/bats/failing_setup.bats deleted file mode 100644 index 9a35587..0000000 --- a/vendor/bats/test/fixtures/bats/failing_setup.bats +++ /dev/null @@ -1,7 +0,0 @@ -setup() { - false -} - -@test "truth" { - true -} diff --git a/vendor/bats/test/fixtures/bats/failing_teardown.bats b/vendor/bats/test/fixtures/bats/failing_teardown.bats deleted file mode 100644 index 28eebf6..0000000 --- a/vendor/bats/test/fixtures/bats/failing_teardown.bats +++ /dev/null @@ -1,7 +0,0 @@ -teardown() { - eval "( exit ${STATUS:-1} )" -} - -@test "truth" { - [ "$PASS" = "1" ] -} diff --git a/vendor/bats/test/fixtures/bats/intact.bats b/vendor/bats/test/fixtures/bats/intact.bats deleted file mode 100644 index c25c28c..0000000 --- a/vendor/bats/test/fixtures/bats/intact.bats +++ /dev/null @@ -1,6 +0,0 @@ -@test "dash-e on beginning of line" { - run cat - <&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 -} diff --git a/vendor/bats/test/fixtures/bats/passing.bats b/vendor/bats/test/fixtures/bats/passing.bats deleted file mode 100644 index e8182ce..0000000 --- a/vendor/bats/test/fixtures/bats/passing.bats +++ /dev/null @@ -1,3 +0,0 @@ -@test "a passing test" { - true -} diff --git a/vendor/bats/test/fixtures/bats/passing_and_failing.bats b/vendor/bats/test/fixtures/bats/passing_and_failing.bats deleted file mode 100644 index 7b7d8ee..0000000 --- a/vendor/bats/test/fixtures/bats/passing_and_failing.bats +++ /dev/null @@ -1,7 +0,0 @@ -@test "a passing test" { - true -} - -@test "a failing test" { - false -} diff --git a/vendor/bats/test/fixtures/bats/passing_and_skipping.bats b/vendor/bats/test/fixtures/bats/passing_and_skipping.bats deleted file mode 100644 index 88d74be..0000000 --- a/vendor/bats/test/fixtures/bats/passing_and_skipping.bats +++ /dev/null @@ -1,7 +0,0 @@ -@test "a passing test" { - true -} - -@test "a skipping test" { - skip -} diff --git a/vendor/bats/test/fixtures/bats/passing_failing_and_skipping.bats b/vendor/bats/test/fixtures/bats/passing_failing_and_skipping.bats deleted file mode 100644 index 3c9f17f..0000000 --- a/vendor/bats/test/fixtures/bats/passing_failing_and_skipping.bats +++ /dev/null @@ -1,11 +0,0 @@ -@test "a passing test" { - true -} - -@test "a skipping test" { - skip -} - -@test "a failing test" { - false -} diff --git a/vendor/bats/test/fixtures/bats/setup.bats b/vendor/bats/test/fixtures/bats/setup.bats deleted file mode 100644 index 3cc52cc..0000000 --- a/vendor/bats/test/fixtures/bats/setup.bats +++ /dev/null @@ -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" ] -} diff --git a/vendor/bats/test/fixtures/bats/single_line.bats b/vendor/bats/test/fixtures/bats/single_line.bats deleted file mode 100644 index fc342d9..0000000 --- a/vendor/bats/test/fixtures/bats/single_line.bats +++ /dev/null @@ -1,9 +0,0 @@ -@test "empty" { } - -@test "passing" { true; } - -@test "input redirection" { diff - <( echo hello ); } <> "$LOG" -} - -@test "one" { - true -} - -@test "two" { - false -} - -@test "three" { - true -} diff --git a/vendor/bats/test/fixtures/bats/test_helper.bash b/vendor/bats/test/fixtures/bats/test_helper.bash deleted file mode 100644 index 530d034..0000000 --- a/vendor/bats/test/fixtures/bats/test_helper.bash +++ /dev/null @@ -1,7 +0,0 @@ -help_me() { - true -} - -failing_helper() { - false -} diff --git a/vendor/bats/test/fixtures/bats/without_trailing_newline.bats b/vendor/bats/test/fixtures/bats/without_trailing_newline.bats deleted file mode 100644 index e3ace8b..0000000 --- a/vendor/bats/test/fixtures/bats/without_trailing_newline.bats +++ /dev/null @@ -1,3 +0,0 @@ -@test "truth" { - true -} \ No newline at end of file diff --git a/vendor/bats/test/fixtures/suite/empty/.gitkeep b/vendor/bats/test/fixtures/suite/empty/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/vendor/bats/test/fixtures/suite/multiple/a.bats b/vendor/bats/test/fixtures/suite/multiple/a.bats deleted file mode 100644 index fbc1f38..0000000 --- a/vendor/bats/test/fixtures/suite/multiple/a.bats +++ /dev/null @@ -1,3 +0,0 @@ -@test "truth" { - true -} diff --git a/vendor/bats/test/fixtures/suite/multiple/b.bats b/vendor/bats/test/fixtures/suite/multiple/b.bats deleted file mode 100644 index bb965a4..0000000 --- a/vendor/bats/test/fixtures/suite/multiple/b.bats +++ /dev/null @@ -1,7 +0,0 @@ -@test "more truth" { - true -} - -@test "quasi-truth" { - [ -z "$FLUNK" ] -} diff --git a/vendor/bats/test/fixtures/suite/single/test.bats b/vendor/bats/test/fixtures/suite/single/test.bats deleted file mode 100644 index e8182ce..0000000 --- a/vendor/bats/test/fixtures/suite/single/test.bats +++ /dev/null @@ -1,3 +0,0 @@ -@test "a passing test" { - true -} diff --git a/vendor/bats/test/suite.bats b/vendor/bats/test/suite.bats deleted file mode 100755 index 5371686..0000000 --- a/vendor/bats/test/suite.bats +++ /dev/null @@ -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" ] -} diff --git a/vendor/bats/test/test_helper.bash b/vendor/bats/test/test_helper.bash deleted file mode 100644 index 84eee8c..0000000 --- a/vendor/bats/test/test_helper.bash +++ /dev/null @@ -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"/* -} From 73a24d0d707d56ac53e308f096aad9e94d006597 Mon Sep 17 00:00:00 2001 From: Mazedur Rahman Date: Sun, 12 Mar 2017 07:18:57 +0000 Subject: [PATCH 5/8] Added assertion for build success using demo project --- docs/docker/README.md | 1 - test/bats/run-cr.bats | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/docker/README.md b/docs/docker/README.md index 34a4bd1..f9f4699 100644 --- a/docs/docker/README.md +++ b/docs/docker/README.md @@ -1,5 +1,4 @@ ## TODO for Dockerization -* Add more assertions for tests * Add maintainer * Lean-ify image (consider tiny base e.g. busybox, alpine, etc.) * Reorganize directory structure (cleaner project root preferred) diff --git a/test/bats/run-cr.bats b/test/bats/run-cr.bats index b662d40..d8f329f 100644 --- a/test/bats/run-cr.bats +++ b/test/bats/run-cr.bats @@ -2,6 +2,9 @@ load test_helper +CR_SRC=yamaszone/clusterrunner:src +CR_DEMO_REPO=https://github.com/boxengservices/ClusterRunnerDemo.git + @test "'run-cr' script displays help." { run ./run-cr assert_contains "$output" "Usage:" @@ -16,3 +19,14 @@ load test_helper run ./run-cr src -h assert_contains "$output" "usage: main.py" } + +#slow-test +@test "CR-SRC: Image built from source can build job properly." { + git clone $CR_DEMO_REPO /tmp/cr-demo + cd /tmp/cr-demo + run docker run --rm -v $PWD:/sut -w /sut $CR_SRC build --job-name Simple + assert_contains "$output" "NO_FAILURES" + cd - + # Needs super user privilege as build artefacts are written as root + sudo rm -rf /tmp/cr-demo +} From 4b4f68e14aef1898238af68191b5020a09aca927 Mon Sep 17 00:00:00 2001 From: Mazedur Rahman Date: Tue, 14 Mar 2017 06:04:56 +0000 Subject: [PATCH 6/8] Cleaned up redundant mounts --- run-cr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run-cr b/run-cr index 1635784..5eee064 100755 --- a/run-cr +++ b/run-cr @@ -55,7 +55,7 @@ INPUTS=`echo "${@:2}"` case $1 in bin) - docker run --rm -v $PWD:/cr -w /cr $CR_BIN $INPUTS + docker run --rm $CR_BIN $INPUTS ;; build) build_images @@ -64,7 +64,7 @@ case $1 in push_images ;; src) - docker run --rm -v $PWD:/cr -w /cr $CR_SRC $INPUTS + docker run --rm $CR_SRC $INPUTS ;; # TechDebt: Could be a target in Makefile # CoreOS doesn't come with Make; so staying within it's limits From ff6e0ee72c64cb3baf3b56cb24f02ab61a453e92 Mon Sep 17 00:00:00 2001 From: Mazedur Rahman Date: Mon, 13 Mar 2017 23:06:17 -0700 Subject: [PATCH 7/8] Updated notes for Dockerization TODO list --- docs/docker/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/docker/README.md b/docs/docker/README.md index f9f4699..dc0cd9b 100644 --- a/docs/docker/README.md +++ b/docs/docker/README.md @@ -1,7 +1,15 @@ ## TODO for Dockerization * Add maintainer + - Maintainer for CR Dockerfile needs to be added after pull request is merged. Ideally the maintainer should be someone from official team with appropriate Docker Hub permission to tag image as `box/clusterrunner:latest`. I can volunteer if needed but will require collaborator permission for Docker Hub. * Lean-ify image (consider tiny base e.g. busybox, alpine, etc.) + - Currently `Dockerfile.src` uses `python:3.4-slim` as the base. I attempted `python:alpine` as the base but it didn't feel like worth the [trouble](https://github.com/docker/docker/issues/27940). My docker version is `1.12.6` but the problem might have been fixed in `1.13.0+`. I will revisit this in the future. * Reorganize directory structure (cleaner project root preferred) + - I was considering potential restructure of CR project root directory similar to [this](https://gist.github.com/yamaszone/6a4304069652a4a01ecdacdd4e7c7df1) so that: + - Only relevant project artefacts can be easily added into Docker image excluding non-PROD dependencies like tests, docs, Dockerfiles, docker-compose.yaml, and so on... + - Non-PROD tools/libs installation inside Docker container is excluded by splitting `requirements.txt` into `requirements-prod.txt` and `requirements-non-prod.txt` to deal with security/maintenance aspects of production dependencies as a priority basis + - Readability can be improved + - ... :) + - I will hold off on this as it will potentially require breaking changes. Also allowing more time to rethink this! ## User Guide #### Usage Scenarios From 7199d90261f7a70066e21cd9bff4dab09900b58a Mon Sep 17 00:00:00 2001 From: Mazedur Rahman Date: Tue, 14 Mar 2017 00:34:07 -0700 Subject: [PATCH 8/8] Fixed typo in docs --- docs/docker/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/docker/README.md b/docs/docker/README.md index dc0cd9b..84f9379 100644 --- a/docs/docker/README.md +++ b/docs/docker/README.md @@ -1,12 +1,12 @@ ## TODO for Dockerization -* Add maintainer - - Maintainer for CR Dockerfile needs to be added after pull request is merged. Ideally the maintainer should be someone from official team with appropriate Docker Hub permission to tag image as `box/clusterrunner:latest`. I can volunteer if needed but will require collaborator permission for Docker Hub. -* Lean-ify image (consider tiny base e.g. busybox, alpine, etc.) +* Add maintainer(s) + - Maintainer for CR Dockerfile needs to be added after pull request is merged. Ideally the maintainer should be someone from official team with appropriate Docker Hub permission to tag image as `box/clusterrunner:latest`. I can volunteer if needed but that will require collaborator permission for Docker Hub. +* Lean Docker image (consider tiny base e.g. busybox, alpine, etc.) - Currently `Dockerfile.src` uses `python:3.4-slim` as the base. I attempted `python:alpine` as the base but it didn't feel like worth the [trouble](https://github.com/docker/docker/issues/27940). My docker version is `1.12.6` but the problem might have been fixed in `1.13.0+`. I will revisit this in the future. * Reorganize directory structure (cleaner project root preferred) - I was considering potential restructure of CR project root directory similar to [this](https://gist.github.com/yamaszone/6a4304069652a4a01ecdacdd4e7c7df1) so that: - Only relevant project artefacts can be easily added into Docker image excluding non-PROD dependencies like tests, docs, Dockerfiles, docker-compose.yaml, and so on... - - Non-PROD tools/libs installation inside Docker container is excluded by splitting `requirements.txt` into `requirements-prod.txt` and `requirements-non-prod.txt` to deal with security/maintenance aspects of production dependencies as a priority basis + - Non-PROD tools/libs installation inside Docker container is excluded by splitting `requirements.txt` into `requirements-prod.txt` and `requirements-non-prod.txt` to deal with security/maintenance aspects of production dependencies as a priority basis - Readability can be improved - ... :) - I will hold off on this as it will potentially require breaking changes. Also allowing more time to rethink this!