├── .tool-versions ├── vendor └── bats │ ├── bin │ └── bats │ ├── .gitattributes │ ├── VERSION.txt │ ├── .travis.yml │ ├── man │ ├── Makefile │ ├── README.md │ ├── bats.1.ronn │ ├── bats.1 │ ├── bats.7.ronn │ └── bats.7 │ ├── package.json │ ├── install.sh │ ├── LICENSE │ ├── libexec │ ├── bats-exec-suite │ ├── bats-preprocess │ ├── bats │ ├── bats-format-tap-stream │ └── bats-exec-test │ └── README.md ├── config ├── cucumber.yml └── features │ ├── plugin_list_command.feature │ ├── support │ └── env.rb │ ├── plugin_install_command.feature │ └── test_command.feature ├── .markdownlint.yaml ├── .markdownlint-cli2.jsonc ├── .github ├── dependabot.yml └── workflows │ ├── lint.yaml │ └── publish.yaml ├── .rubocop.yml ├── renovate.json ├── .gitignore ├── features ├── plugin_list_command.feature ├── support │ └── env.rb ├── plugin_install_command.feature └── test_command.feature ├── Gemfile ├── LICENSE ├── Guardfile ├── lib └── busser │ ├── bats │ └── version.rb │ └── runner_plugin │ └── bats.rb ├── busser-bats.gemspec ├── Rakefile ├── CHANGELOG.md └── README.md /.tool-versions: -------------------------------------------------------------------------------- 1 | ruby 3.3.3 2 | -------------------------------------------------------------------------------- /vendor/bats/bin/bats: -------------------------------------------------------------------------------- 1 | ../libexec/bats -------------------------------------------------------------------------------- /vendor/bats/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.sh eol=lf 3 | libexec/* eol=lf 4 | -------------------------------------------------------------------------------- /vendor/bats/VERSION.txt: -------------------------------------------------------------------------------- 1 | https://github.com/sstephenson/bats/archive/v0.4.0.tar.gz 2 | -------------------------------------------------------------------------------- /config/cucumber.yml: -------------------------------------------------------------------------------- 1 | default: --publish-quiet --format pretty --format html --out reports.html 2 | -------------------------------------------------------------------------------- /vendor/bats/.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | script: bin/bats --tap test 3 | notifications: 4 | email: 5 | on_success: never 6 | -------------------------------------------------------------------------------- /.markdownlint.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | default: true 3 | MD013: false 4 | MD024: false 5 | MD026: false 6 | MD036: false 7 | MD012: false 8 | MD029: false 9 | MD004: false 10 | -------------------------------------------------------------------------------- /.markdownlint-cli2.jsonc: -------------------------------------------------------------------------------- 1 | { 2 | "fix": false, 3 | "globs": ["**/*.md", "!vendor"], 4 | // "ignores": ["ignore*.md"], 5 | "noProgress": false, 6 | "showFound": true 7 | } 8 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | --- 2 | version: 2 3 | updates: 4 | - package-ecosystem: bundler 5 | directory: "/" 6 | schedule: 7 | interval: daily 8 | open-pull-requests-limit: 10 9 | -------------------------------------------------------------------------------- /vendor/bats/man/Makefile: -------------------------------------------------------------------------------- 1 | RONN := ronn 2 | PAGES := bats.1 bats.7 3 | 4 | all: $(PAGES) 5 | 6 | bats.1: bats.1.ronn 7 | $(RONN) -r $< 8 | 9 | bats.7: bats.7.ronn 10 | $(RONN) -r $< 11 | -------------------------------------------------------------------------------- /.github/workflows/lint.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: "Test" 3 | 4 | "on": 5 | pull_request: 6 | 7 | jobs: 8 | lint-unit: 9 | uses: test-kitchen/.github/.github/workflows/lint-unit.yml@v0.1.2 10 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | --- 2 | require: 3 | - chefstyle 4 | 5 | AllCops: 6 | TargetRubyVersion: 2.7 7 | Include: 8 | - "**/*.rb" 9 | Exclude: 10 | - "vendor/**/*" 11 | - "spec/**/*" 12 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": [ 4 | "config:recommended", 5 | ":disableDependencyDashboard", 6 | "schedule:automergeEarlyMondays" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | .bundle 4 | .config 5 | .yardoc 6 | Gemfile.lock 7 | InstalledFiles 8 | _yardoc 9 | coverage 10 | doc/ 11 | lib/bundler/man 12 | pkg 13 | rdoc 14 | spec/reports 15 | test/tmp 16 | test/version_tmp 17 | tmp 18 | reports.html 19 | -------------------------------------------------------------------------------- /vendor/bats/man/README.md: -------------------------------------------------------------------------------- 1 | Bats man pages are generated with [Ronn](http://rtomayko.github.io/ronn/). 2 | 3 | After making changes to `bats.1.ronn` or `bats.7.ronn`, run `make` in 4 | this directory to generate `bats.1` and `bats.7`. **Do not edit the 5 | `bats.1` or `bats.7` files directly.** 6 | -------------------------------------------------------------------------------- /features/plugin_list_command.feature: -------------------------------------------------------------------------------- 1 | Feature: Plugin list command 2 | In order to use this plugin 3 | As a user of Busser 4 | I want to see this plugin in the 'busser plugin list' command 5 | 6 | Scenario: Plugin appears in plugin list command 7 | When I successfully run `busser plugin list` 8 | Then the output should match /^bats\b/ 9 | -------------------------------------------------------------------------------- /config/features/plugin_list_command.feature: -------------------------------------------------------------------------------- 1 | Feature: Plugin list command 2 | In order to use this plugin 3 | As a user of Busser 4 | I want to see this plugin in the 'busser plugin list' command 5 | 6 | Scenario: Plugin appears in plugin list command 7 | When I successfully run `busser plugin list` 8 | Then the output should match /^bats\b/ 9 | -------------------------------------------------------------------------------- /vendor/bats/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bats", 3 | "version": "0.3.1", 4 | "description": "Bash Automated Testing System", 5 | "global": "true", 6 | "install": "./install.sh /usr/local", 7 | "scripts": [ "libexec/bats", "libexec/bats-exec-suite", "libexec/bats-exec-test", "libexec/bats-format-tap-stream", "libexec/bats-preprocess", "bin/bats" ] 8 | } 9 | 10 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | gemspec 4 | 5 | group :guard do 6 | gem "guard-cucumber" 7 | gem "guard-cane" 8 | gem "guard-rubocop" 9 | end 10 | 11 | group :test do 12 | gem "rake", ">= 11.0" 13 | gem "rspec", "~> 3.2" 14 | gem "aruba" 15 | end 16 | 17 | group :development do 18 | gem "countloc" 19 | gem "simplecov" 20 | end 21 | 22 | group :chefstyle do 23 | gem "chefstyle", "2.2.3" 24 | end 25 | -------------------------------------------------------------------------------- /features/support/env.rb: -------------------------------------------------------------------------------- 1 | require "aruba/cucumber" 2 | require "busser/cucumber" 3 | 4 | if ENV["COVERAGE"] 5 | require "simplecov" 6 | SimpleCov.command_name "features" 7 | end 8 | 9 | Before do 10 | @aruba_timeout_seconds = 20 11 | end 12 | 13 | After do |s| 14 | # Tell Cucumber to quit after this scenario is done - if it failed. 15 | # This is useful to inspect the 'tmp/aruba' directory before any other 16 | # steps are executed and clear it out. 17 | Cucumber.wants_to_quit = true if s.failed? 18 | end 19 | -------------------------------------------------------------------------------- /config/features/support/env.rb: -------------------------------------------------------------------------------- 1 | require "aruba/cucumber" 2 | require "busser/cucumber" 3 | 4 | if ENV["COVERAGE"] 5 | require "simplecov" 6 | SimpleCov.command_name "features" 7 | end 8 | 9 | Before do 10 | @aruba_timeout_seconds = 20 11 | end 12 | 13 | After do |s| 14 | # Tell Cucumber to quit after this scenario is done - if it failed. 15 | # This is useful to inspect the 'tmp/aruba' directory before any other 16 | # steps are executed and clear it out. 17 | Cucumber.wants_to_quit = true if s.failed? 18 | end 19 | -------------------------------------------------------------------------------- /features/plugin_install_command.feature: -------------------------------------------------------------------------------- 1 | Feature: Plugin install command 2 | In order to use this plugin 3 | As a user of Busser 4 | I want to run the postinstall for this plugin 5 | 6 | Background: 7 | Given a test BUSSER_ROOT directory named "busser-bats-install" 8 | 9 | Scenario: Running the postinstall generator 10 | When I run `busser plugin install busser-bats --force-postinstall` 11 | # Then the vendor directory named "bats" should exist 12 | # Then the vendor file "bats/bin/bats" should contain "BATS_PREFIX=" 13 | And the output should contain "Installed Bats" 14 | And the exit status should be 0 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Author:: Fletcher Nichol () 2 | 3 | Copyright (C) 2013, Fletcher Nichol 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | -------------------------------------------------------------------------------- /Guardfile: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | ignore %r{^\.gem/} 3 | 4 | def rubocop_opts 5 | { :all_on_start => false, :keep_failed => false, :cli => "-r finstyle -D" } 6 | end 7 | 8 | group :red_green_refactor, :halt_on_fail => true do 9 | guard :cucumber do 10 | watch(%r{^features/.+\.feature$}) 11 | watch(%r{^features/support/.+$}) { "features" } 12 | watch(%r{^features/step_definitions/(.+)_steps\.rb$}) do |m| 13 | Dir[File.join("**/#{m[1]}.feature")][0] || "features" 14 | end 15 | end 16 | 17 | guard :rubocop, rubocop_opts do 18 | watch(%r{.+\.rb$}) 19 | watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) } 20 | end 21 | 22 | guard :cane do 23 | watch(%r{.*\.rb}) 24 | watch(".cane") 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /lib/busser/bats/version.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Fletcher Nichol () 3 | # 4 | # Copyright (C) 2013, Fletcher Nichol 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | module Busser 19 | module Bats 20 | VERSION = "0.5.0".freeze 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /busser-bats.gemspec: -------------------------------------------------------------------------------- 1 | lib = File.expand_path("lib", __dir__) 2 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 3 | require "busser/bats/version" 4 | require "English" 5 | 6 | Gem::Specification.new do |gem| 7 | gem.name = "busser-bats" 8 | gem.version = Busser::Bats::VERSION 9 | gem.authors = ["Fletcher Nichol"] 10 | gem.email = ["fnichol@nichol.ca"] 11 | gem.description = "A Busser runner plugin for Bats" 12 | gem.summary = gem.description 13 | gem.homepage = "https://github.com/test-kitchen/busser-bats" 14 | gem.license = "Apache 2.0" 15 | 16 | gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR) 17 | gem.executables = [] 18 | gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) 19 | gem.require_paths = ["lib"] 20 | 21 | gem.add_dependency "busser" 22 | end 23 | -------------------------------------------------------------------------------- /vendor/bats/install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | resolve_link() { 5 | $(type -p greadlink readlink | head -1) "$1" 6 | } 7 | 8 | abs_dirname() { 9 | local cwd="$(pwd)" 10 | local path="$1" 11 | 12 | while [ -n "$path" ]; do 13 | cd "${path%/*}" 14 | local name="${path##*/}" 15 | path="$(resolve_link "$name" || true)" 16 | done 17 | 18 | pwd 19 | cd "$cwd" 20 | } 21 | 22 | PREFIX="$1" 23 | if [ -z "$1" ]; then 24 | { echo "usage: $0 " 25 | echo " e.g. $0 /usr/local" 26 | } >&2 27 | exit 1 28 | fi 29 | 30 | BATS_ROOT="$(abs_dirname "$0")" 31 | mkdir -p "$PREFIX"/{bin,libexec,share/man/man{1,7}} 32 | cp -R "$BATS_ROOT"/bin/* "$PREFIX"/bin 33 | cp -R "$BATS_ROOT"/libexec/* "$PREFIX"/libexec 34 | cp "$BATS_ROOT"/man/bats.1 "$PREFIX"/share/man/man1 35 | cp "$BATS_ROOT"/man/bats.7 "$PREFIX"/share/man/man7 36 | 37 | echo "Installed Bats to $PREFIX/bin/bats" 38 | -------------------------------------------------------------------------------- /config/features/plugin_install_command.feature: -------------------------------------------------------------------------------- 1 | # Commenting out this test for now as it is not working on MacOS due to permissions (stop writing to /opt!) 2 | # undefined method `check_directory_presence' for # (NoMethodError) 3 | # features/plugin_install_command.feature:11:in `the vendor directory named "bats" should exist' 4 | # Feature: Plugin install command 5 | # In order to use this plugin 6 | # As a user of Busser 7 | # I want to run the postinstall for this plugin 8 | 9 | # Background: 10 | # Given a test BUSSER_ROOT directory named "busser-bats-install" 11 | 12 | # Scenario: Running the postinstall generator 13 | # When I run `busser plugin install busser-bats --force-postinstall` 14 | # Then the vendor directory named "bats" should exist 15 | # And the vendor file "bats/bin/bats" should contain "BATS_PREFIX=" 16 | # And the output should contain "Installed Bats" 17 | # And the exit status should be 0 18 | -------------------------------------------------------------------------------- /vendor/bats/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Sam Stephenson 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /.github/workflows/publish.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: release-please 3 | 4 | "on": 5 | push: 6 | branches: [main] 7 | 8 | jobs: 9 | release-please: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: google-github-actions/release-please-action@v4 13 | id: release 14 | with: 15 | release-type: ruby 16 | package-name: busser-bats 17 | version-file: lib/busser/bats/version.rb 18 | token: ${{ secrets.PORTER_GITHUB_TOKEN }} 19 | 20 | - name: Checkout 21 | uses: actions/checkout@v4 22 | if: ${{ steps.release.outputs.release_created }} 23 | 24 | - name: Build and publish to GitHub Package 25 | uses: actionshub/publish-gem-to-github@main 26 | if: ${{ steps.release.outputs.release_created }} 27 | with: 28 | token: ${{ secrets.GITHUB_TOKEN }} 29 | owner: ${{ secrets.OWNER }} 30 | 31 | - name: Build and publish to RubyGems 32 | uses: actionshub/publish-gem-to-rubygems@main 33 | if: ${{ steps.release.outputs.release_created }} 34 | with: 35 | token: ${{ secrets.RUBYGEMS_API_KEY }} 36 | -------------------------------------------------------------------------------- /vendor/bats/libexec/bats-exec-suite: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | count_only_flag="" 5 | if [ "$1" = "-c" ]; then 6 | count_only_flag=1 7 | shift 8 | fi 9 | 10 | extended_syntax_flag="" 11 | if [ "$1" = "-x" ]; then 12 | extended_syntax_flag="-x" 13 | shift 14 | fi 15 | 16 | trap "kill 0; exit 1" int 17 | 18 | count=0 19 | for filename in "$@"; do 20 | let count+="$(bats-exec-test -c "$filename")" 21 | done 22 | 23 | if [ -n "$count_only_flag" ]; then 24 | echo "$count" 25 | exit 26 | fi 27 | 28 | echo "1..$count" 29 | status=0 30 | offset=0 31 | for filename in "$@"; do 32 | index=0 33 | { 34 | IFS= read -r # 1..n 35 | while IFS= read -r line; do 36 | case "$line" in 37 | "begin "* ) 38 | let index+=1 39 | echo "${line/ $index / $(($offset + $index)) }" 40 | ;; 41 | "ok "* | "not ok "* ) 42 | [ -n "$extended_syntax_flag" ] || let index+=1 43 | echo "${line/ $index / $(($offset + $index)) }" 44 | [ "${line:0:6}" != "not ok" ] || status=1 45 | ;; 46 | * ) 47 | echo "$line" 48 | ;; 49 | esac 50 | done 51 | } < <( bats-exec-test $extended_syntax_flag "$filename" ) 52 | offset=$(($offset + $index)) 53 | done 54 | 55 | exit "$status" 56 | -------------------------------------------------------------------------------- /lib/busser/runner_plugin/bats.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Fletcher Nichol () 3 | # 4 | # Copyright (C) 2013, Fletcher Nichol 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | require "pathname" unless defined?(Pathname) 19 | 20 | require "busser/runner_plugin" 21 | 22 | # A Busser runner plugin for Bats. 23 | # 24 | # @author Fletcher Nichol 25 | # 26 | class Busser::RunnerPlugin::Bats < Busser::RunnerPlugin::Base 27 | 28 | postinstall do 29 | inside(Pathname.new(__FILE__).dirname.join("../../../vendor/bats")) do 30 | FileUtils.ln_sf("../libexec/bats", "bin/bats") 31 | run!(%{./install.sh #{vendor_path("bats")}}) 32 | end 33 | end 34 | 35 | def test 36 | run!("#{vendor_path("bats").join("bin/bats")} #{suite_path("bats")}") 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /vendor/bats/libexec/bats-preprocess: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | encode_name() { 5 | local name="$1" 6 | local result="test_" 7 | 8 | if [[ ! "$name" =~ [^[:alnum:]\ _-] ]]; then 9 | name="${name//_/-5f}" 10 | name="${name//-/-2d}" 11 | name="${name// /_}" 12 | result+="$name" 13 | else 14 | local length="${#name}" 15 | local char i 16 | 17 | for ((i=0; i File.dirname(tarball) do |t| 17 | src = open(url).binmode 18 | dst = open(t.name, "wb") 19 | IO.copy_stream(src, dst) 20 | ensure 21 | src.close 22 | dst.close 23 | end 24 | 25 | file "#{vendor}/VERSION.txt" => [vendor, tarball] do |t| 26 | abs_tarball = File.expand_path(tarball) 27 | Dir.chdir(vendor) { sh "tar xzf #{abs_tarball} --strip-components=1" } 28 | rm_rf "#{vendor}/test" 29 | IO.write(t.name, url + "\n") 30 | end 31 | 32 | desc "Clean up a vendored bats in preparation for a new vendored version" 33 | task :clean do 34 | rm_rf [vendor, tarball] 35 | end 36 | end 37 | 38 | require "cucumber/rake/task" 39 | Cucumber::Rake::Task.new(:features) do |t| 40 | t.cucumber_opts = ["features", "-x", "--format progress"] 41 | end 42 | 43 | desc "Run all test suites" 44 | task test: [:features] 45 | 46 | desc "Display LOC stats" 47 | task :stats do 48 | puts "\n## Production Code Stats" 49 | sh "countloc -r lib" 50 | puts "\n## Test Code Stats" 51 | sh "countloc -r features" 52 | end 53 | 54 | task default: %i{test quality} 55 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # busser-bats Changelog 2 | 3 | ## [0.5.0](https://github.com/test-kitchen/busser-bats/compare/v0.4.0...v0.5.0) (2023-11-30) 4 | 5 | 6 | ### Features 7 | 8 | * Bump Ruby version to 3.1 ([#30](https://github.com/test-kitchen/busser-bats/issues/30)) ([948f626](https://github.com/test-kitchen/busser-bats/commit/948f6265ca4a5aa187bf7e76f93dd275b1568b0d)) 9 | * Remove cane ([#32](https://github.com/test-kitchen/busser-bats/issues/32)) ([1bf1bda](https://github.com/test-kitchen/busser-bats/commit/1bf1bda3235445455cec19ee47af3cf3dda667b0)) 10 | 11 | ## [0.4.0](https://github.com/test-kitchen/busser-bats/compare/v0.3.0...v0.4.0) (2023-11-30) 12 | 13 | 14 | ### Features 15 | 16 | * Add publish workflow, lint workflow ([#24](https://github.com/test-kitchen/busser-bats/issues/24)) ([1a8adb3](https://github.com/test-kitchen/busser-bats/commit/1a8adb3f146b10173aec2a779b0a3fb43745be11)) 17 | 18 | ## [0.3.0](https://github.com/test-kitchen/busser-bats/compare/v0.2.0...v0.3.0) (2023-11-30) 19 | 20 | 21 | ### Features 22 | 23 | * Add publish workflow, lint workflow ([#24](https://github.com/test-kitchen/busser-bats/issues/24)) ([1a8adb3](https://github.com/test-kitchen/busser-bats/commit/1a8adb3f146b10173aec2a779b0a3fb43745be11)) 24 | 25 | ## 0.3.0 / 2014-10-14 26 | 27 | ### New features 28 | 29 | * Upgrade vendored bats version to 0.4.0. ([@fnichol][]) 30 | 31 | ### Improvments 32 | 33 | * Update testing dependencies, upgrade to RSpec 3.x, freshen TravisCI build matrix, add style and complexity support. ([@fnichol][]) 34 | * Allow Aruba tests to wait 20 seconds (vs. 10). ([@fnichol][]) 35 | 36 | 37 | ## 0.2.0 / 2014-03-23 38 | 39 | ### Improvements 40 | 41 | * Vendor a copy of Bats locally (v0.3.1) to speed & simplify plugin installations. ([@fnichol][]) 42 | 43 | 44 | ## 0.1.0 / 2013-04-10 45 | 46 | * Initial release 47 | 48 | 49 | [@fnichol]: https://github.com/fnichol 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Busser::RunnerPlugin::Bats 2 | 3 | [![Gem Version](https://badge.fury.io/rb/busser-bats.png)](http://badge.fury.io/rb/busser-bats) 4 | [![Build Status](https://travis-ci.org/test-kitchen/busser-bats.png?branch=master)](https://travis-ci.org/test-kitchen/busser-bats) 5 | [![Code Climate](https://codeclimate.com/github/test-kitchen/busser-bats.png)](https://codeclimate.com/github/test-kitchen/busser-bats) 6 | 7 | A Busser runner plugin for [Bats][bats_site] 8 | 9 | ## Status 10 | 11 | This software project is no longer under active development as it has no active maintainers. The software may continue to work for some or all use cases, but issues filed in GitHub will most likely not be triaged. If a new maintainer is interested in working on this project please come chat with us in #test-kitchen on Chef Community Slack. 12 | 13 | ## Installation and Setup 14 | 15 | Until proper reference documentation is complete, the [Writing a Test](http://kitchen.ci/docs/getting-started/writing-test) section of the Test Kitchen's [Getting Started Guide](http://kitchen.ci/docs/getting-started/) gives a working example of creating a bats test. 16 | 17 | ## Usage 18 | 19 | **TODO:** Write documentation explaining the structure/format of testing files. 20 | 21 | ## Development 22 | 23 | * Source hosted at [GitHub][repo] 24 | * Report issues/questions/feature requests on [GitHub Issues][issues] 25 | 26 | Pull requests are very welcome! Make sure your patches are well tested. 27 | Ideally create a topic branch for every separate change you make. For 28 | example: 29 | 30 | 1. Fork the repo 31 | 2. Create your feature branch (`git checkout -b my-new-feature`) 32 | 3. Commit your changes (`git commit -am 'Added some feature'`) 33 | 4. Push to the branch (`git push origin my-new-feature`) 34 | 5. Create new Pull Request 35 | 36 | ## Authors 37 | 38 | Created and maintained by [Fletcher Nichol][author] () 39 | 40 | ## License 41 | 42 | Apache 2.0 (see [LICENSE][license]) 43 | 44 | [Bats][bats_site] is released under an MIT-style license, copyright Sam Stephenson. 45 | 46 | 47 | [author]: https://github.com/fnichol 48 | [issues]: https://github.com/fnichol/busser-bats/issues 49 | [license]: https://github.com/fnichol/busser-bats/blob/master/LICENSE 50 | [repo]: https://github.com/fnichol/busser-bats 51 | 52 | [bats_site]: https://github.com/sstephenson/bats 53 | -------------------------------------------------------------------------------- /vendor/bats/man/bats.1.ronn: -------------------------------------------------------------------------------- 1 | bats(1) -- Bash Automated Testing System 2 | ======================================== 3 | 4 | 5 | SYNOPSIS 6 | -------- 7 | 8 | bats [-c] [-p | -t] [ ...] 9 | 10 | is the path to a Bats test file, or the path to a directory 11 | containing Bats test files. 12 | 13 | 14 | DESCRIPTION 15 | ----------- 16 | 17 | Bats is a TAP-compliant testing framework for Bash. It provides a simple 18 | way to verify that the UNIX programs you write behave as expected. 19 | 20 | A Bats test file is a Bash script with special syntax for defining 21 | test cases. Under the hood, each test case is just a function with a 22 | description. 23 | 24 | Test cases consist of standard shell commands. Bats makes use of 25 | Bash's `errexit` (`set -e`) option when running test cases. If every 26 | command in the test case exits with a `0` status code (success), the 27 | test passes. In this way, each line is an assertion of truth. 28 | 29 | See `bats`(7) for more information on writing Bats tests. 30 | 31 | 32 | RUNNING TESTS 33 | ------------- 34 | 35 | To run your tests, invoke the `bats` interpreter with a path to a test 36 | file. The file's test cases are run sequentially and in isolation. If 37 | all the test cases pass, `bats` exits with a `0` status code. If there 38 | are any failures, `bats` exits with a `1` status code. 39 | 40 | You can invoke the `bats` interpreter with multiple test file arguments, 41 | or with a path to a directory containing multiple `.bats` files. Bats 42 | will run each test file individually and aggregate the results. If any 43 | test case fails, `bats` exits with a `1` status code. 44 | 45 | 46 | OPTIONS 47 | ------- 48 | 49 | * `-c`, `--count`: 50 | Count the number of test cases without running any tests 51 | * `-h`, `--help`: 52 | Display help message 53 | * `-p`, `--pretty`: 54 | Show results in pretty format (default for terminals) 55 | * `-t`, `--tap`: 56 | Show results in TAP format 57 | * `-v`, `--version`: 58 | Display the version number 59 | 60 | 61 | OUTPUT 62 | ------ 63 | 64 | When you run Bats from a terminal, you'll see output as each test is 65 | performed, with a check-mark next to the test's name if it passes or 66 | an "X" if it fails. 67 | 68 | $ bats addition.bats 69 | ✓ addition using bc 70 | ✓ addition using dc 71 | 72 | 2 tests, 0 failures 73 | 74 | If Bats is not connected to a terminal--in other words, if you run it 75 | from a continuous integration system or redirect its output to a 76 | file--the results are displayed in human-readable, machine-parsable 77 | TAP format. You can force TAP output from a terminal by invoking Bats 78 | with the `--tap` option. 79 | 80 | $ bats --tap addition.bats 81 | 1..2 82 | ok 1 addition using bc 83 | ok 2 addition using dc 84 | 85 | 86 | EXIT STATUS 87 | ----------- 88 | 89 | The `bats` interpreter exits with a value of `0` if all test cases pass, 90 | or `1` if one or more test cases fail. 91 | 92 | 93 | SEE ALSO 94 | -------- 95 | 96 | Bats wiki: _https://github.com/sstephenson/bats/wiki/_ 97 | 98 | `bash`(1), `bats`(7) 99 | 100 | 101 | COPYRIGHT 102 | --------- 103 | 104 | (c) 2014 Sam Stephenson 105 | 106 | Bats is released under the terms of an MIT-style license. 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /vendor/bats/libexec/bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | version() { 5 | echo "Bats 0.4.0" 6 | } 7 | 8 | usage() { 9 | version 10 | echo "Usage: bats [-c] [-p | -t] [ ...]" 11 | } 12 | 13 | help() { 14 | usage 15 | echo 16 | echo " is the path to a Bats test file, or the path to a directory" 17 | echo " containing Bats test files." 18 | echo 19 | echo " -c, --count Count the number of test cases without running any tests" 20 | echo " -h, --help Display this help message" 21 | echo " -p, --pretty Show results in pretty format (default for terminals)" 22 | echo " -t, --tap Show results in TAP format" 23 | echo " -v, --version Display the version number" 24 | echo 25 | echo " For more information, see https://github.com/sstephenson/bats" 26 | echo 27 | } 28 | 29 | resolve_link() { 30 | $(type -p greadlink readlink | head -1) "$1" 31 | } 32 | 33 | abs_dirname() { 34 | local cwd="$(pwd)" 35 | local path="$1" 36 | 37 | while [ -n "$path" ]; do 38 | cd "${path%/*}" 39 | local name="${path##*/}" 40 | path="$(resolve_link "$name" || true)" 41 | done 42 | 43 | pwd 44 | cd "$cwd" 45 | } 46 | 47 | expand_path() { 48 | { cd "$(dirname "$1")" 2>/dev/null 49 | local dirname="$PWD" 50 | cd "$OLDPWD" 51 | echo "$dirname/$(basename "$1")" 52 | } || echo "$1" 53 | } 54 | 55 | BATS_LIBEXEC="$(abs_dirname "$0")" 56 | export BATS_PREFIX="$(abs_dirname "$BATS_LIBEXEC")" 57 | export BATS_CWD="$(abs_dirname .)" 58 | export PATH="$BATS_LIBEXEC:$PATH" 59 | 60 | options=() 61 | arguments=() 62 | for arg in "$@"; do 63 | if [ "${arg:0:1}" = "-" ]; then 64 | if [ "${arg:1:1}" = "-" ]; then 65 | options[${#options[*]}]="${arg:2}" 66 | else 67 | index=1 68 | while option="${arg:$index:1}"; do 69 | [ -n "$option" ] || break 70 | options[${#options[*]}]="$option" 71 | let index+=1 72 | done 73 | fi 74 | else 75 | arguments[${#arguments[*]}]="$arg" 76 | fi 77 | done 78 | 79 | unset count_flag pretty 80 | [ -t 0 ] && [ -t 1 ] && pretty="1" 81 | [ -n "$CI" ] && pretty="" 82 | 83 | for option in "${options[@]}"; do 84 | case "$option" in 85 | "h" | "help" ) 86 | help 87 | exit 0 88 | ;; 89 | "v" | "version" ) 90 | version 91 | exit 0 92 | ;; 93 | "c" | "count" ) 94 | count_flag="-c" 95 | ;; 96 | "t" | "tap" ) 97 | pretty="" 98 | ;; 99 | "p" | "pretty" ) 100 | pretty="1" 101 | ;; 102 | * ) 103 | usage >&2 104 | exit 1 105 | ;; 106 | esac 107 | done 108 | 109 | if [ "${#arguments[@]}" -eq 0 ]; then 110 | usage >&2 111 | exit 1 112 | fi 113 | 114 | filenames=() 115 | for filename in "${arguments[@]}"; do 116 | if [ -d "$filename" ]; then 117 | shopt -s nullglob 118 | for suite_filename in "$(expand_path "$filename")"/*.bats; do 119 | filenames["${#filenames[@]}"]="$suite_filename" 120 | done 121 | shopt -u nullglob 122 | else 123 | filenames["${#filenames[@]}"]="$(expand_path "$filename")" 124 | fi 125 | done 126 | 127 | if [ "${#filenames[@]}" -eq 1 ]; then 128 | command="bats-exec-test" 129 | else 130 | command="bats-exec-suite" 131 | fi 132 | 133 | if [ -n "$pretty" ]; then 134 | extended_syntax_flag="-x" 135 | formatter="bats-format-tap-stream" 136 | else 137 | extended_syntax_flag="" 138 | formatter="cat" 139 | fi 140 | 141 | set -o pipefail execfail 142 | exec "$command" $count_flag $extended_syntax_flag "${filenames[@]}" | "$formatter" 143 | -------------------------------------------------------------------------------- /vendor/bats/man/bats.1: -------------------------------------------------------------------------------- 1 | .\" generated with Ronn/v0.7.3 2 | .\" http://github.com/rtomayko/ronn/tree/0.7.3 3 | . 4 | .TH "BATS" "1" "August 2014" "" "" 5 | . 6 | .SH "NAME" 7 | \fBbats\fR \- Bash Automated Testing System 8 | . 9 | .SH "SYNOPSIS" 10 | bats [\-c] [\-p | \-t] \fItest\fR [\fItest\fR \.\.\.] 11 | . 12 | .P 13 | \fItest\fR is the path to a Bats test file, or the path to a directory containing Bats test files\. 14 | . 15 | .SH "DESCRIPTION" 16 | 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\. 17 | . 18 | .P 19 | 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\. 20 | . 21 | .P 22 | Test cases consist of standard shell commands\. Bats makes use of Bash\'s \fBerrexit\fR (\fBset \-e\fR) option when running test cases\. If every command in the test case exits with a \fB0\fR status code (success), the test passes\. In this way, each line is an assertion of truth\. 23 | . 24 | .P 25 | See \fBbats\fR(7) for more information on writing Bats tests\. 26 | . 27 | .SH "RUNNING TESTS" 28 | To run your tests, invoke the \fBbats\fR interpreter with a path to a test file\. The file\'s test cases are run sequentially and in isolation\. If all the test cases pass, \fBbats\fR exits with a \fB0\fR status code\. If there are any failures, \fBbats\fR exits with a \fB1\fR status code\. 29 | . 30 | .P 31 | You can invoke the \fBbats\fR interpreter with multiple test file arguments, or with a path to a directory containing multiple \fB\.bats\fR files\. Bats will run each test file individually and aggregate the results\. If any test case fails, \fBbats\fR exits with a \fB1\fR status code\. 32 | . 33 | .SH "OPTIONS" 34 | . 35 | .TP 36 | \fB\-c\fR, \fB\-\-count\fR 37 | Count the number of test cases without running any tests 38 | . 39 | .TP 40 | \fB\-h\fR, \fB\-\-help\fR 41 | Display help message 42 | . 43 | .TP 44 | \fB\-p\fR, \fB\-\-pretty\fR 45 | Show results in pretty format (default for terminals) 46 | . 47 | .TP 48 | \fB\-t\fR, \fB\-\-tap\fR 49 | Show results in TAP format 50 | . 51 | .TP 52 | \fB\-v\fR, \fB\-\-version\fR 53 | Display the version number 54 | . 55 | .SH "OUTPUT" 56 | 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\. 57 | . 58 | .IP "" 4 59 | . 60 | .nf 61 | 62 | $ bats addition\.bats 63 | ✓ addition using bc 64 | ✓ addition using dc 65 | 66 | 2 tests, 0 failures 67 | . 68 | .fi 69 | . 70 | .IP "" 0 71 | . 72 | .P 73 | If Bats is not connected to a terminal\-\-in other words, if you run it from a continuous integration system or redirect its output to a file\-\-the results are displayed in human\-readable, machine\-parsable TAP format\. You can force TAP output from a terminal by invoking Bats with the \fB\-\-tap\fR option\. 74 | . 75 | .IP "" 4 76 | . 77 | .nf 78 | 79 | $ bats \-\-tap addition\.bats 80 | 1\.\.2 81 | ok 1 addition using bc 82 | ok 2 addition using dc 83 | . 84 | .fi 85 | . 86 | .IP "" 0 87 | . 88 | .SH "EXIT STATUS" 89 | The \fBbats\fR interpreter exits with a value of \fB0\fR if all test cases pass, or \fB1\fR if one or more test cases fail\. 90 | . 91 | .SH "SEE ALSO" 92 | Bats wiki: \fIhttps://github\.com/sstephenson/bats/wiki/\fR 93 | . 94 | .P 95 | \fBbash\fR(1), \fBbats\fR(7) 96 | . 97 | .SH "COPYRIGHT" 98 | (c) 2014 Sam Stephenson 99 | . 100 | .P 101 | Bats is released under the terms of an MIT\-style license\. 102 | -------------------------------------------------------------------------------- /vendor/bats/libexec/bats-format-tap-stream: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | # Just stream the TAP output (sans extended syntax) if tput is missing 5 | command -v tput >/dev/null || exec grep -v "^begin " 6 | 7 | header_pattern='[0-9]+\.\.[0-9]+' 8 | IFS= read -r header 9 | 10 | if [[ "$header" =~ $header_pattern ]]; then 11 | count="${header:3}" 12 | index=0 13 | failures=0 14 | skipped=0 15 | name="" 16 | count_column_width=$(( ${#count} * 2 + 2 )) 17 | else 18 | # If the first line isn't a TAP plan, print it and pass the rest through 19 | printf "%s\n" "$header" 20 | exec cat 21 | fi 22 | 23 | update_screen_width() { 24 | screen_width="$(tput cols)" 25 | count_column_left=$(( $screen_width - $count_column_width )) 26 | } 27 | 28 | trap update_screen_width WINCH 29 | update_screen_width 30 | 31 | begin() { 32 | go_to_column 0 33 | printf_with_truncation $(( $count_column_left - 1 )) " %s" "$name" 34 | clear_to_end_of_line 35 | go_to_column $count_column_left 36 | printf "%${#count}s/${count}" "$index" 37 | go_to_column 1 38 | } 39 | 40 | pass() { 41 | go_to_column 0 42 | printf " ✓ %s" "$name" 43 | advance 44 | } 45 | 46 | skip() { 47 | local reason="$1" 48 | [ -z "$reason" ] || reason=": $reason" 49 | go_to_column 0 50 | printf " - %s (skipped%s)" "$name" "$reason" 51 | advance 52 | } 53 | 54 | fail() { 55 | go_to_column 0 56 | set_color 1 bold 57 | printf " ✗ %s" "$name" 58 | advance 59 | } 60 | 61 | log() { 62 | set_color 1 63 | printf " %s\n" "$1" 64 | clear_color 65 | } 66 | 67 | summary() { 68 | printf "\n%d test%s" "$count" "$(plural "$count")" 69 | 70 | printf ", %d failure%s" "$failures" "$(plural "$failures")" 71 | 72 | if [ "$skipped" -gt 0 ]; then 73 | printf ", %d skipped" "$skipped" 74 | fi 75 | 76 | printf "\n" 77 | } 78 | 79 | printf_with_truncation() { 80 | local width="$1" 81 | shift 82 | local string="$(printf "$@")" 83 | 84 | if [ "${#string}" -gt "$width" ]; then 85 | printf "%s..." "${string:0:$(( $width - 4 ))}" 86 | else 87 | printf "%s" "$string" 88 | fi 89 | } 90 | 91 | go_to_column() { 92 | local column="$1" 93 | printf "\x1B[%dG" $(( $column + 1 )) 94 | } 95 | 96 | clear_to_end_of_line() { 97 | printf "\x1B[K" 98 | } 99 | 100 | advance() { 101 | clear_to_end_of_line 102 | echo 103 | clear_color 104 | } 105 | 106 | set_color() { 107 | local color="$1" 108 | local weight="$2" 109 | printf "\x1B[%d;%dm" $(( 30 + $color )) "$( [ "$weight" = "bold" ] && echo 1 || echo 22 )" 110 | } 111 | 112 | clear_color() { 113 | printf "\x1B[0m" 114 | } 115 | 116 | plural() { 117 | [ "$1" -eq 1 ] || echo "s" 118 | } 119 | 120 | _buffer="" 121 | 122 | buffer() { 123 | _buffer="${_buffer}$("$@")" 124 | } 125 | 126 | flush() { 127 | printf "%s" "$_buffer" 128 | _buffer="" 129 | } 130 | 131 | finish() { 132 | flush 133 | printf "\n" 134 | } 135 | 136 | trap finish EXIT 137 | 138 | while IFS= read -r line; do 139 | case "$line" in 140 | "begin "* ) 141 | let index+=1 142 | name="${line#* $index }" 143 | buffer begin 144 | flush 145 | ;; 146 | "ok "* ) 147 | skip_expr="ok $index # skip (\(([^)]*)\))?" 148 | if [[ "$line" =~ $skip_expr ]]; then 149 | let skipped+=1 150 | buffer skip "${BASH_REMATCH[2]}" 151 | else 152 | buffer pass 153 | fi 154 | ;; 155 | "not ok "* ) 156 | let failures+=1 157 | buffer fail 158 | ;; 159 | "# "* ) 160 | buffer log "${line:2}" 161 | ;; 162 | esac 163 | done 164 | 165 | buffer summary 166 | -------------------------------------------------------------------------------- /vendor/bats/man/bats.7.ronn: -------------------------------------------------------------------------------- 1 | bats(7) -- Bats test file format 2 | ================================ 3 | 4 | 5 | DESCRIPTION 6 | ----------- 7 | 8 | A Bats test file is a Bash script with special syntax for defining 9 | test cases. Under the hood, each test case is just a function with a 10 | description. 11 | 12 | #!/usr/bin/env bats 13 | 14 | @test "addition using bc" { 15 | result="$(echo 2+2 | bc)" 16 | [ "$result" -eq 4 ] 17 | } 18 | 19 | @test "addition using dc" { 20 | result="$(echo 2 2+p | dc)" 21 | [ "$result" -eq 4 ] 22 | } 23 | 24 | 25 | Each Bats test file is evaluated n+1 times, where _n_ is the number of 26 | test cases in the file. The first run counts the number of test cases, 27 | then iterates over the test cases and executes each one in its own 28 | process. 29 | 30 | 31 | THE RUN HELPER 32 | -------------- 33 | 34 | Many Bats tests need to run a command and then make assertions about 35 | its exit status and output. Bats includes a `run` helper that invokes 36 | its arguments as a command, saves the exit status and output into 37 | special global variables, and then returns with a `0` status code so 38 | you can continue to make assertions in your test case. 39 | 40 | For example, let's say you're testing that the `foo` command, when 41 | passed a nonexistent filename, exits with a `1` status code and prints 42 | an error message. 43 | 44 | @test "invoking foo with a nonexistent file prints an error" { 45 | run foo nonexistent_filename 46 | [ "$status" -eq 1 ] 47 | [ "$output" = "foo: no such file 'nonexistent_filename'" ] 48 | } 49 | 50 | The `$status` variable contains the status code of the command, and 51 | the `$output` variable contains the combined contents of the command's 52 | standard output and standard error streams. 53 | 54 | A third special variable, the `$lines` array, is available for easily 55 | accessing individual lines of output. For example, if you want to test 56 | that invoking `foo` without any arguments prints usage information on 57 | the first line: 58 | 59 | @test "invoking foo without arguments prints usage" { 60 | run foo 61 | [ "$status" -eq 1 ] 62 | [ "${lines[0]}" = "usage: foo " ] 63 | } 64 | 65 | 66 | THE LOAD COMMAND 67 | ---------------- 68 | 69 | You may want to share common code across multiple test files. Bats 70 | includes a convenient `load` command for sourcing a Bash source file 71 | relative to the location of the current test file. For example, if you 72 | have a Bats test in `test/foo.bats`, the command 73 | 74 | load test_helper 75 | 76 | will source the script `test/test_helper.bash` in your test file. This 77 | can be useful for sharing functions to set up your environment or load 78 | fixtures. 79 | 80 | 81 | THE SKIP COMMAND 82 | ---------------- 83 | 84 | Tests can be skipped by using the `skip` command at the point in a 85 | test you wish to skip. 86 | 87 | @test "A test I don't want to execute for now" { 88 | skip 89 | run foo 90 | [ "$status" -eq 0 ] 91 | } 92 | 93 | Optionally, you may include a reason for skipping: 94 | 95 | @test "A test I don't want to execute for now" { 96 | skip "This command will return zero soon, but not now" 97 | run foo 98 | [ "$status" -eq 0 ] 99 | } 100 | 101 | Or you can skip conditionally: 102 | 103 | @test "A test which should run" { 104 | if [ foo != bar ]; then 105 | skip "foo isn't bar" 106 | fi 107 | 108 | run foo 109 | [ "$status" -eq 0 ] 110 | } 111 | 112 | 113 | SETUP AND TEARDOWN FUNCTIONS 114 | ---------------------------- 115 | 116 | You can define special `setup` and `teardown` functions which run 117 | before and after each test case, respectively. Use these to load 118 | fixtures, set up your environment, and clean up when you're done. 119 | 120 | 121 | CODE OUTSIDE OF TEST CASES 122 | -------------------------- 123 | 124 | You can include code in your test file outside of `@test` functions. 125 | For example, this may be useful if you want to check for dependencies 126 | and fail immediately if they're not present. However, any output that 127 | you print in code outside of `@test`, `setup` or `teardown` functions 128 | must be redirected to `stderr` (`>&2`). Otherwise, the output may 129 | cause Bats to fail by polluting the TAP stream on `stdout`. 130 | 131 | 132 | SPECIAL VARIABLES 133 | ----------------- 134 | 135 | There are several global variables you can use to introspect on Bats 136 | tests: 137 | 138 | * `$BATS_TEST_FILENAME` is the fully expanded path to the Bats test 139 | file. 140 | * `$BATS_TEST_DIRNAME` is the directory in which the Bats test file is 141 | located. 142 | * `$BATS_TEST_NAMES` is an array of function names for each test case. 143 | * `$BATS_TEST_NAME` is the name of the function containing the current 144 | test case. 145 | * `$BATS_TEST_DESCRIPTION` is the description of the current test 146 | case. 147 | * `$BATS_TEST_NUMBER` is the (1-based) index of the current test case 148 | in the test file. 149 | * `$BATS_TMPDIR` is the location to a directory that may be used to 150 | store temporary files. 151 | 152 | 153 | SEE ALSO 154 | -------- 155 | 156 | `bash`(1), `bats`(1) 157 | -------------------------------------------------------------------------------- /vendor/bats/man/bats.7: -------------------------------------------------------------------------------- 1 | .\" generated with Ronn/v0.7.3 2 | .\" http://github.com/rtomayko/ronn/tree/0.7.3 3 | . 4 | .TH "BATS" "7" "November 2013" "" "" 5 | . 6 | .SH "NAME" 7 | \fBbats\fR \- Bats test file format 8 | . 9 | .SH "DESCRIPTION" 10 | A Bats test file is a Bash script with special syntax for defining test cases\. Under the hood, each test case is just a function with a description\. 11 | . 12 | .IP "" 4 13 | . 14 | .nf 15 | 16 | #!/usr/bin/env bats 17 | 18 | @test "addition using bc" { 19 | result="$(echo 2+2 | bc)" 20 | [ "$result" \-eq 4 ] 21 | } 22 | 23 | @test "addition using dc" { 24 | result="$(echo 2 2+p | dc)" 25 | [ "$result" \-eq 4 ] 26 | } 27 | . 28 | .fi 29 | . 30 | .IP "" 0 31 | . 32 | .P 33 | Each Bats test file is evaluated n+1 times, where \fIn\fR is the number of test cases in the file\. The first run counts the number of test cases, then iterates over the test cases and executes each one in its own process\. 34 | . 35 | .SH "THE RUN HELPER" 36 | Many Bats tests need to run a command and then make assertions about its exit status and output\. Bats includes a \fBrun\fR helper that invokes its arguments as a command, saves the exit status and output into special global variables, and then returns with a \fB0\fR status code so you can continue to make assertions in your test case\. 37 | . 38 | .P 39 | For example, let\'s say you\'re testing that the \fBfoo\fR command, when passed a nonexistent filename, exits with a \fB1\fR status code and prints an error message\. 40 | . 41 | .IP "" 4 42 | . 43 | .nf 44 | 45 | @test "invoking foo with a nonexistent file prints an error" { 46 | run foo nonexistent_filename 47 | [ "$status" \-eq 1 ] 48 | [ "$output" = "foo: no such file \'nonexistent_filename\'" ] 49 | } 50 | . 51 | .fi 52 | . 53 | .IP "" 0 54 | . 55 | .P 56 | The \fB$status\fR variable contains the status code of the command, and the \fB$output\fR variable contains the combined contents of the command\'s standard output and standard error streams\. 57 | . 58 | .P 59 | A third special variable, the \fB$lines\fR array, is available for easily accessing individual lines of output\. For example, if you want to test that invoking \fBfoo\fR without any arguments prints usage information on the first line: 60 | . 61 | .IP "" 4 62 | . 63 | .nf 64 | 65 | @test "invoking foo without arguments prints usage" { 66 | run foo 67 | [ "$status" \-eq 1 ] 68 | [ "${lines[0]}" = "usage: foo " ] 69 | } 70 | . 71 | .fi 72 | . 73 | .IP "" 0 74 | . 75 | .SH "THE LOAD COMMAND" 76 | You may want to share common code across multiple test files\. Bats includes a convenient \fBload\fR command for sourcing a Bash source file relative to the location of the current test file\. For example, if you have a Bats test in \fBtest/foo\.bats\fR, the command 77 | . 78 | .IP "" 4 79 | . 80 | .nf 81 | 82 | load test_helper 83 | . 84 | .fi 85 | . 86 | .IP "" 0 87 | . 88 | .P 89 | will source the script \fBtest/test_helper\.bash\fR in your test file\. This can be useful for sharing functions to set up your environment or load fixtures\. 90 | . 91 | .SH "THE SKIP COMMAND" 92 | Tests can be skipped by using the \fBskip\fR command at the point in a test you wish to skip\. 93 | . 94 | .IP "" 4 95 | . 96 | .nf 97 | 98 | @test "A test I don\'t want to execute for now" { 99 | skip 100 | run foo 101 | [ "$status" \-eq 0 ] 102 | } 103 | . 104 | .fi 105 | . 106 | .IP "" 0 107 | . 108 | .P 109 | Optionally, you may include a reason for skipping: 110 | . 111 | .IP "" 4 112 | . 113 | .nf 114 | 115 | @test "A test I don\'t want to execute for now" { 116 | skip "This command will return zero soon, but not now" 117 | run foo 118 | [ "$status" \-eq 0 ] 119 | } 120 | . 121 | .fi 122 | . 123 | .IP "" 0 124 | . 125 | .P 126 | Or you can skip conditionally: 127 | . 128 | .IP "" 4 129 | . 130 | .nf 131 | 132 | @test "A test which should run" { 133 | if [ foo != bar ]; then 134 | skip "foo isn\'t bar" 135 | fi 136 | 137 | run foo 138 | [ "$status" \-eq 0 ] 139 | } 140 | . 141 | .fi 142 | . 143 | .IP "" 0 144 | . 145 | .SH "SETUP AND TEARDOWN FUNCTIONS" 146 | You can define special \fBsetup\fR and \fBteardown\fR functions which run before and after each test case, respectively\. Use these to load fixtures, set up your environment, and clean up when you\'re done\. 147 | . 148 | .SH "CODE OUTSIDE OF TEST CASES" 149 | You can include code in your test file outside of \fB@test\fR functions\. For example, this may be useful if you want to check for dependencies and fail immediately if they\'re not present\. However, any output that you print in code outside of \fB@test\fR, \fBsetup\fR or \fBteardown\fR functions must be redirected to \fBstderr\fR (\fB>&2\fR)\. Otherwise, the output may cause Bats to fail by polluting the TAP stream on \fBstdout\fR\. 150 | . 151 | .SH "SPECIAL VARIABLES" 152 | There are several global variables you can use to introspect on Bats tests: 153 | . 154 | .IP "\(bu" 4 155 | \fB$BATS_TEST_FILENAME\fR is the fully expanded path to the Bats test file\. 156 | . 157 | .IP "\(bu" 4 158 | \fB$BATS_TEST_DIRNAME\fR is the directory in which the Bats test file is located\. 159 | . 160 | .IP "\(bu" 4 161 | \fB$BATS_TEST_NAMES\fR is an array of function names for each test case\. 162 | . 163 | .IP "\(bu" 4 164 | \fB$BATS_TEST_NAME\fR is the name of the function containing the current test case\. 165 | . 166 | .IP "\(bu" 4 167 | \fB$BATS_TEST_DESCRIPTION\fR is the description of the current test case\. 168 | . 169 | .IP "\(bu" 4 170 | \fB$BATS_TEST_NUMBER\fR is the (1\-based) index of the current test case in the test file\. 171 | . 172 | .IP "\(bu" 4 173 | \fB$BATS_TMPDIR\fR is the location to a directory that may be used to store temporary files\. 174 | . 175 | .IP "" 0 176 | . 177 | .SH "SEE ALSO" 178 | \fBbash\fR(1), \fBbats\fR(1) 179 | -------------------------------------------------------------------------------- /vendor/bats/libexec/bats-exec-test: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | set -E 4 | set -T 5 | 6 | BATS_COUNT_ONLY="" 7 | if [ "$1" = "-c" ]; then 8 | BATS_COUNT_ONLY=1 9 | shift 10 | fi 11 | 12 | BATS_EXTENDED_SYNTAX="" 13 | if [ "$1" = "-x" ]; then 14 | BATS_EXTENDED_SYNTAX="$1" 15 | shift 16 | fi 17 | 18 | BATS_TEST_FILENAME="$1" 19 | if [ -z "$BATS_TEST_FILENAME" ]; then 20 | echo "usage: bats-exec " >&2 21 | exit 1 22 | elif [ ! -f "$BATS_TEST_FILENAME" ]; then 23 | echo "bats: $BATS_TEST_FILENAME does not exist" >&2 24 | exit 1 25 | else 26 | shift 27 | fi 28 | 29 | BATS_TEST_DIRNAME="$(dirname "$BATS_TEST_FILENAME")" 30 | BATS_TEST_NAMES=() 31 | 32 | load() { 33 | local name="$1" 34 | local filename 35 | 36 | if [ "${name:0:1}" = "/" ]; then 37 | filename="${name}" 38 | else 39 | filename="$BATS_TEST_DIRNAME/${name}.bash" 40 | fi 41 | 42 | [ -f "$filename" ] || { 43 | echo "bats: $filename does not exist" >&2 44 | exit 1 45 | } 46 | 47 | source "${filename}" 48 | } 49 | 50 | run() { 51 | local e E T 52 | [[ ! "$-" =~ e ]] || e=1 53 | [[ ! "$-" =~ E ]] || E=1 54 | [[ ! "$-" =~ T ]] || T=1 55 | set +e 56 | set +E 57 | set +T 58 | output="$("$@" 2>&1)" 59 | status="$?" 60 | IFS=$'\n' lines=($output) 61 | [ -z "$e" ] || set -e 62 | [ -z "$E" ] || set -E 63 | [ -z "$T" ] || set -T 64 | } 65 | 66 | setup() { 67 | true 68 | } 69 | 70 | teardown() { 71 | true 72 | } 73 | 74 | skip() { 75 | BATS_TEST_SKIPPED=${1:-1} 76 | BATS_TEST_COMPLETED=1 77 | exit 0 78 | } 79 | 80 | bats_test_begin() { 81 | BATS_TEST_DESCRIPTION="$1" 82 | if [ -n "$BATS_EXTENDED_SYNTAX" ]; then 83 | echo "begin $BATS_TEST_NUMBER $BATS_TEST_DESCRIPTION" >&3 84 | fi 85 | setup 86 | } 87 | 88 | bats_test_function() { 89 | local test_name="$1" 90 | BATS_TEST_NAMES["${#BATS_TEST_NAMES[@]}"]="$test_name" 91 | } 92 | 93 | bats_capture_stack_trace() { 94 | BATS_PREVIOUS_STACK_TRACE=( "${BATS_CURRENT_STACK_TRACE[@]}" ) 95 | BATS_CURRENT_STACK_TRACE=() 96 | 97 | local test_pattern=" $BATS_TEST_NAME $BATS_TEST_SOURCE" 98 | local setup_pattern=" setup $BATS_TEST_SOURCE" 99 | local teardown_pattern=" teardown $BATS_TEST_SOURCE" 100 | 101 | local frame 102 | local index=1 103 | 104 | while frame="$(caller "$index")"; do 105 | BATS_CURRENT_STACK_TRACE["${#BATS_CURRENT_STACK_TRACE[@]}"]="$frame" 106 | if [[ "$frame" = *"$test_pattern" || \ 107 | "$frame" = *"$setup_pattern" || \ 108 | "$frame" = *"$teardown_pattern" ]]; then 109 | break 110 | else 111 | let index+=1 112 | fi 113 | done 114 | 115 | BATS_SOURCE="$(bats_frame_filename "${BATS_CURRENT_STACK_TRACE[0]}")" 116 | BATS_LINENO="$(bats_frame_lineno "${BATS_CURRENT_STACK_TRACE[0]}")" 117 | } 118 | 119 | bats_print_stack_trace() { 120 | local frame 121 | local index=1 122 | local count="${#@}" 123 | 124 | for frame in "$@"; do 125 | local filename="$(bats_trim_filename "$(bats_frame_filename "$frame")")" 126 | local lineno="$(bats_frame_lineno "$frame")" 127 | 128 | if [ $index -eq 1 ]; then 129 | echo -n "# (" 130 | else 131 | echo -n "# " 132 | fi 133 | 134 | local fn="$(bats_frame_function "$frame")" 135 | if [ "$fn" != "$BATS_TEST_NAME" ]; then 136 | echo -n "from function \`$fn' " 137 | fi 138 | 139 | if [ $index -eq $count ]; then 140 | echo "in test file $filename, line $lineno)" 141 | else 142 | echo "in file $filename, line $lineno," 143 | fi 144 | 145 | let index+=1 146 | done 147 | } 148 | 149 | bats_print_failed_command() { 150 | local frame="$1" 151 | local status="$2" 152 | local filename="$(bats_frame_filename "$frame")" 153 | local lineno="$(bats_frame_lineno "$frame")" 154 | 155 | local failed_line="$(bats_extract_line "$filename" "$lineno")" 156 | local failed_command="$(bats_strip_string "$failed_line")" 157 | echo -n "# \`${failed_command}' " 158 | 159 | if [ $status -eq 1 ]; then 160 | echo "failed" 161 | else 162 | echo "failed with status $status" 163 | fi 164 | } 165 | 166 | bats_frame_lineno() { 167 | local frame="$1" 168 | local lineno="${frame%% *}" 169 | echo "$lineno" 170 | } 171 | 172 | bats_frame_function() { 173 | local frame="$1" 174 | local rest="${frame#* }" 175 | local fn="${rest%% *}" 176 | echo "$fn" 177 | } 178 | 179 | bats_frame_filename() { 180 | local frame="$1" 181 | local rest="${frame#* }" 182 | local filename="${rest#* }" 183 | 184 | if [ "$filename" = "$BATS_TEST_SOURCE" ]; then 185 | echo "$BATS_TEST_FILENAME" 186 | else 187 | echo "$filename" 188 | fi 189 | } 190 | 191 | bats_extract_line() { 192 | local filename="$1" 193 | local lineno="$2" 194 | sed -n "${lineno}p" "$filename" 195 | } 196 | 197 | bats_strip_string() { 198 | local string="$1" 199 | printf "%s" "$string" | sed -e "s/^[ "$'\t'"]*//" -e "s/[ "$'\t'"]*$//" 200 | } 201 | 202 | bats_trim_filename() { 203 | local filename="$1" 204 | local length="${#BATS_CWD}" 205 | 206 | if [ "${filename:0:length+1}" = "${BATS_CWD}/" ]; then 207 | echo "${filename:length+1}" 208 | else 209 | echo "$filename" 210 | fi 211 | } 212 | 213 | bats_debug_trap() { 214 | if [ "$BASH_SOURCE" != "$1" ]; then 215 | bats_capture_stack_trace 216 | fi 217 | } 218 | 219 | bats_error_trap() { 220 | BATS_ERROR_STATUS="$?" 221 | BATS_ERROR_STACK_TRACE=( "${BATS_PREVIOUS_STACK_TRACE[@]}" ) 222 | trap - debug 223 | } 224 | 225 | bats_teardown_trap() { 226 | trap "bats_exit_trap" exit 227 | local status=0 228 | teardown >>"$BATS_OUT" 2>&1 || status="$?" 229 | 230 | if [ $status -eq 0 ]; then 231 | BATS_TEARDOWN_COMPLETED=1 232 | elif [ -n "$BATS_TEST_COMPLETED" ]; then 233 | BATS_ERROR_STATUS="$status" 234 | BATS_ERROR_STACK_TRACE=( "${BATS_CURRENT_STACK_TRACE[@]}" ) 235 | fi 236 | 237 | bats_exit_trap 238 | } 239 | 240 | bats_exit_trap() { 241 | local status 242 | local skipped 243 | trap - err exit 244 | 245 | skipped="" 246 | if [ -n "$BATS_TEST_SKIPPED" ]; then 247 | skipped=" # skip" 248 | if [ "1" != "$BATS_TEST_SKIPPED" ]; then 249 | skipped+=" ($BATS_TEST_SKIPPED)" 250 | fi 251 | fi 252 | 253 | if [ -z "$BATS_TEST_COMPLETED" ] || [ -z "$BATS_TEARDOWN_COMPLETED" ]; then 254 | echo "not ok $BATS_TEST_NUMBER $BATS_TEST_DESCRIPTION" >&3 255 | bats_print_stack_trace "${BATS_ERROR_STACK_TRACE[@]}" >&3 256 | bats_print_failed_command "${BATS_ERROR_STACK_TRACE[${#BATS_ERROR_STACK_TRACE[@]}-1]}" "$BATS_ERROR_STATUS" >&3 257 | sed -e "s/^/# /" < "$BATS_OUT" >&3 258 | status=1 259 | else 260 | echo "ok ${BATS_TEST_NUMBER}${skipped} ${BATS_TEST_DESCRIPTION}" >&3 261 | status=0 262 | fi 263 | 264 | rm -f "$BATS_OUT" 265 | exit "$status" 266 | } 267 | 268 | bats_perform_tests() { 269 | echo "1..$#" 270 | test_number=1 271 | status=0 272 | for test_name in "$@"; do 273 | "$0" $BATS_EXTENDED_SYNTAX "$BATS_TEST_FILENAME" "$test_name" "$test_number" || status=1 274 | let test_number+=1 275 | done 276 | exit "$status" 277 | } 278 | 279 | bats_perform_test() { 280 | BATS_TEST_NAME="$1" 281 | if [ "$(type -t "$BATS_TEST_NAME" || true)" = "function" ]; then 282 | BATS_TEST_NUMBER="$2" 283 | if [ -z "$BATS_TEST_NUMBER" ]; then 284 | echo "1..1" 285 | BATS_TEST_NUMBER="1" 286 | fi 287 | 288 | BATS_TEST_COMPLETED="" 289 | BATS_TEARDOWN_COMPLETED="" 290 | trap "bats_debug_trap \"\$BASH_SOURCE\"" debug 291 | trap "bats_error_trap" err 292 | trap "bats_teardown_trap" exit 293 | "$BATS_TEST_NAME" >>"$BATS_OUT" 2>&1 294 | BATS_TEST_COMPLETED=1 295 | 296 | else 297 | echo "bats: unknown test name \`$BATS_TEST_NAME'" >&2 298 | exit 1 299 | fi 300 | } 301 | 302 | if [ -z "$TMPDIR" ]; then 303 | BATS_TMPDIR="/tmp" 304 | else 305 | BATS_TMPDIR="${TMPDIR%/}" 306 | fi 307 | 308 | BATS_TMPNAME="$BATS_TMPDIR/bats.$$" 309 | BATS_PARENT_TMPNAME="$BATS_TMPDIR/bats.$PPID" 310 | BATS_OUT="${BATS_TMPNAME}.out" 311 | 312 | bats_preprocess_source() { 313 | BATS_TEST_SOURCE="${BATS_TMPNAME}.src" 314 | { tr -d '\r' < "$BATS_TEST_FILENAME"; echo; } | bats-preprocess > "$BATS_TEST_SOURCE" 315 | trap "bats_cleanup_preprocessed_source" err exit 316 | trap "bats_cleanup_preprocessed_source; exit 1" int 317 | } 318 | 319 | bats_cleanup_preprocessed_source() { 320 | rm -f "$BATS_TEST_SOURCE" 321 | } 322 | 323 | bats_evaluate_preprocessed_source() { 324 | if [ -z "$BATS_TEST_SOURCE" ]; then 325 | BATS_TEST_SOURCE="${BATS_PARENT_TMPNAME}.src" 326 | fi 327 | source "$BATS_TEST_SOURCE" 328 | } 329 | 330 | exec 3<&1 331 | 332 | if [ "$#" -eq 0 ]; then 333 | bats_preprocess_source 334 | bats_evaluate_preprocessed_source 335 | 336 | if [ -n "$BATS_COUNT_ONLY" ]; then 337 | echo "${#BATS_TEST_NAMES[@]}" 338 | else 339 | bats_perform_tests "${BATS_TEST_NAMES[@]}" 340 | fi 341 | else 342 | bats_evaluate_preprocessed_source 343 | bats_perform_test "$@" 344 | fi 345 | -------------------------------------------------------------------------------- /vendor/bats/README.md: -------------------------------------------------------------------------------- 1 | # Bats: Bash Automated Testing System 2 | 3 | Bats is a [TAP](http://testanything.org)-compliant testing framework 4 | for Bash. It provides a simple way to verify that the UNIX programs 5 | you write behave as expected. 6 | 7 | A Bats test file is a Bash script with special syntax for defining 8 | test cases. Under the hood, each test case is just a function with a 9 | description. 10 | 11 | ```bash 12 | #!/usr/bin/env bats 13 | 14 | @test "addition using bc" { 15 | result="$(echo 2+2 | bc)" 16 | [ "$result" -eq 4 ] 17 | } 18 | 19 | @test "addition using dc" { 20 | result="$(echo 2 2+p | dc)" 21 | [ "$result" -eq 4 ] 22 | } 23 | ``` 24 | 25 | Bats is most useful when testing software written in Bash, but you can 26 | use it to test any UNIX program. 27 | 28 | Test cases consist of standard shell commands. Bats makes use of 29 | Bash's `errexit` (`set -e`) option when running test cases. If every 30 | command in the test case exits with a `0` status code (success), the 31 | test passes. In this way, each line is an assertion of truth. 32 | 33 | 34 | ## Running tests 35 | 36 | To run your tests, invoke the `bats` interpreter with a path to a test 37 | file. The file's test cases are run sequentially and in isolation. If 38 | all the test cases pass, `bats` exits with a `0` status code. If there 39 | are any failures, `bats` exits with a `1` status code. 40 | 41 | When you run Bats from a terminal, you'll see output as each test is 42 | performed, with a check-mark next to the test's name if it passes or 43 | an "X" if it fails. 44 | 45 | $ bats addition.bats 46 | ✓ addition using bc 47 | ✓ addition using dc 48 | 49 | 2 tests, 0 failures 50 | 51 | If Bats is not connected to a terminal—in other words, if you 52 | run it from a continuous integration system, or redirect its output to 53 | a file—the results are displayed in human-readable, machine-parsable 54 | [TAP format](http://testanything.org). 55 | 56 | You can force TAP output from a terminal by invoking Bats with the 57 | `--tap` option. 58 | 59 | $ bats --tap addition.bats 60 | 1..2 61 | ok 1 addition using bc 62 | ok 2 addition using dc 63 | 64 | ### Test suites 65 | 66 | You can invoke the `bats` interpreter with multiple test file 67 | arguments, or with a path to a directory containing multiple `.bats` 68 | files. Bats will run each test file individually and aggregate the 69 | results. If any test case fails, `bats` exits with a `1` status code. 70 | 71 | 72 | ## Writing tests 73 | 74 | Each Bats test file is evaluated _n+1_ times, where _n_ is the number of 75 | test cases in the file. The first run counts the number of test cases, 76 | then iterates over the test cases and executes each one in its own 77 | process. 78 | 79 | For more details about how Bats evaluates test files, see 80 | [Bats Evaluation Process](https://github.com/sstephenson/bats/wiki/Bats-Evaluation-Process) 81 | on the wiki. 82 | 83 | ### `run`: Test other commands 84 | 85 | Many Bats tests need to run a command and then make assertions about 86 | its exit status and output. Bats includes a `run` helper that invokes 87 | its arguments as a command, saves the exit status and output into 88 | special global variables, and then returns with a `0` status code so 89 | you can continue to make assertions in your test case. 90 | 91 | For example, let's say you're testing that the `foo` command, when 92 | passed a nonexistent filename, exits with a `1` status code and prints 93 | an error message. 94 | 95 | ```bash 96 | @test "invoking foo with a nonexistent file prints an error" { 97 | run foo nonexistent_filename 98 | [ "$status" -eq 1 ] 99 | [ "$output" = "foo: no such file 'nonexistent_filename'" ] 100 | } 101 | ``` 102 | 103 | The `$status` variable contains the status code of the command, and 104 | the `$output` variable contains the combined contents of the command's 105 | standard output and standard error streams. 106 | 107 | A third special variable, the `$lines` array, is available for easily 108 | accessing individual lines of output. For example, if you want to test 109 | that invoking `foo` without any arguments prints usage information on 110 | the first line: 111 | 112 | ```bash 113 | @test "invoking foo without arguments prints usage" { 114 | run foo 115 | [ "$status" -eq 1 ] 116 | [ "${lines[0]}" = "usage: foo " ] 117 | } 118 | ``` 119 | 120 | ### `load`: Share common code 121 | 122 | You may want to share common code across multiple test files. Bats 123 | includes a convenient `load` command for sourcing a Bash source file 124 | relative to the location of the current test file. For example, if you 125 | have a Bats test in `test/foo.bats`, the command 126 | 127 | ```bash 128 | load test_helper 129 | ``` 130 | 131 | will source the script `test/test_helper.bash` in your test file. This 132 | can be useful for sharing functions to set up your environment or load 133 | fixtures. 134 | 135 | ### `skip`: Easily skip tests 136 | 137 | Tests can be skipped by using the `skip` command at the point in a 138 | test you wish to skip. 139 | 140 | ```bash 141 | @test "A test I don't want to execute for now" { 142 | skip 143 | run foo 144 | [ "$status" -eq 0 ] 145 | } 146 | ``` 147 | 148 | Optionally, you may include a reason for skipping: 149 | 150 | ```bash 151 | @test "A test I don't want to execute for now" { 152 | skip "This command will return zero soon, but not now" 153 | run foo 154 | [ "$status" -eq 0 ] 155 | } 156 | ``` 157 | 158 | Or you can skip conditionally: 159 | 160 | ```bash 161 | @test "A test which should run" { 162 | if [ foo != bar ]; then 163 | skip "foo isn't bar" 164 | fi 165 | 166 | run foo 167 | [ "$status" -eq 0 ] 168 | } 169 | ``` 170 | 171 | ### `setup` and `teardown`: Pre- and post-test hooks 172 | 173 | You can define special `setup` and `teardown` functions, which run 174 | before and after each test case, respectively. Use these to load 175 | fixtures, set up your environment, and clean up when you're done. 176 | 177 | ### Code outside of test cases 178 | 179 | You can include code in your test file outside of `@test` functions. 180 | For example, this may be useful if you want to check for dependencies 181 | and fail immediately if they're not present. However, any output that 182 | you print in code outside of `@test`, `setup` or `teardown` functions 183 | must be redirected to `stderr` (`>&2`). Otherwise, the output may 184 | cause Bats to fail by polluting the TAP stream on `stdout`. 185 | 186 | ### Special variables 187 | 188 | There are several global variables you can use to introspect on Bats 189 | tests: 190 | 191 | * `$BATS_TEST_FILENAME` is the fully expanded path to the Bats test 192 | file. 193 | * `$BATS_TEST_DIRNAME` is the directory in which the Bats test file is 194 | located. 195 | * `$BATS_TEST_NAMES` is an array of function names for each test case. 196 | * `$BATS_TEST_NAME` is the name of the function containing the current 197 | test case. 198 | * `$BATS_TEST_DESCRIPTION` is the description of the current test 199 | case. 200 | * `$BATS_TEST_NUMBER` is the (1-based) index of the current test case 201 | in the test file. 202 | * `$BATS_TMPDIR` is the location to a directory that may be used to 203 | store temporary files. 204 | 205 | 206 | ## Installing Bats from source 207 | 208 | Check out a copy of the Bats repository. Then, either add the Bats 209 | `bin` directory to your `$PATH`, or run the provided `install.sh` 210 | command with the location to the prefix in which you want to install 211 | Bats. For example, to install Bats into `/usr/local`, 212 | 213 | $ git clone https://github.com/sstephenson/bats.git 214 | $ cd bats 215 | $ ./install.sh /usr/local 216 | 217 | Note that you may need to run `install.sh` with `sudo` if you do not 218 | have permission to write to the installation prefix. 219 | 220 | 221 | ## Support 222 | 223 | The Bats source code repository is [hosted on 224 | GitHub](https://github.com/sstephenson/bats). There you can file bugs 225 | on the issue tracker or submit tested pull requests for review. 226 | 227 | For real-world examples from open-source projects using Bats, see 228 | [Projects Using Bats](https://github.com/sstephenson/bats/wiki/Projects-Using-Bats) 229 | on the wiki. 230 | 231 | To learn how to set up your editor for Bats syntax highlighting, see 232 | [Syntax Highlighting](https://github.com/sstephenson/bats/wiki/Syntax-Highlighting) 233 | on the wiki. 234 | 235 | 236 | ## Version history 237 | 238 | *0.4.0* (August 13, 2014) 239 | 240 | * Improved the display of failing test cases. Bats now shows the 241 | source code of failing test lines, along with full stack traces 242 | including function names, filenames, and line numbers. 243 | * Improved the display of the pretty-printed test summary line to 244 | include the number of skipped tests, if any. 245 | * Improved the speed of the preprocessor, dramatically shortening test 246 | and suite startup times. 247 | * Added support for absolute pathnames to the `load` helper. 248 | * Added support for single-line `@test` definitions. 249 | * Added bats(1) and bats(7) manual pages. 250 | * Modified the `bats` command to default to TAP output when the `$CI` 251 | variable is set, to better support environments such as Travis CI. 252 | 253 | *0.3.1* (October 28, 2013) 254 | 255 | * Fixed an incompatibility with the pretty formatter in certain 256 | environments such as tmux. 257 | * Fixed a bug where the pretty formatter would crash if the first line 258 | of a test file's output was invalid TAP. 259 | 260 | *0.3.0* (October 21, 2013) 261 | 262 | * Improved formatting for tests run from a terminal. Failing tests 263 | are now colored in red, and the total number of failing tests is 264 | displayed at the end of the test run. When Bats is not connected to 265 | a terminal (e.g. in CI runs), or when invoked with the `--tap` flag, 266 | output is displayed in standard TAP format. 267 | * Added the ability to skip tests using the `skip` command. 268 | * Added a message to failing test case output indicating the file and 269 | line number of the statement that caused the test to fail. 270 | * Added "ad-hoc" test suite support. You can now invoke `bats` with 271 | multiple filename or directory arguments to run all the specified 272 | tests in aggregate. 273 | * Added support for test files with Windows line endings. 274 | * Fixed regular expression warnings from certain versions of Bash. 275 | * Fixed a bug running tests containing lines that begin with `-e`. 276 | 277 | *0.2.0* (November 16, 2012) 278 | 279 | * Added test suite support. The `bats` command accepts a directory 280 | name containing multiple test files to be run in aggregate. 281 | * Added the ability to count the number of test cases in a file or 282 | suite by passing the `-c` flag to `bats`. 283 | * Preprocessed sources are cached between test case runs in the same 284 | file for better performance. 285 | 286 | *0.1.0* (December 30, 2011) 287 | 288 | * Initial public release. 289 | 290 | --- 291 | 292 | © 2014 Sam Stephenson. Bats is released under an MIT-style license; 293 | see `LICENSE` for details. 294 | --------------------------------------------------------------------------------