Full Code of sstephenson/bats for AI

master 03608115df20 cached
48 files
57.0 KB
18.5k tokens
1 requests
Download .txt
Repository: sstephenson/bats
Branch: master
Commit: 03608115df20
Files: 48
Total size: 57.0 KB

Directory structure:
gitextract_ytbcl905/

├── .gitattributes
├── .travis.yml
├── CONDUCT.md
├── LICENSE
├── README.md
├── install.sh
├── libexec/
│   ├── bats
│   ├── bats-exec-suite
│   ├── bats-exec-test
│   ├── bats-format-tap-stream
│   └── bats-preprocess
├── man/
│   ├── Makefile
│   ├── README.md
│   ├── bats.1
│   ├── bats.1.ronn
│   ├── bats.7
│   └── bats.7.ronn
├── package.json
└── test/
    ├── bats.bats
    ├── fixtures/
    │   ├── bats/
    │   │   ├── dos_line.bats
    │   │   ├── empty.bats
    │   │   ├── environment.bats
    │   │   ├── failing.bats
    │   │   ├── failing_and_passing.bats
    │   │   ├── failing_helper.bats
    │   │   ├── failing_setup.bats
    │   │   ├── failing_teardown.bats
    │   │   ├── intact.bats
    │   │   ├── invalid_tap.bats
    │   │   ├── load.bats
    │   │   ├── loop_keep_IFS.bats
    │   │   ├── output.bats
    │   │   ├── passing.bats
    │   │   ├── passing_and_failing.bats
    │   │   ├── passing_and_skipping.bats
    │   │   ├── passing_failing_and_skipping.bats
    │   │   ├── setup.bats
    │   │   ├── single_line.bats
    │   │   ├── skipped.bats
    │   │   ├── teardown.bats
    │   │   ├── test_helper.bash
    │   │   └── without_trailing_newline.bats
    │   └── suite/
    │       ├── empty/
    │       │   └── .gitkeep
    │       ├── multiple/
    │       │   ├── a.bats
    │       │   └── b.bats
    │       └── single/
    │           └── test.bats
    ├── suite.bats
    └── test_helper.bash

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitattributes
================================================
* text=auto
*.sh eol=lf
libexec/* eol=lf


================================================
FILE: .travis.yml
================================================
language: c
script: bin/bats --tap test
notifications:
  email:
    on_success: never


================================================
FILE: CONDUCT.md
================================================
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
  address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
  professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting one of the project maintainers listed below. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Project Maintainers

* Sam Stephenson <<sstephenson@gmail.com>>

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/


================================================
FILE: LICENSE
================================================
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.


================================================
FILE: README.md
================================================
# Bats: Bash Automated Testing System

Bats is a [TAP](http://testanything.org)-compliant testing framework
for Bash. It provides a simple way to verify that the UNIX programs
you write behave as expected.

A Bats test file is a Bash script with special syntax for defining
test cases. Under the hood, each test case is just a function with a
description.

```bash
#!/usr/bin/env bats

@test "addition using bc" {
  result="$(echo 2+2 | bc)"
  [ "$result" -eq 4 ]
}

@test "addition using dc" {
  result="$(echo 2 2+p | dc)"
  [ "$result" -eq 4 ]
}
```

Bats is most useful when testing software written in Bash, but you can
use it to test any UNIX program.

Test cases consist of standard shell commands. Bats makes use of
Bash's `errexit` (`set -e`) option when running test cases. If every
command in the test case exits with a `0` status code (success), the
test passes. In this way, each line is an assertion of truth.


## Running tests

To run your tests, invoke the `bats` interpreter with a path to a test
file. The file's test cases are run sequentially and in isolation. If
all the test cases pass, `bats` exits with a `0` status code. If there
are any failures, `bats` exits with a `1` status code.

When you run Bats from a terminal, you'll see output as each test is
performed, with a check-mark next to the test's name if it passes or
an "X" if it fails.

    $ bats addition.bats
     ✓ addition using bc
     ✓ addition using dc

    2 tests, 0 failures

If Bats is not connected to a terminal—in other words, if you
run it from a continuous integration system, or redirect its output to
a file—the results are displayed in human-readable, machine-parsable
[TAP format](http://testanything.org).

You can force TAP output from a terminal by invoking Bats with the
`--tap` option.

    $ bats --tap addition.bats
    1..2
    ok 1 addition using bc
    ok 2 addition using dc

### Test suites

You can invoke the `bats` interpreter with multiple test file
arguments, or with a path to a directory containing multiple `.bats`
files. Bats will run each test file individually and aggregate the
results. If any test case fails, `bats` exits with a `1` status code.


## Writing tests

Each Bats test file is evaluated _n+1_ times, where _n_ is the number of
test cases in the file. The first run counts the number of test cases,
then iterates over the test cases and executes each one in its own
process.

For more details about how Bats evaluates test files, see 
[Bats Evaluation Process](https://github.com/sstephenson/bats/wiki/Bats-Evaluation-Process)
on the wiki.

### `run`: Test other commands

Many Bats tests need to run a command and then make assertions about
its exit status and output. Bats includes a `run` helper that invokes
its arguments as a command, saves the exit status and output into
special global variables, and then returns with a `0` status code so
you can continue to make assertions in your test case.

For example, let's say you're testing that the `foo` command, when
passed a nonexistent filename, exits with a `1` status code and prints
an error message.

```bash
@test "invoking foo with a nonexistent file prints an error" {
  run foo nonexistent_filename
  [ "$status" -eq 1 ]
  [ "$output" = "foo: no such file 'nonexistent_filename'" ]
}
```

The `$status` variable contains the status code of the command, and
the `$output` variable contains the combined contents of the command's
standard output and standard error streams.

A third special variable, the `$lines` array, is available for easily
accessing individual lines of output. For example, if you want to test
that invoking `foo` without any arguments prints usage information on
the first line:

```bash
@test "invoking foo without arguments prints usage" {
  run foo
  [ "$status" -eq 1 ]
  [ "${lines[0]}" = "usage: foo <filename>" ]
}
```

### `load`: Share common code

You may want to share common code across multiple test files. Bats
includes a convenient `load` command for sourcing a Bash source file
relative to the location of the current test file. For example, if you
have a Bats test in `test/foo.bats`, the command

```bash
load test_helper
```

will source the script `test/test_helper.bash` in your test file. This
can be useful for sharing functions to set up your environment or load
fixtures.

### `skip`: Easily skip tests

Tests can be skipped by using the `skip` command at the point in a
test you wish to skip.

```bash
@test "A test I don't want to execute for now" {
  skip
  run foo
  [ "$status" -eq 0 ]
}
```

Optionally, you may include a reason for skipping:

```bash
@test "A test I don't want to execute for now" {
  skip "This command will return zero soon, but not now"
  run foo
  [ "$status" -eq 0 ]
}
```

Or you can skip conditionally:

```bash
@test "A test which should run" {
  if [ foo != bar ]; then
    skip "foo isn't bar"
  fi

  run foo
  [ "$status" -eq 0 ]
}
```

### `setup` and `teardown`: Pre- and post-test hooks

You can define special `setup` and `teardown` functions, which run
before and after each test case, respectively. Use these to load
fixtures, set up your environment, and clean up when you're done.

### Code outside of test cases

You can include code in your test file outside of `@test` functions.
For example, this may be useful if you want to check for dependencies
and fail immediately if they're not present. However, any output that
you print in code outside of `@test`, `setup` or `teardown` functions
must be redirected to `stderr` (`>&2`). Otherwise, the output may
cause Bats to fail by polluting the TAP stream on `stdout`.

### Special variables

There are several global variables you can use to introspect on Bats
tests:

* `$BATS_TEST_FILENAME` is the fully expanded path to the Bats test
file.
* `$BATS_TEST_DIRNAME` is the directory in which the Bats test file is
located.
* `$BATS_TEST_NAMES` is an array of function names for each test case.
* `$BATS_TEST_NAME` is the name of the function containing the current
test case.
* `$BATS_TEST_DESCRIPTION` is the description of the current test
case.
* `$BATS_TEST_NUMBER` is the (1-based) index of the current test case
in the test file.
* `$BATS_TMPDIR` is the location to a directory that may be used to
store temporary files.


## Installing Bats from source

Check out a copy of the Bats repository. Then, either add the Bats
`bin` directory to your `$PATH`, or run the provided `install.sh`
command with the location to the prefix in which you want to install
Bats. For example, to install Bats into `/usr/local`,

    $ git clone https://github.com/sstephenson/bats.git
    $ cd bats
    $ ./install.sh /usr/local

Note that you may need to run `install.sh` with `sudo` if you do not
have permission to write to the installation prefix.


## Support

The Bats source code repository is [hosted on
GitHub](https://github.com/sstephenson/bats). There you can file bugs
on the issue tracker or submit tested pull requests for review.

For real-world examples from open-source projects using Bats, see
[Projects Using Bats](https://github.com/sstephenson/bats/wiki/Projects-Using-Bats)
on the wiki.

To learn how to set up your editor for Bats syntax highlighting, see
[Syntax Highlighting](https://github.com/sstephenson/bats/wiki/Syntax-Highlighting)
on the wiki.


## Version history

*0.4.0* (August 13, 2014)

* Improved the display of failing test cases. Bats now shows the
  source code of failing test lines, along with full stack traces
  including function names, filenames, and line numbers.
* Improved the display of the pretty-printed test summary line to
  include the number of skipped tests, if any.
* Improved the speed of the preprocessor, dramatically shortening test
  and suite startup times.
* Added support for absolute pathnames to the `load` helper.
* Added support for single-line `@test` definitions.
* Added bats(1) and bats(7) manual pages.
* Modified the `bats` command to default to TAP output when the `$CI`
  variable is set, to better support environments such as Travis CI.

*0.3.1* (October 28, 2013)

* Fixed an incompatibility with the pretty formatter in certain
  environments such as tmux.
* Fixed a bug where the pretty formatter would crash if the first line
  of a test file's output was invalid TAP.

*0.3.0* (October 21, 2013)

* Improved formatting for tests run from a terminal. Failing tests
  are now colored in red, and the total number of failing tests is
  displayed at the end of the test run. When Bats is not connected to
  a terminal (e.g. in CI runs), or when invoked with the `--tap` flag,
  output is displayed in standard TAP format.
* Added the ability to skip tests using the `skip` command.
* Added a message to failing test case output indicating the file and
  line number of the statement that caused the test to fail.
* Added "ad-hoc" test suite support. You can now invoke `bats` with
  multiple filename or directory arguments to run all the specified
  tests in aggregate.
* Added support for test files with Windows line endings.
* Fixed regular expression warnings from certain versions of Bash.
* Fixed a bug running tests containing lines that begin with `-e`.

*0.2.0* (November 16, 2012)

* Added test suite support. The `bats` command accepts a directory
  name containing multiple test files to be run in aggregate.
* Added the ability to count the number of test cases in a file or
  suite by passing the `-c` flag to `bats`.
* Preprocessed sources are cached between test case runs in the same
  file for better performance.

*0.1.0* (December 30, 2011)

* Initial public release.

---

© 2014 Sam Stephenson. Bats is released under an MIT-style license;
see `LICENSE` for details.


================================================
FILE: install.sh
================================================
#!/usr/bin/env bash
set -e

resolve_link() {
  $(type -p greadlink readlink | head -1) "$1"
}

abs_dirname() {
  local cwd="$(pwd)"
  local path="$1"

  while [ -n "$path" ]; do
    cd "${path%/*}"
    local name="${path##*/}"
    path="$(resolve_link "$name" || true)"
  done

  pwd
  cd "$cwd"
}

PREFIX="$1"
if [ -z "$1" ]; then
  { echo "usage: $0 <prefix>"
    echo "  e.g. $0 /usr/local"
  } >&2
  exit 1
fi

BATS_ROOT="$(abs_dirname "$0")"
mkdir -p "$PREFIX"/{bin,libexec,share/man/man{1,7}}
cp -R "$BATS_ROOT"/bin/* "$PREFIX"/bin
cp -R "$BATS_ROOT"/libexec/* "$PREFIX"/libexec
cp "$BATS_ROOT"/man/bats.1 "$PREFIX"/share/man/man1
cp "$BATS_ROOT"/man/bats.7 "$PREFIX"/share/man/man7

echo "Installed Bats to $PREFIX/bin/bats"


================================================
FILE: libexec/bats
================================================
#!/usr/bin/env bash
set -e

version() {
  echo "Bats 0.4.0"
}

usage() {
  version
  echo "Usage: bats [-c] [-p | -t] <test> [<test> ...]"
}

help() {
  usage
  echo
  echo "  <test> is the path to a Bats test file, or the path to a directory"
  echo "  containing Bats test files."
  echo
  echo "  -c, --count    Count the number of test cases without running any tests"
  echo "  -h, --help     Display this help message"
  echo "  -p, --pretty   Show results in pretty format (default for terminals)"
  echo "  -t, --tap      Show results in TAP format"
  echo "  -v, --version  Display the version number"
  echo
  echo "  For more information, see https://github.com/sstephenson/bats"
  echo
}

resolve_link() {
  $(type -p greadlink readlink | head -1) "$1"
}

abs_dirname() {
  local cwd="$(pwd)"
  local path="$1"

  while [ -n "$path" ]; do
    cd "${path%/*}"
    local name="${path##*/}"
    path="$(resolve_link "$name" || true)"
  done

  pwd
  cd "$cwd"
}

expand_path() {
  { cd "$(dirname "$1")" 2>/dev/null
    local dirname="$PWD"
    cd "$OLDPWD"
    echo "$dirname/$(basename "$1")"
  } || echo "$1"
}

BATS_LIBEXEC="$(abs_dirname "$0")"
export BATS_PREFIX="$(abs_dirname "$BATS_LIBEXEC")"
export BATS_CWD="$(abs_dirname .)"
export PATH="$BATS_LIBEXEC:$PATH"

options=()
arguments=()
for arg in "$@"; do
  if [ "${arg:0:1}" = "-" ]; then
    if [ "${arg:1:1}" = "-" ]; then
      options[${#options[*]}]="${arg:2}"
    else
      index=1
      while option="${arg:$index:1}"; do
        [ -n "$option" ] || break
        options[${#options[*]}]="$option"
        let index+=1
      done
    fi
  else
    arguments[${#arguments[*]}]="$arg"
  fi
done

unset count_flag pretty
[ -t 0 ] && [ -t 1 ] && pretty="1"
[ -n "$CI" ] && pretty=""

for option in "${options[@]}"; do
  case "$option" in
  "h" | "help" )
    help
    exit 0
    ;;
  "v" | "version" )
    version
    exit 0
    ;;
  "c" | "count" )
    count_flag="-c"
    ;;
  "t" | "tap" )
    pretty=""
    ;;
  "p" | "pretty" )
    pretty="1"
    ;;
  * )
    usage >&2
    exit 1
    ;;
  esac
done

if [ "${#arguments[@]}" -eq 0 ]; then
  usage >&2
  exit 1
fi

filenames=()
for filename in "${arguments[@]}"; do
  if [ -d "$filename" ]; then
    shopt -s nullglob
    for suite_filename in "$(expand_path "$filename")"/*.bats; do
      filenames["${#filenames[@]}"]="$suite_filename"
    done
    shopt -u nullglob
  else
    filenames["${#filenames[@]}"]="$(expand_path "$filename")"
  fi
done

if [ "${#filenames[@]}" -eq 1 ]; then
  command="bats-exec-test"
else
  command="bats-exec-suite"
fi

if [ -n "$pretty" ]; then
  extended_syntax_flag="-x"
  formatter="bats-format-tap-stream"
else
  extended_syntax_flag=""
  formatter="cat"
fi

set -o pipefail execfail
exec "$command" $count_flag $extended_syntax_flag "${filenames[@]}" | "$formatter"


================================================
FILE: libexec/bats-exec-suite
================================================
#!/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"


================================================
FILE: libexec/bats-exec-test
================================================
#!/usr/bin/env bash
set -e
set -E
set -T

BATS_COUNT_ONLY=""
if [ "$1" = "-c" ]; then
  BATS_COUNT_ONLY=1
  shift
fi

BATS_EXTENDED_SYNTAX=""
if [ "$1" = "-x" ]; then
  BATS_EXTENDED_SYNTAX="$1"
  shift
fi

BATS_TEST_FILENAME="$1"
if [ -z "$BATS_TEST_FILENAME" ]; then
  echo "usage: bats-exec <filename>" >&2
  exit 1
elif [ ! -f "$BATS_TEST_FILENAME" ]; then
  echo "bats: $BATS_TEST_FILENAME does not exist" >&2
  exit 1
else
  shift
fi

BATS_TEST_DIRNAME="$(dirname "$BATS_TEST_FILENAME")"
BATS_TEST_NAMES=()

load() {
  local name="$1"
  local filename

  if [ "${name:0:1}" = "/" ]; then
    filename="${name}"
  else
    filename="$BATS_TEST_DIRNAME/${name}.bash"
  fi

  [ -f "$filename" ] || {
    echo "bats: $filename does not exist" >&2
    exit 1
  }

  source "${filename}"
}

run() {
  local e E T 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


================================================
FILE: libexec/bats-format-tap-stream
================================================
#!/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


================================================
FILE: libexec/bats-preprocess
================================================
#!/usr/bin/env bash
set -e

encode_name() {
  local name="$1"
  local result="test_"

  if [[ ! "$name" =~ [^[:alnum:]\ _-] ]]; then
    name="${name//_/-5f}"
    name="${name//-/-2d}"
    name="${name// /_}"
    result+="$name"
  else
    local length="${#name}"
    local char i

    for ((i=0; i<length; i++)); do
      char="${name:$i:1}"
      if [ "$char" = " " ]; then
        result+="_"
      elif [[ "$char" =~ [[:alnum:]] ]]; then
        result+="$char"
      else
        result+="$(printf -- "-%02x" \'"$char")"
      fi
    done
  fi

  echo "$result"
}

tests=()
index=0
pattern='^ *@test  *([^ ].*)  *\{ *(.*)$'

while IFS= read -r line; do
  let index+=1
  if [[ "$line" =~ $pattern ]]; then
    quoted_name="${BASH_REMATCH[1]}"
    body="${BASH_REMATCH[2]}"
    name="$(eval echo "$quoted_name")"
    encoded_name="$(encode_name "$name")"
    tests["${#tests[@]}"]="$encoded_name"
    echo "${encoded_name}() { bats_test_begin ${quoted_name} ${index}; ${body}"
  else
    printf "%s\n" "$line"
  fi
done

for test_name in "${tests[@]}"; do
  echo "bats_test_function ${test_name}"
done


================================================
FILE: man/Makefile
================================================
RONN := ronn
PAGES := bats.1 bats.7

all: $(PAGES)

bats.1: bats.1.ronn
	$(RONN) -r $<

bats.7: bats.7.ronn
	$(RONN) -r $<


================================================
FILE: man/README.md
================================================
Bats man pages are generated with [Ronn](http://rtomayko.github.io/ronn/).

After making changes to `bats.1.ronn` or `bats.7.ronn`, run `make` in
this directory to generate `bats.1` and `bats.7`. **Do not edit the
`bats.1` or `bats.7` files directly.**


================================================
FILE: man/bats.1
================================================
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "BATS" "1" "August 2014" "" ""
.
.SH "NAME"
\fBbats\fR \- Bash Automated Testing System
.
.SH "SYNOPSIS"
bats [\-c] [\-p | \-t] \fItest\fR [\fItest\fR \.\.\.]
.
.P
\fItest\fR is the path to a Bats test file, or the path to a directory containing Bats test files\.
.
.SH "DESCRIPTION"
Bats is a TAP\-compliant testing framework for Bash\. It provides a simple way to verify that the UNIX programs you write behave as expected\.
.
.P
A Bats test file is a Bash script with special syntax for defining test cases\. Under the hood, each test case is just a function with a description\.
.
.P
Test cases consist of standard shell commands\. Bats makes use of Bash\'s \fBerrexit\fR (\fBset \-e\fR) option when running test cases\. If every command in the test case exits with a \fB0\fR status code (success), the test passes\. In this way, each line is an assertion of truth\.
.
.P
See \fBbats\fR(7) for more information on writing Bats tests\.
.
.SH "RUNNING TESTS"
To run your tests, invoke the \fBbats\fR interpreter with a path to a test file\. The file\'s test cases are run sequentially and in isolation\. If all the test cases pass, \fBbats\fR exits with a \fB0\fR status code\. If there are any failures, \fBbats\fR exits with a \fB1\fR status code\.
.
.P
You can invoke the \fBbats\fR interpreter with multiple test file arguments, or with a path to a directory containing multiple \fB\.bats\fR files\. Bats will run each test file individually and aggregate the results\. If any test case fails, \fBbats\fR exits with a \fB1\fR status code\.
.
.SH "OPTIONS"
.
.TP
\fB\-c\fR, \fB\-\-count\fR
Count the number of test cases without running any tests
.
.TP
\fB\-h\fR, \fB\-\-help\fR
Display help message
.
.TP
\fB\-p\fR, \fB\-\-pretty\fR
Show results in pretty format (default for terminals)
.
.TP
\fB\-t\fR, \fB\-\-tap\fR
Show results in TAP format
.
.TP
\fB\-v\fR, \fB\-\-version\fR
Display the version number
.
.SH "OUTPUT"
When you run Bats from a terminal, you\'ll see output as each test is performed, with a check\-mark next to the test\'s name if it passes or an "X" if it fails\.
.
.IP "" 4
.
.nf

$ bats addition\.bats
 ✓ addition using bc
 ✓ addition using dc

2 tests, 0 failures
.
.fi
.
.IP "" 0
.
.P
If Bats is not connected to a terminal\-\-in other words, if you run it from a continuous integration system or redirect its output to a file\-\-the results are displayed in human\-readable, machine\-parsable TAP format\. You can force TAP output from a terminal by invoking Bats with the \fB\-\-tap\fR option\.
.
.IP "" 4
.
.nf

$ bats \-\-tap addition\.bats
1\.\.2
ok 1 addition using bc
ok 2 addition using dc
.
.fi
.
.IP "" 0
.
.SH "EXIT STATUS"
The \fBbats\fR interpreter exits with a value of \fB0\fR if all test cases pass, or \fB1\fR if one or more test cases fail\.
.
.SH "SEE ALSO"
Bats wiki: \fIhttps://github\.com/sstephenson/bats/wiki/\fR
.
.P
\fBbash\fR(1), \fBbats\fR(7)
.
.SH "COPYRIGHT"
(c) 2014 Sam Stephenson
.
.P
Bats is released under the terms of an MIT\-style license\.


================================================
FILE: man/bats.1.ronn
================================================
bats(1) -- Bash Automated Testing System
========================================


SYNOPSIS
--------

bats [-c] [-p | -t] <test> [<test> ...]

<test> is the path to a Bats test file, or the path to a directory
containing Bats test files.


DESCRIPTION
-----------

Bats is a TAP-compliant testing framework for Bash. It provides a simple
way to verify that the UNIX programs you write behave as expected.

A Bats test file is a Bash script with special syntax for defining
test cases. Under the hood, each test case is just a function with a
description.

Test cases consist of standard shell commands. Bats makes use of
Bash's `errexit` (`set -e`) option when running test cases. If every
command in the test case exits with a `0` status code (success), the
test passes. In this way, each line is an assertion of truth.

See `bats`(7) for more information on writing Bats tests.


RUNNING TESTS
-------------

To run your tests, invoke the `bats` interpreter with a path to a test
file. The file's test cases are run sequentially and in isolation. If
all the test cases pass, `bats` exits with a `0` status code. If there
are any failures, `bats` exits with a `1` status code.

You can invoke the `bats` interpreter with multiple test file arguments,
or with a path to a directory containing multiple `.bats` files. Bats
will run each test file individually and aggregate the results. If any
test case fails, `bats` exits with a `1` status code.


OPTIONS
-------

  * `-c`, `--count`:
    Count the number of test cases without running any tests
  * `-h`, `--help`:
    Display help message
  * `-p`, `--pretty`:
    Show results in pretty format (default for terminals)
  * `-t`, `--tap`:
    Show results in TAP format
  * `-v`, `--version`:
    Display the version number


OUTPUT
------

When you run Bats from a terminal, you'll see output as each test is
performed, with a check-mark next to the test's name if it passes or
an "X" if it fails.

    $ bats addition.bats
     ✓ addition using bc
     ✓ addition using dc

    2 tests, 0 failures

If Bats is not connected to a terminal--in other words, if you run it
from a continuous integration system or redirect its output to a
file--the results are displayed in human-readable, machine-parsable
TAP format. You can force TAP output from a terminal by invoking Bats
with the `--tap` option.

    $ bats --tap addition.bats
    1..2
    ok 1 addition using bc
    ok 2 addition using dc


EXIT STATUS
-----------

The `bats` interpreter exits with a value of `0` if all test cases pass,
or `1` if one or more test cases fail.


SEE ALSO
--------

Bats wiki: _https://github.com/sstephenson/bats/wiki/_

`bash`(1), `bats`(7)


COPYRIGHT
---------

(c) 2014 Sam Stephenson

Bats is released under the terms of an MIT-style license.





================================================
FILE: man/bats.7
================================================
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "BATS" "7" "November 2013" "" ""
.
.SH "NAME"
\fBbats\fR \- Bats test file format
.
.SH "DESCRIPTION"
A Bats test file is a Bash script with special syntax for defining test cases\. Under the hood, each test case is just a function with a description\.
.
.IP "" 4
.
.nf

#!/usr/bin/env bats

@test "addition using bc" {
  result="$(echo 2+2 | bc)"
  [ "$result" \-eq 4 ]
}

@test "addition using dc" {
  result="$(echo 2 2+p | dc)"
  [ "$result" \-eq 4 ]
}
.
.fi
.
.IP "" 0
.
.P
Each Bats test file is evaluated n+1 times, where \fIn\fR is the number of test cases in the file\. The first run counts the number of test cases, then iterates over the test cases and executes each one in its own process\.
.
.SH "THE RUN HELPER"
Many Bats tests need to run a command and then make assertions about its exit status and output\. Bats includes a \fBrun\fR helper that invokes its arguments as a command, saves the exit status and output into special global variables, and then returns with a \fB0\fR status code so you can continue to make assertions in your test case\.
.
.P
For example, let\'s say you\'re testing that the \fBfoo\fR command, when passed a nonexistent filename, exits with a \fB1\fR status code and prints an error message\.
.
.IP "" 4
.
.nf

@test "invoking foo with a nonexistent file prints an error" {
  run foo nonexistent_filename
  [ "$status" \-eq 1 ]
  [ "$output" = "foo: no such file \'nonexistent_filename\'" ]
}
.
.fi
.
.IP "" 0
.
.P
The \fB$status\fR variable contains the status code of the command, and the \fB$output\fR variable contains the combined contents of the command\'s standard output and standard error streams\.
.
.P
A third special variable, the \fB$lines\fR array, is available for easily accessing individual lines of output\. For example, if you want to test that invoking \fBfoo\fR without any arguments prints usage information on the first line:
.
.IP "" 4
.
.nf

@test "invoking foo without arguments prints usage" {
  run foo
  [ "$status" \-eq 1 ]
  [ "${lines[0]}" = "usage: foo <filename>" ]
}
.
.fi
.
.IP "" 0
.
.SH "THE LOAD COMMAND"
You may want to share common code across multiple test files\. Bats includes a convenient \fBload\fR command for sourcing a Bash source file relative to the location of the current test file\. For example, if you have a Bats test in \fBtest/foo\.bats\fR, the command
.
.IP "" 4
.
.nf

load test_helper
.
.fi
.
.IP "" 0
.
.P
will source the script \fBtest/test_helper\.bash\fR in your test file\. This can be useful for sharing functions to set up your environment or load fixtures\.
.
.SH "THE SKIP COMMAND"
Tests can be skipped by using the \fBskip\fR command at the point in a test you wish to skip\.
.
.IP "" 4
.
.nf

@test "A test I don\'t want to execute for now" {
  skip
  run foo
  [ "$status" \-eq 0 ]
}
.
.fi
.
.IP "" 0
.
.P
Optionally, you may include a reason for skipping:
.
.IP "" 4
.
.nf

@test "A test I don\'t want to execute for now" {
  skip "This command will return zero soon, but not now"
  run foo
  [ "$status" \-eq 0 ]
}
.
.fi
.
.IP "" 0
.
.P
Or you can skip conditionally:
.
.IP "" 4
.
.nf

@test "A test which should run" {
  if [ foo != bar ]; then
    skip "foo isn\'t bar"
  fi

  run foo
  [ "$status" \-eq 0 ]
}
.
.fi
.
.IP "" 0
.
.SH "SETUP AND TEARDOWN FUNCTIONS"
You can define special \fBsetup\fR and \fBteardown\fR functions which run before and after each test case, respectively\. Use these to load fixtures, set up your environment, and clean up when you\'re done\.
.
.SH "CODE OUTSIDE OF TEST CASES"
You can include code in your test file outside of \fB@test\fR functions\. For example, this may be useful if you want to check for dependencies and fail immediately if they\'re not present\. However, any output that you print in code outside of \fB@test\fR, \fBsetup\fR or \fBteardown\fR functions must be redirected to \fBstderr\fR (\fB>&2\fR)\. Otherwise, the output may cause Bats to fail by polluting the TAP stream on \fBstdout\fR\.
.
.SH "SPECIAL VARIABLES"
There are several global variables you can use to introspect on Bats tests:
.
.IP "\(bu" 4
\fB$BATS_TEST_FILENAME\fR is the fully expanded path to the Bats test file\.
.
.IP "\(bu" 4
\fB$BATS_TEST_DIRNAME\fR is the directory in which the Bats test file is located\.
.
.IP "\(bu" 4
\fB$BATS_TEST_NAMES\fR is an array of function names for each test case\.
.
.IP "\(bu" 4
\fB$BATS_TEST_NAME\fR is the name of the function containing the current test case\.
.
.IP "\(bu" 4
\fB$BATS_TEST_DESCRIPTION\fR is the description of the current test case\.
.
.IP "\(bu" 4
\fB$BATS_TEST_NUMBER\fR is the (1\-based) index of the current test case in the test file\.
.
.IP "\(bu" 4
\fB$BATS_TMPDIR\fR is the location to a directory that may be used to store temporary files\.
.
.IP "" 0
.
.SH "SEE ALSO"
\fBbash\fR(1), \fBbats\fR(1)


================================================
FILE: man/bats.7.ronn
================================================
bats(7) -- Bats test file format
================================


DESCRIPTION
-----------

A Bats test file is a Bash script with special syntax for defining
test cases. Under the hood, each test case is just a function with a
description.

    #!/usr/bin/env bats

    @test "addition using bc" {
      result="$(echo 2+2 | bc)"
      [ "$result" -eq 4 ]
    }

    @test "addition using dc" {
      result="$(echo 2 2+p | dc)"
      [ "$result" -eq 4 ]
    }


Each Bats test file is evaluated n+1 times, where _n_ is the number of
test cases in the file. The first run counts the number of test cases,
then iterates over the test cases and executes each one in its own
process.


THE RUN HELPER
--------------

Many Bats tests need to run a command and then make assertions about
its exit status and output. Bats includes a `run` helper that invokes
its arguments as a command, saves the exit status and output into
special global variables, and then returns with a `0` status code so
you can continue to make assertions in your test case.

For example, let's say you're testing that the `foo` command, when
passed a nonexistent filename, exits with a `1` status code and prints
an error message.

    @test "invoking foo with a nonexistent file prints an error" {
      run foo nonexistent_filename
      [ "$status" -eq 1 ]
      [ "$output" = "foo: no such file 'nonexistent_filename'" ]
    }

The `$status` variable contains the status code of the command, and
the `$output` variable contains the combined contents of the command's
standard output and standard error streams.

A third special variable, the `$lines` array, is available for easily
accessing individual lines of output. For example, if you want to test
that invoking `foo` without any arguments prints usage information on
the first line:

    @test "invoking foo without arguments prints usage" {
      run foo
      [ "$status" -eq 1 ]
      [ "${lines[0]}" = "usage: foo <filename>" ]
    }


THE LOAD COMMAND
----------------

You may want to share common code across multiple test files. Bats
includes a convenient `load` command for sourcing a Bash source file
relative to the location of the current test file. For example, if you
have a Bats test in `test/foo.bats`, the command

    load test_helper

will source the script `test/test_helper.bash` in your test file. This
can be useful for sharing functions to set up your environment or load
fixtures.


THE SKIP COMMAND
----------------

Tests can be skipped by using the `skip` command at the point in a
test you wish to skip.

    @test "A test I don't want to execute for now" {
      skip
      run foo
      [ "$status" -eq 0 ]
    }

Optionally, you may include a reason for skipping:

    @test "A test I don't want to execute for now" {
      skip "This command will return zero soon, but not now"
      run foo
      [ "$status" -eq 0 ]
    }

Or you can skip conditionally:

    @test "A test which should run" {
      if [ foo != bar ]; then
        skip "foo isn't bar"
      fi

      run foo
      [ "$status" -eq 0 ]
    }


SETUP AND TEARDOWN FUNCTIONS
----------------------------

You can define special `setup` and `teardown` functions which run
before and after each test case, respectively. Use these to load
fixtures, set up your environment, and clean up when you're done.


CODE OUTSIDE OF TEST CASES
--------------------------

You can include code in your test file outside of `@test` functions.
For example, this may be useful if you want to check for dependencies
and fail immediately if they're not present. However, any output that
you print in code outside of `@test`, `setup` or `teardown` functions
must be redirected to `stderr` (`>&2`). Otherwise, the output may
cause Bats to fail by polluting the TAP stream on `stdout`.


SPECIAL VARIABLES
-----------------

There are several global variables you can use to introspect on Bats
tests:

* `$BATS_TEST_FILENAME` is the fully expanded path to the Bats test
file.
* `$BATS_TEST_DIRNAME` is the directory in which the Bats test file is
located.
* `$BATS_TEST_NAMES` is an array of function names for each test case.
* `$BATS_TEST_NAME` is the name of the function containing the current
test case.
* `$BATS_TEST_DESCRIPTION` is the description of the current test
case.
* `$BATS_TEST_NUMBER` is the (1-based) index of the current test case
in the test file.
* `$BATS_TMPDIR` is the location to a directory that may be used to
store temporary files.


SEE ALSO
--------

`bash`(1), `bats`(1)


================================================
FILE: package.json
================================================
{
  "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" ]
}



================================================
FILE: test/bats.bats
================================================
#!/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" ]
}


================================================
FILE: test/fixtures/bats/dos_line.bats
================================================
@test "foo" {

  echo "foo"

}



================================================
FILE: test/fixtures/bats/empty.bats
================================================


================================================
FILE: test/fixtures/bats/environment.bats
================================================
@test "setting a variable" {
  variable=1
  [ $variable -eq 1 ]
}

@test "variables do not persist across tests" {
  [ -z "$variable" ]
}


================================================
FILE: test/fixtures/bats/failing.bats
================================================
@test "a failing test" {
  true
  true
  eval "( exit ${STATUS:-1} )"
}


================================================
FILE: test/fixtures/bats/failing_and_passing.bats
================================================
@test "a failing test" {
  false
}

@test "a passing test" {
  true
}


================================================
FILE: test/fixtures/bats/failing_helper.bats
================================================
load "test_helper"

@test "failing helper function" {
  true
  failing_helper
}


================================================
FILE: test/fixtures/bats/failing_setup.bats
================================================
setup() {
  false
}

@test "truth" {
  true
}


================================================
FILE: test/fixtures/bats/failing_teardown.bats
================================================
teardown() {
  eval "( exit ${STATUS:-1} )"
}

@test "truth" {
  [ "$PASS" = "1" ]
}


================================================
FILE: test/fixtures/bats/intact.bats
================================================
@test "dash-e on beginning of line" {
  run cat - <<INPUT
-e
INPUT
  test "$output" = "-e"
}


================================================
FILE: test/fixtures/bats/invalid_tap.bats
================================================
echo "This isn't TAP!"
echo "Good day to you"
exit 1

@test "truth" {
  true
}


================================================
FILE: test/fixtures/bats/load.bats
================================================
[ -n "$HELPER_NAME" ] || HELPER_NAME="test_helper"
load "$HELPER_NAME"

@test "calling a loaded helper" {
  help_me
}


================================================
FILE: test/fixtures/bats/loop_keep_IFS.bats
================================================
# see issue #89
loop_func() {
  local search="none one two tree"
  local d

  for d in $search ; do
    echo $d
  done
}

@test "loop_func" {
  run loop_func
  [[ "${lines[3]}" == 'tree' ]]
  run loop_func
  [[ "${lines[2]}" == 'two' ]]
}


================================================
FILE: test/fixtures/bats/output.bats
================================================
@test "success writing to stdout" {
  echo "success stdout 1"
  echo "success stdout 2"
}

@test "success writing to stderr" {
  echo "success stderr" >&2
}

@test "failure writing to stdout" {
  echo "failure stdout 1"
  echo "failure stdout 2"
  false
}

@test "failure writing to stderr" {
  echo "failure stderr" >&2
  false
}


================================================
FILE: test/fixtures/bats/passing.bats
================================================
@test "a passing test" {
  true
}


================================================
FILE: test/fixtures/bats/passing_and_failing.bats
================================================
@test "a passing test" {
  true
}

@test "a failing test" {
  false
}


================================================
FILE: test/fixtures/bats/passing_and_skipping.bats
================================================
@test "a passing test" {
  true
}

@test "a skipping test" {
  skip
}


================================================
FILE: test/fixtures/bats/passing_failing_and_skipping.bats
================================================
@test "a passing test" {
  true
}

@test "a skipping test" {
  skip
}

@test "a failing test" {
  false
}


================================================
FILE: test/fixtures/bats/setup.bats
================================================
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" ]
}


================================================
FILE: test/fixtures/bats/single_line.bats
================================================
@test "empty" { }

@test "passing" { true; }

@test "input redirection" { diff - <( echo hello ); } <<EOS
hello
EOS

@test "failing" { false; }


================================================
FILE: test/fixtures/bats/skipped.bats
================================================
@test "a skipped test" {
  skip
}

@test "a skipped test with a reason" {
  skip "a reason"
}


================================================
FILE: test/fixtures/bats/teardown.bats
================================================
LOG="$TMP/teardown.log"

teardown() {
  echo "$BATS_TEST_NAME" >> "$LOG"
}

@test "one" {
  true
}

@test "two" {
  false
}

@test "three" {
  true
}


================================================
FILE: test/fixtures/bats/test_helper.bash
================================================
help_me() {
  true
}

failing_helper() {
  false
}


================================================
FILE: test/fixtures/bats/without_trailing_newline.bats
================================================
@test "truth" {
  true
}

================================================
FILE: test/fixtures/suite/empty/.gitkeep
================================================


================================================
FILE: test/fixtures/suite/multiple/a.bats
================================================
@test "truth" {
  true
}


================================================
FILE: test/fixtures/suite/multiple/b.bats
================================================
@test "more truth" {
  true
}

@test "quasi-truth" {
  [ -z "$FLUNK" ]
}


================================================
FILE: test/fixtures/suite/single/test.bats
================================================
@test "a passing test" {
  true
}


================================================
FILE: test/suite.bats
================================================
#!/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" ]
}


================================================
FILE: test/test_helper.bash
================================================
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"/*
}
Download .txt
gitextract_ytbcl905/

├── .gitattributes
├── .travis.yml
├── CONDUCT.md
├── LICENSE
├── README.md
├── install.sh
├── libexec/
│   ├── bats
│   ├── bats-exec-suite
│   ├── bats-exec-test
│   ├── bats-format-tap-stream
│   └── bats-preprocess
├── man/
│   ├── Makefile
│   ├── README.md
│   ├── bats.1
│   ├── bats.1.ronn
│   ├── bats.7
│   └── bats.7.ronn
├── package.json
└── test/
    ├── bats.bats
    ├── fixtures/
    │   ├── bats/
    │   │   ├── dos_line.bats
    │   │   ├── empty.bats
    │   │   ├── environment.bats
    │   │   ├── failing.bats
    │   │   ├── failing_and_passing.bats
    │   │   ├── failing_helper.bats
    │   │   ├── failing_setup.bats
    │   │   ├── failing_teardown.bats
    │   │   ├── intact.bats
    │   │   ├── invalid_tap.bats
    │   │   ├── load.bats
    │   │   ├── loop_keep_IFS.bats
    │   │   ├── output.bats
    │   │   ├── passing.bats
    │   │   ├── passing_and_failing.bats
    │   │   ├── passing_and_skipping.bats
    │   │   ├── passing_failing_and_skipping.bats
    │   │   ├── setup.bats
    │   │   ├── single_line.bats
    │   │   ├── skipped.bats
    │   │   ├── teardown.bats
    │   │   ├── test_helper.bash
    │   │   └── without_trailing_newline.bats
    │   └── suite/
    │       ├── empty/
    │       │   └── .gitkeep
    │       ├── multiple/
    │       │   ├── a.bats
    │       │   └── b.bats
    │       └── single/
    │           └── test.bats
    ├── suite.bats
    └── test_helper.bash
Condensed preview — 48 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (65K chars).
[
  {
    "path": ".gitattributes",
    "chars": 41,
    "preview": "* text=auto\n*.sh eol=lf\nlibexec/* eol=lf\n"
  },
  {
    "path": ".travis.yml",
    "chars": 86,
    "preview": "language: c\nscript: bin/bats --tap test\nnotifications:\n  email:\n    on_success: never\n"
  },
  {
    "path": "CONDUCT.md",
    "chars": 3299,
    "preview": "# Contributor Covenant Code of Conduct\n\n## Our Pledge\n\nIn the interest of fostering an open and welcoming environment, w"
  },
  {
    "path": "LICENSE",
    "chars": 1058,
    "preview": "Copyright (c) 2014 Sam Stephenson\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this "
  },
  {
    "path": "README.md",
    "chars": 9710,
    "preview": "# Bats: Bash Automated Testing System\n\nBats is a [TAP](http://testanything.org)-compliant testing framework\nfor Bash. It"
  },
  {
    "path": "install.sh",
    "chars": 732,
    "preview": "#!/usr/bin/env bash\nset -e\n\nresolve_link() {\n  $(type -p greadlink readlink | head -1) \"$1\"\n}\n\nabs_dirname() {\n  local c"
  },
  {
    "path": "libexec/bats",
    "chars": 2832,
    "preview": "#!/usr/bin/env bash\nset -e\n\nversion() {\n  echo \"Bats 0.4.0\"\n}\n\nusage() {\n  version\n  echo \"Usage: bats [-c] [-p | -t] <t"
  },
  {
    "path": "libexec/bats-exec-suite",
    "chars": 1001,
    "preview": "#!/usr/bin/env bash\nset -e\n\ncount_only_flag=\"\"\nif [ \"$1\" = \"-c\" ]; then\n  count_only_flag=1\n  shift\nfi\n\nextended_syntax_"
  },
  {
    "path": "libexec/bats-exec-test",
    "chars": 7260,
    "preview": "#!/usr/bin/env bash\nset -e\nset -E\nset -T\n\nBATS_COUNT_ONLY=\"\"\nif [ \"$1\" = \"-c\" ]; then\n  BATS_COUNT_ONLY=1\n  shift\nfi\n\nBA"
  },
  {
    "path": "libexec/bats-format-tap-stream",
    "chars": 2718,
    "preview": "#!/usr/bin/env bash\nset -e\n\n# Just stream the TAP output (sans extended syntax) if tput is missing\ncommand -v tput >/dev"
  },
  {
    "path": "libexec/bats-preprocess",
    "chars": 1105,
    "preview": "#!/usr/bin/env bash\nset -e\n\nencode_name() {\n  local name=\"$1\"\n  local result=\"test_\"\n\n  if [[ ! \"$name\" =~ [^[:alnum:]\\ "
  },
  {
    "path": "man/Makefile",
    "chars": 123,
    "preview": "RONN := ronn\nPAGES := bats.1 bats.7\n\nall: $(PAGES)\n\nbats.1: bats.1.ronn\n\t$(RONN) -r $<\n\nbats.7: bats.7.ronn\n\t$(RONN) -r "
  },
  {
    "path": "man/README.md",
    "chars": 253,
    "preview": "Bats man pages are generated with [Ronn](http://rtomayko.github.io/ronn/).\n\nAfter making changes to `bats.1.ronn` or `ba"
  },
  {
    "path": "man/bats.1",
    "chars": 3092,
    "preview": ".\\\" generated with Ronn/v0.7.3\n.\\\" http://github.com/rtomayko/ronn/tree/0.7.3\n.\n.TH \"BATS\" \"1\" \"August 2014\" \"\" \"\"\n.\n.SH"
  },
  {
    "path": "man/bats.1.ronn",
    "chars": 2794,
    "preview": "bats(1) -- Bash Automated Testing System\n========================================\n\n\nSYNOPSIS\n--------\n\nbats [-c] [-p | -"
  },
  {
    "path": "man/bats.7",
    "chars": 4895,
    "preview": ".\\\" generated with Ronn/v0.7.3\n.\\\" http://github.com/rtomayko/ronn/tree/0.7.3\n.\n.TH \"BATS\" \"7\" \"November 2013\" \"\" \"\"\n.\n."
  },
  {
    "path": "man/bats.7.ronn",
    "chars": 4510,
    "preview": "bats(7) -- Bats test file format\n================================\n\n\nDESCRIPTION\n-----------\n\nA Bats test file is a Bash "
  },
  {
    "path": "package.json",
    "chars": 305,
    "preview": "{\n  \"name\": \"bats\",\n  \"version\": \"v0.4.0\",\n  \"description\": \"Bash Automated Testing System\",\n  \"install\": \"./install.sh "
  },
  {
    "path": "test/bats.bats",
    "chars": 7949,
    "preview": "#!/usr/bin/env bats\n\nload test_helper\nfixtures bats\n\n@test \"no arguments prints usage instructions\" {\n  run bats\n  [ $st"
  },
  {
    "path": "test/fixtures/bats/dos_line.bats",
    "chars": 35,
    "preview": "@test \"foo\" {\r\r\n  echo \"foo\"\r\r\n}\r\r\n"
  },
  {
    "path": "test/fixtures/bats/empty.bats",
    "chars": 0,
    "preview": ""
  },
  {
    "path": "test/fixtures/bats/environment.bats",
    "chars": 138,
    "preview": "@test \"setting a variable\" {\n  variable=1\n  [ $variable -eq 1 ]\n}\n\n@test \"variables do not persist across tests\" {\n  [ -"
  },
  {
    "path": "test/fixtures/bats/failing.bats",
    "chars": 72,
    "preview": "@test \"a failing test\" {\n  true\n  true\n  eval \"( exit ${STATUS:-1} )\"\n}\n"
  },
  {
    "path": "test/fixtures/bats/failing_and_passing.bats",
    "chars": 70,
    "preview": "@test \"a failing test\" {\n  false\n}\n\n@test \"a passing test\" {\n  true\n}\n"
  },
  {
    "path": "test/fixtures/bats/failing_helper.bats",
    "chars": 80,
    "preview": "load \"test_helper\"\n\n@test \"failing helper function\" {\n  true\n  failing_helper\n}\n"
  },
  {
    "path": "test/fixtures/bats/failing_setup.bats",
    "chars": 46,
    "preview": "setup() {\n  false\n}\n\n@test \"truth\" {\n  true\n}\n"
  },
  {
    "path": "test/fixtures/bats/failing_teardown.bats",
    "chars": 85,
    "preview": "teardown() {\n  eval \"( exit ${STATUS:-1} )\"\n}\n\n@test \"truth\" {\n  [ \"$PASS\" = \"1\" ]\n}\n"
  },
  {
    "path": "test/fixtures/bats/intact.bats",
    "chars": 93,
    "preview": "@test \"dash-e on beginning of line\" {\n  run cat - <<INPUT\n-e\nINPUT\n  test \"$output\" = \"-e\"\n}\n"
  },
  {
    "path": "test/fixtures/bats/invalid_tap.bats",
    "chars": 79,
    "preview": "echo \"This isn't TAP!\"\necho \"Good day to you\"\nexit 1\n\n@test \"truth\" {\n  true\n}\n"
  },
  {
    "path": "test/fixtures/bats/load.bats",
    "chars": 118,
    "preview": "[ -n \"$HELPER_NAME\" ] || HELPER_NAME=\"test_helper\"\nload \"$HELPER_NAME\"\n\n@test \"calling a loaded helper\" {\n  help_me\n}\n"
  },
  {
    "path": "test/fixtures/bats/loop_keep_IFS.bats",
    "chars": 239,
    "preview": "# see issue #89\nloop_func() {\n  local search=\"none one two tree\"\n  local d\n\n  for d in $search ; do\n    echo $d\n  done\n}"
  },
  {
    "path": "test/fixtures/bats/output.bats",
    "chars": 331,
    "preview": "@test \"success writing to stdout\" {\n  echo \"success stdout 1\"\n  echo \"success stdout 2\"\n}\n\n@test \"success writing to std"
  },
  {
    "path": "test/fixtures/bats/passing.bats",
    "chars": 34,
    "preview": "@test \"a passing test\" {\n  true\n}\n"
  },
  {
    "path": "test/fixtures/bats/passing_and_failing.bats",
    "chars": 70,
    "preview": "@test \"a passing test\" {\n  true\n}\n\n@test \"a failing test\" {\n  false\n}\n"
  },
  {
    "path": "test/fixtures/bats/passing_and_skipping.bats",
    "chars": 70,
    "preview": "@test \"a passing test\" {\n  true\n}\n\n@test \"a skipping test\" {\n  skip\n}\n"
  },
  {
    "path": "test/fixtures/bats/passing_failing_and_skipping.bats",
    "chars": 106,
    "preview": "@test \"a passing test\" {\n  true\n}\n\n@test \"a skipping test\" {\n  skip\n}\n\n@test \"a failing test\" {\n  false\n}\n"
  },
  {
    "path": "test/fixtures/bats/setup.bats",
    "chars": 247,
    "preview": "LOG=\"$TMP/setup.log\"\n\nsetup() {\n  echo \"$BATS_TEST_NAME\" >> \"$LOG\"\n}\n\n@test \"one\" {\n  [ \"$(tail -n 1 \"$LOG\")\" = \"test_on"
  },
  {
    "path": "test/fixtures/bats/single_line.bats",
    "chars": 144,
    "preview": "@test \"empty\" { }\n\n@test \"passing\" { true; }\n\n@test \"input redirection\" { diff - <( echo hello ); } <<EOS\nhello\nEOS\n\n@te"
  },
  {
    "path": "test/fixtures/bats/skipped.bats",
    "chars": 94,
    "preview": "@test \"a skipped test\" {\n  skip\n}\n\n@test \"a skipped test with a reason\" {\n  skip \"a reason\"\n}\n"
  },
  {
    "path": "test/fixtures/bats/teardown.bats",
    "chars": 150,
    "preview": "LOG=\"$TMP/teardown.log\"\n\nteardown() {\n  echo \"$BATS_TEST_NAME\" >> \"$LOG\"\n}\n\n@test \"one\" {\n  true\n}\n\n@test \"two\" {\n  fals"
  },
  {
    "path": "test/fixtures/bats/test_helper.bash",
    "chars": 51,
    "preview": "help_me() {\n  true\n}\n\nfailing_helper() {\n  false\n}\n"
  },
  {
    "path": "test/fixtures/bats/without_trailing_newline.bats",
    "chars": 24,
    "preview": "@test \"truth\" {\n  true\n}"
  },
  {
    "path": "test/fixtures/suite/empty/.gitkeep",
    "chars": 0,
    "preview": ""
  },
  {
    "path": "test/fixtures/suite/multiple/a.bats",
    "chars": 25,
    "preview": "@test \"truth\" {\n  true\n}\n"
  },
  {
    "path": "test/fixtures/suite/multiple/b.bats",
    "chars": 73,
    "preview": "@test \"more truth\" {\n  true\n}\n\n@test \"quasi-truth\" {\n  [ -z \"$FLUNK\" ]\n}\n"
  },
  {
    "path": "test/fixtures/suite/single/test.bats",
    "chars": 34,
    "preview": "@test \"a passing test\" {\n  true\n}\n"
  },
  {
    "path": "test/suite.bats",
    "chars": 1751,
    "preview": "#!/usr/bin/env bats\n\nload test_helper\nfixtures suite\n\n@test \"running a suite with no test files\" {\n  run bats \"$FIXTURE_"
  },
  {
    "path": "test/test_helper.bash",
    "chars": 304,
    "preview": "fixtures() {\n  FIXTURE_ROOT=\"$BATS_TEST_DIRNAME/fixtures/$1\"\n  RELATIVE_FIXTURE_ROOT=\"$(bats_trim_filename \"$FIXTURE_ROO"
  }
]

About this extraction

This page contains the full source code of the sstephenson/bats GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 48 files (57.0 KB), approximately 18.5k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!