mirror of
https://github.com/sstephenson/bats.git
synced 2024-11-17 19:52:37 +01:00
Merge branch 'master' into rojkov-fix-head-util
This commit is contained in:
commit
f953d774b7
15
.appveyor.yml
Normal file
15
.appveyor.yml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
version: 'v0.4.0.{build}'
|
||||||
|
|
||||||
|
build: off
|
||||||
|
|
||||||
|
# This presumes that Git bash is installed at `C:\Program Files\Git` and the
|
||||||
|
# bash we're using is `C:\Program Files\Git\bin\bash.exe`.
|
||||||
|
#
|
||||||
|
# If instead it finds the Windows Subsystem for Linux bash at
|
||||||
|
# `C:\Windows\System32\bash.exe`, it will fail with an error like:
|
||||||
|
# /mnt/c/.../bats-core/test/test_helper.bash: line 1:
|
||||||
|
# syntax error near unexpected token `$'{\r''
|
||||||
|
test_script:
|
||||||
|
- where bash
|
||||||
|
- bash --version
|
||||||
|
- bash -c 'time libexec/bats test'
|
10
.travis.yml
10
.travis.yml
|
@ -1,5 +1,11 @@
|
||||||
language: c
|
language: bash
|
||||||
script: bin/bats --tap test
|
os:
|
||||||
|
- linux
|
||||||
|
- osx
|
||||||
|
|
||||||
|
script:
|
||||||
|
- bash -c 'time bin/bats --tap test'
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
email:
|
email:
|
||||||
on_success: never
|
on_success: never
|
||||||
|
|
|
@ -67,6 +67,11 @@ members of the project's leadership.
|
||||||
|
|
||||||
## Project Maintainers
|
## Project Maintainers
|
||||||
|
|
||||||
|
### bats-core organization:
|
||||||
|
* Bianca Tamayo <<hi@biancatamayo.me>>
|
||||||
|
|
||||||
|
|
||||||
|
## Project Original Author(s)
|
||||||
* Sam Stephenson <<sstephenson@gmail.com>>
|
* Sam Stephenson <<sstephenson@gmail.com>>
|
||||||
|
|
||||||
## Attribution
|
## Attribution
|
||||||
|
|
21
LICENSE
21
LICENSE
|
@ -1,3 +1,24 @@
|
||||||
|
Copyright (c) 2017 Bianca Tamayo and bats-core organization
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
Copyright (c) 2014 Sam Stephenson
|
Copyright (c) 2014 Sam Stephenson
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
|
49
README.md
49
README.md
|
@ -1,3 +1,34 @@
|
||||||
|
## BATS-core: Bash Automated Testing System (2017)
|
||||||
|
|
||||||
|
[![Build Status](https://travis-ci.org/bats-core/bats-core.svg?branch=master)](https://travis-ci.org/bats-core/bats-core)
|
||||||
|
|
||||||
|
### Background:
|
||||||
|
### What is this repo?
|
||||||
|
**Tuesday, September 19, 2017:** This is a mirrored fork of [bats](https://github.com/sstephenson/bats), at [0360811](https://github.com/sstephenson/bats/commit/03608115df2071fff4eaaff1605768c275e5f81f). It was created via `git clone --bare` and `git push --mirror`.
|
||||||
|
|
||||||
|
#### Why was it created?
|
||||||
|
The original bats repository needed new maintainers, and has not been actively maintained since 2013. While there were volunteers for maintainers, attempts to organize issues, and outstanding PRs, the lack of write-access to the repo hindered progress severely.
|
||||||
|
|
||||||
|
## What's the plan and why?
|
||||||
|
The rough plan, originally [outlined here](https://github.com/sstephenson/bats/issues/150#issuecomment-323845404) is to create a new, mirrored mainline (this repo!). An excerpt:
|
||||||
|
|
||||||
|
> **1. Roadmap 1.0:**
|
||||||
|
> There are already existing high-quality PRs, and often-requested features and issues, especially here at [#196](https://github.com/sstephenson/bats/issues/196). Leverage these and **consolidate into a single roadmap**.
|
||||||
|
>
|
||||||
|
>**2. Create or choose a fork or *mirror* of this repo to use as the new mainline:**
|
||||||
|
>Repoint existing PRs (whichever ones are possible) to the new mainline, get that repo to a stable 1.0. IMO we should create an organization and grant 2-3 people admin and write access.
|
||||||
|
>
|
||||||
|
|
||||||
|
Doing it this way accomplishes two things:
|
||||||
|
1. Removes the dependency on the original maintainer
|
||||||
|
2. Enables collaboration and contribution flow again
|
||||||
|
3. Allows the possibility of merging back to original, or merging from original if or when the need arises
|
||||||
|
4. Prevents lock-out by giving administrative access to more than one person, increases transferability
|
||||||
|
|
||||||
|
## Misc
|
||||||
|
- We are `#bats` on freenode
|
||||||
|
|
||||||
|
---
|
||||||
# Bats: Bash Automated Testing System
|
# Bats: Bash Automated Testing System
|
||||||
|
|
||||||
Bats is a [TAP](http://testanything.org)-compliant testing framework
|
Bats is a [TAP](http://testanything.org)-compliant testing framework
|
||||||
|
@ -77,7 +108,7 @@ then iterates over the test cases and executes each one in its own
|
||||||
process.
|
process.
|
||||||
|
|
||||||
For more details about how Bats evaluates test files, see
|
For more details about how Bats evaluates test files, see
|
||||||
[Bats Evaluation Process](https://github.com/sstephenson/bats/wiki/Bats-Evaluation-Process)
|
[Bats Evaluation Process](https://github.com/bats-core/bats-core/wiki/Bats-Evaluation-Process)
|
||||||
on the wiki.
|
on the wiki.
|
||||||
|
|
||||||
### `run`: Test other commands
|
### `run`: Test other commands
|
||||||
|
@ -210,8 +241,8 @@ Check out a copy of the Bats repository. Then, either add the Bats
|
||||||
command with the location to the prefix in which you want to install
|
command with the location to the prefix in which you want to install
|
||||||
Bats. For example, to install Bats into `/usr/local`,
|
Bats. For example, to install Bats into `/usr/local`,
|
||||||
|
|
||||||
$ git clone https://github.com/sstephenson/bats.git
|
$ git clone https://github.com/bats-core/bats-core.git
|
||||||
$ cd bats
|
$ cd bats-core
|
||||||
$ ./install.sh /usr/local
|
$ ./install.sh /usr/local
|
||||||
|
|
||||||
Note that you may need to run `install.sh` with `sudo` if you do not
|
Note that you may need to run `install.sh` with `sudo` if you do not
|
||||||
|
@ -221,15 +252,15 @@ have permission to write to the installation prefix.
|
||||||
## Support
|
## Support
|
||||||
|
|
||||||
The Bats source code repository is [hosted on
|
The Bats source code repository is [hosted on
|
||||||
GitHub](https://github.com/sstephenson/bats). There you can file bugs
|
GitHub](https://github.com/bats-core/bats-core). There you can file bugs
|
||||||
on the issue tracker or submit tested pull requests for review.
|
on the issue tracker or submit tested pull requests for review.
|
||||||
|
|
||||||
For real-world examples from open-source projects using Bats, see
|
For real-world examples from open-source projects using Bats, see
|
||||||
[Projects Using Bats](https://github.com/sstephenson/bats/wiki/Projects-Using-Bats)
|
[Projects Using Bats](https://github.com/bats-core/bats-core/wiki/Projects-Using-Bats)
|
||||||
on the wiki.
|
on the wiki.
|
||||||
|
|
||||||
To learn how to set up your editor for Bats syntax highlighting, see
|
To learn how to set up your editor for Bats syntax highlighting, see
|
||||||
[Syntax Highlighting](https://github.com/sstephenson/bats/wiki/Syntax-Highlighting)
|
[Syntax Highlighting](https://github.com/bats-core/bats-core/wiki/Syntax-Highlighting)
|
||||||
on the wiki.
|
on the wiki.
|
||||||
|
|
||||||
|
|
||||||
|
@ -289,5 +320,9 @@ on the wiki.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
© 2014 Sam Stephenson. Bats is released under an MIT-style license;
|
© 2017 Bianca Tamayo (bats-core organization)
|
||||||
|
|
||||||
|
© 2014 Sam Stephenson
|
||||||
|
|
||||||
|
Bats is released under an MIT-style license;
|
||||||
see `LICENSE` for details.
|
see `LICENSE` for details.
|
||||||
|
|
65
libexec/bats
65
libexec/bats
|
@ -22,39 +22,62 @@ help() {
|
||||||
echo " -t, --tap Show results in TAP format"
|
echo " -t, --tap Show results in TAP format"
|
||||||
echo " -v, --version Display the version number"
|
echo " -v, --version Display the version number"
|
||||||
echo
|
echo
|
||||||
echo " For more information, see https://github.com/sstephenson/bats"
|
echo " For more information, see https://github.com/bats-core/bats-core"
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BATS_READLINK=
|
||||||
|
|
||||||
resolve_link() {
|
resolve_link() {
|
||||||
$(type -p greadlink readlink | head -n1) "$1"
|
if [[ -z "$BATS_READLINK" ]]; then
|
||||||
|
if command -v 'greadlink' >/dev/null; then
|
||||||
|
BATS_READLINK='greadlink'
|
||||||
|
elif command -v 'readlink' >/dev/null; then
|
||||||
|
BATS_READLINK='readlink'
|
||||||
|
else
|
||||||
|
BATS_READLINK='true'
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
"$BATS_READLINK" "$1" || return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
abs_dirname() {
|
abs_dirname() {
|
||||||
local cwd="$(pwd)"
|
local cwd="$PWD"
|
||||||
local path="$1"
|
local path="$1"
|
||||||
|
|
||||||
while [ -n "$path" ]; do
|
while [ -n "$path" ]; do
|
||||||
cd "${path%/*}"
|
cd "${path%/*}"
|
||||||
local name="${path##*/}"
|
local name="${path##*/}"
|
||||||
path="$(resolve_link "$name" || true)"
|
path="$(resolve_link "$name")"
|
||||||
done
|
done
|
||||||
|
|
||||||
pwd
|
printf -v "$2" -- '%s' "$PWD"
|
||||||
cd "$cwd"
|
cd "$cwd"
|
||||||
}
|
}
|
||||||
|
|
||||||
expand_path() {
|
expand_path() {
|
||||||
{ cd "$(dirname "$1")" 2>/dev/null
|
local path="${1%/}"
|
||||||
local dirname="$PWD"
|
local dirname="${path%/*}"
|
||||||
|
|
||||||
|
if [[ "$dirname" == "$path" ]]; then
|
||||||
|
dirname="$PWD"
|
||||||
|
elif cd "$dirname" 2>/dev/null; then
|
||||||
|
dirname="$PWD"
|
||||||
cd "$OLDPWD"
|
cd "$OLDPWD"
|
||||||
echo "$dirname/$(basename "$1")"
|
else
|
||||||
} || echo "$1"
|
printf '%s' "$path"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
printf -v "$2" '%s/%s' "$dirname" "${path##*/}"
|
||||||
}
|
}
|
||||||
|
|
||||||
BATS_LIBEXEC="$(abs_dirname "$0")"
|
abs_dirname "$0" 'BATS_LIBEXEC'
|
||||||
export BATS_PREFIX="$(abs_dirname "$BATS_LIBEXEC")"
|
abs_dirname "$BATS_LIBEXEC" 'BATS_PREFIX'
|
||||||
export BATS_CWD="$(abs_dirname .)"
|
abs_dirname '.' 'BATS_CWD'
|
||||||
|
|
||||||
|
export BATS_PREFIX
|
||||||
|
export BATS_CWD
|
||||||
|
export BATS_TEST_PATTERN='^ *@test +(.+) +\{ *(.*)$'
|
||||||
export PATH="$BATS_LIBEXEC:$PATH"
|
export PATH="$BATS_LIBEXEC:$PATH"
|
||||||
|
|
||||||
options=()
|
options=()
|
||||||
|
@ -113,14 +136,16 @@ fi
|
||||||
|
|
||||||
filenames=()
|
filenames=()
|
||||||
for filename in "${arguments[@]}"; do
|
for filename in "${arguments[@]}"; do
|
||||||
|
expand_path "$filename" 'filename'
|
||||||
|
|
||||||
if [ -d "$filename" ]; then
|
if [ -d "$filename" ]; then
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
for suite_filename in "$(expand_path "$filename")"/*.bats; do
|
for suite_filename in "$filename"/*.bats; do
|
||||||
filenames["${#filenames[@]}"]="$suite_filename"
|
filenames["${#filenames[@]}"]="$suite_filename"
|
||||||
done
|
done
|
||||||
shopt -u nullglob
|
shopt -u nullglob
|
||||||
else
|
else
|
||||||
filenames["${#filenames[@]}"]="$(expand_path "$filename")"
|
filenames["${#filenames[@]}"]="$filename"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -130,13 +155,11 @@ else
|
||||||
command="bats-exec-suite"
|
command="bats-exec-suite"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$pretty" ]; then
|
set -o pipefail execfail
|
||||||
|
if [ -z "$pretty" ]; then
|
||||||
|
exec "$command" $count_flag "${filenames[@]}"
|
||||||
|
else
|
||||||
extended_syntax_flag="-x"
|
extended_syntax_flag="-x"
|
||||||
formatter="bats-format-tap-stream"
|
formatter="bats-format-tap-stream"
|
||||||
else
|
exec "$command" $count_flag $extended_syntax_flag "${filenames[@]}" | "$formatter"
|
||||||
extended_syntax_flag=""
|
|
||||||
formatter="cat"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
set -o pipefail execfail
|
|
||||||
exec "$command" $count_flag $extended_syntax_flag "${filenames[@]}" | "$formatter"
|
|
||||||
|
|
|
@ -17,7 +17,11 @@ trap "kill 0; exit 1" int
|
||||||
|
|
||||||
count=0
|
count=0
|
||||||
for filename in "$@"; do
|
for filename in "$@"; do
|
||||||
let count+="$(bats-exec-test -c "$filename")"
|
while IFS= read -r line; do
|
||||||
|
if [[ "$line" =~ $BATS_TEST_PATTERN ]]; then
|
||||||
|
let count+=1
|
||||||
|
fi
|
||||||
|
done <"$filename"
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -n "$count_only_flag" ]; then
|
if [ -n "$count_only_flag" ]; then
|
||||||
|
|
|
@ -26,7 +26,7 @@ else
|
||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
|
|
||||||
BATS_TEST_DIRNAME="$(dirname "$BATS_TEST_FILENAME")"
|
BATS_TEST_DIRNAME="${BATS_TEST_FILENAME%/*}"
|
||||||
BATS_TEST_NAMES=()
|
BATS_TEST_NAMES=()
|
||||||
|
|
||||||
load() {
|
load() {
|
||||||
|
@ -39,10 +39,10 @@ load() {
|
||||||
filename="$BATS_TEST_DIRNAME/${name}.bash"
|
filename="$BATS_TEST_DIRNAME/${name}.bash"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ -f "$filename" ] || {
|
if [[ ! -f "$filename" ]]; then
|
||||||
echo "bats: $filename does not exist" >&2
|
echo "bats: $filename does not exist" >&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
fi
|
||||||
|
|
||||||
source "${filename}"
|
source "${filename}"
|
||||||
}
|
}
|
||||||
|
@ -101,31 +101,33 @@ bats_capture_stack_trace() {
|
||||||
local teardown_pattern=" teardown $BATS_TEST_SOURCE"
|
local teardown_pattern=" teardown $BATS_TEST_SOURCE"
|
||||||
|
|
||||||
local frame
|
local frame
|
||||||
local index=1
|
local i
|
||||||
|
|
||||||
while frame="$(caller "$index")"; do
|
for ((i=2; i != ${#FUNCNAME[@]}; ++i)); do
|
||||||
|
frame="${BASH_LINENO[$((i-1))]} ${FUNCNAME[$i]} ${BASH_SOURCE[$i]}"
|
||||||
BATS_CURRENT_STACK_TRACE["${#BATS_CURRENT_STACK_TRACE[@]}"]="$frame"
|
BATS_CURRENT_STACK_TRACE["${#BATS_CURRENT_STACK_TRACE[@]}"]="$frame"
|
||||||
if [[ "$frame" = *"$test_pattern" || \
|
if [[ "$frame" = *"$test_pattern" || \
|
||||||
"$frame" = *"$setup_pattern" || \
|
"$frame" = *"$setup_pattern" || \
|
||||||
"$frame" = *"$teardown_pattern" ]]; then
|
"$frame" = *"$teardown_pattern" ]]; then
|
||||||
break
|
break
|
||||||
else
|
|
||||||
let index+=1
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
BATS_SOURCE="$(bats_frame_filename "${BATS_CURRENT_STACK_TRACE[0]}")"
|
bats_frame_filename "${BATS_CURRENT_STACK_TRACE[0]}" 'BATS_SOURCE'
|
||||||
BATS_LINENO="$(bats_frame_lineno "${BATS_CURRENT_STACK_TRACE[0]}")"
|
bats_frame_lineno "${BATS_CURRENT_STACK_TRACE[0]}" 'BATS_LINENO'
|
||||||
}
|
}
|
||||||
|
|
||||||
bats_print_stack_trace() {
|
bats_print_stack_trace() {
|
||||||
local frame
|
local frame
|
||||||
local index=1
|
local index=1
|
||||||
local count="${#@}"
|
local count="${#@}"
|
||||||
|
local filename
|
||||||
|
local lineno
|
||||||
|
|
||||||
for frame in "$@"; do
|
for frame in "$@"; do
|
||||||
local filename="$(bats_trim_filename "$(bats_frame_filename "$frame")")"
|
bats_frame_filename "$frame" 'filename'
|
||||||
local lineno="$(bats_frame_lineno "$frame")"
|
bats_trim_filename "$filename" 'filename'
|
||||||
|
bats_frame_lineno "$frame" 'lineno'
|
||||||
|
|
||||||
if [ $index -eq 1 ]; then
|
if [ $index -eq 1 ]; then
|
||||||
echo -n "# ("
|
echo -n "# ("
|
||||||
|
@ -133,7 +135,8 @@ bats_print_stack_trace() {
|
||||||
echo -n "# "
|
echo -n "# "
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local fn="$(bats_frame_function "$frame")"
|
local fn
|
||||||
|
bats_frame_function "$frame" 'fn'
|
||||||
if [ "$fn" != "$BATS_TEST_NAME" ]; then
|
if [ "$fn" != "$BATS_TEST_NAME" ]; then
|
||||||
echo -n "from function \`$fn' "
|
echo -n "from function \`$fn' "
|
||||||
fi
|
fi
|
||||||
|
@ -151,12 +154,16 @@ bats_print_stack_trace() {
|
||||||
bats_print_failed_command() {
|
bats_print_failed_command() {
|
||||||
local frame="$1"
|
local frame="$1"
|
||||||
local status="$2"
|
local status="$2"
|
||||||
local filename="$(bats_frame_filename "$frame")"
|
local filename
|
||||||
local lineno="$(bats_frame_lineno "$frame")"
|
local lineno
|
||||||
|
local failed_line
|
||||||
|
local failed_command
|
||||||
|
|
||||||
local failed_line="$(bats_extract_line "$filename" "$lineno")"
|
bats_frame_filename "$frame" 'filename'
|
||||||
local failed_command="$(bats_strip_string "$failed_line")"
|
bats_frame_lineno "$frame" 'lineno'
|
||||||
echo -n "# \`${failed_command}' "
|
bats_extract_line "$filename" "$lineno" 'failed_line'
|
||||||
|
bats_strip_string "$failed_line" 'failed_command'
|
||||||
|
printf '%s' "# \`${failed_command}' "
|
||||||
|
|
||||||
if [ $status -eq 1 ]; then
|
if [ $status -eq 1 ]; then
|
||||||
echo "failed"
|
echo "failed"
|
||||||
|
@ -166,49 +173,46 @@ bats_print_failed_command() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bats_frame_lineno() {
|
bats_frame_lineno() {
|
||||||
local frame="$1"
|
printf -v "$2" '%s' "${1%% *}"
|
||||||
local lineno="${frame%% *}"
|
|
||||||
echo "$lineno"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bats_frame_function() {
|
bats_frame_function() {
|
||||||
local frame="$1"
|
local __bff_function="${1#* }"
|
||||||
local rest="${frame#* }"
|
printf -v "$2" '%s' "${__bff_function%% *}"
|
||||||
local fn="${rest%% *}"
|
|
||||||
echo "$fn"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bats_frame_filename() {
|
bats_frame_filename() {
|
||||||
local frame="$1"
|
local __bff_filename="${1#* }"
|
||||||
local rest="${frame#* }"
|
__bff_filename="${__bff_filename#* }"
|
||||||
local filename="${rest#* }"
|
|
||||||
|
|
||||||
if [ "$filename" = "$BATS_TEST_SOURCE" ]; then
|
if [ "$__bff_filename" = "$BATS_TEST_SOURCE" ]; then
|
||||||
echo "$BATS_TEST_FILENAME"
|
__bff_filename="$BATS_TEST_FILENAME"
|
||||||
else
|
|
||||||
echo "$filename"
|
|
||||||
fi
|
fi
|
||||||
|
printf -v "$2" '%s' "$__bff_filename"
|
||||||
}
|
}
|
||||||
|
|
||||||
bats_extract_line() {
|
bats_extract_line() {
|
||||||
local filename="$1"
|
local __bats_extract_line_line
|
||||||
local lineno="$2"
|
local __bats_extract_line_index='0'
|
||||||
sed -n "${lineno}p" "$filename"
|
|
||||||
|
while IFS= read -r __bats_extract_line_line; do
|
||||||
|
if [[ "$((++__bats_extract_line_index))" -eq "$2" ]]; then
|
||||||
|
printf -v "$3" '%s' "${__bats_extract_line_line%$'\r'}"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done <"$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
bats_strip_string() {
|
bats_strip_string() {
|
||||||
local string="$1"
|
[[ "$1" =~ ^[[:space:]]*(.*)[[:space:]]*$ ]]
|
||||||
printf "%s" "$string" | sed -e "s/^[ "$'\t'"]*//" -e "s/[ "$'\t'"]*$//"
|
printf -v "$2" '%s' "${BASH_REMATCH[1]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
bats_trim_filename() {
|
bats_trim_filename() {
|
||||||
local filename="$1"
|
if [[ "$1" =~ ^${BATS_CWD}/ ]]; then
|
||||||
local length="${#BATS_CWD}"
|
printf -v "$2" '%s' "${1#$BATS_CWD/}"
|
||||||
|
|
||||||
if [ "${filename:0:length+1}" = "${BATS_CWD}/" ]; then
|
|
||||||
echo "${filename:length+1}"
|
|
||||||
else
|
else
|
||||||
echo "$filename"
|
printf -v "$2" '%s' "$1"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,13 +222,22 @@ bats_debug_trap() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# When running under Bash 3.2.57(1)-release on macOS, the `ERR` trap may not
|
||||||
|
# always fire, but the `EXIT` trap will. For this reason we call it at the very
|
||||||
|
# beginning of `bats_teardown_trap` (the `DEBUG` trap for the call will move
|
||||||
|
# `BATS_CURRENT_STACK_TRACE` to `BATS_PREVIOUS_STACK_TRACE`) and check the value
|
||||||
|
# of `$?` before taking other actions.
|
||||||
bats_error_trap() {
|
bats_error_trap() {
|
||||||
BATS_ERROR_STATUS="$?"
|
local status="$?"
|
||||||
BATS_ERROR_STACK_TRACE=( "${BATS_PREVIOUS_STACK_TRACE[@]}" )
|
if [[ "$status" -ne '0' ]]; then
|
||||||
trap - debug
|
BATS_ERROR_STATUS="$status"
|
||||||
|
BATS_ERROR_STACK_TRACE=( "${BATS_PREVIOUS_STACK_TRACE[@]}" )
|
||||||
|
trap - debug
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
bats_teardown_trap() {
|
bats_teardown_trap() {
|
||||||
|
bats_error_trap
|
||||||
trap "bats_exit_trap" exit
|
trap "bats_exit_trap" exit
|
||||||
local status=0
|
local status=0
|
||||||
teardown >>"$BATS_OUT" 2>&1 || status="$?"
|
teardown >>"$BATS_OUT" 2>&1 || status="$?"
|
||||||
|
@ -280,7 +293,7 @@ bats_perform_tests() {
|
||||||
|
|
||||||
bats_perform_test() {
|
bats_perform_test() {
|
||||||
BATS_TEST_NAME="$1"
|
BATS_TEST_NAME="$1"
|
||||||
if [ "$(type -t "$BATS_TEST_NAME" || true)" = "function" ]; then
|
if declare -F "$BATS_TEST_NAME" >/dev/null; then
|
||||||
BATS_TEST_NUMBER="$2"
|
BATS_TEST_NUMBER="$2"
|
||||||
if [ -z "$BATS_TEST_NUMBER" ]; then
|
if [ -z "$BATS_TEST_NUMBER" ]; then
|
||||||
echo "1..1"
|
echo "1..1"
|
||||||
|
@ -313,7 +326,7 @@ BATS_OUT="${BATS_TMPNAME}.out"
|
||||||
|
|
||||||
bats_preprocess_source() {
|
bats_preprocess_source() {
|
||||||
BATS_TEST_SOURCE="${BATS_TMPNAME}.src"
|
BATS_TEST_SOURCE="${BATS_TMPNAME}.src"
|
||||||
{ tr -d '\r' < "$BATS_TEST_FILENAME"; echo; } | bats-preprocess > "$BATS_TEST_SOURCE"
|
. bats-preprocess <<< "$(< "$BATS_TEST_FILENAME")"$'\n' > "$BATS_TEST_SOURCE"
|
||||||
trap "bats_cleanup_preprocessed_source" err exit
|
trap "bats_cleanup_preprocessed_source" err exit
|
||||||
trap "bats_cleanup_preprocessed_source; exit 1" int
|
trap "bats_cleanup_preprocessed_source; exit 1" int
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,9 +65,15 @@ log() {
|
||||||
}
|
}
|
||||||
|
|
||||||
summary() {
|
summary() {
|
||||||
printf "\n%d test%s" "$count" "$(plural "$count")"
|
printf "\n%d test" "$count"
|
||||||
|
if [[ "$count" -ne '1' ]]; then
|
||||||
|
printf 's'
|
||||||
|
fi
|
||||||
|
|
||||||
printf ", %d failure%s" "$failures" "$(plural "$failures")"
|
printf ", %d failure" "$failures"
|
||||||
|
if [[ "$failures" -ne '1' ]]; then
|
||||||
|
printf 's'
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$skipped" -gt 0 ]; then
|
if [ "$skipped" -gt 0 ]; then
|
||||||
printf ", %d skipped" "$skipped"
|
printf ", %d skipped" "$skipped"
|
||||||
|
@ -79,7 +85,9 @@ summary() {
|
||||||
printf_with_truncation() {
|
printf_with_truncation() {
|
||||||
local width="$1"
|
local width="$1"
|
||||||
shift
|
shift
|
||||||
local string="$(printf "$@")"
|
local string
|
||||||
|
|
||||||
|
printf -v 'string' -- "$@"
|
||||||
|
|
||||||
if [ "${#string}" -gt "$width" ]; then
|
if [ "${#string}" -gt "$width" ]; then
|
||||||
printf "%s..." "${string:0:$(( $width - 4 ))}"
|
printf "%s..." "${string:0:$(( $width - 4 ))}"
|
||||||
|
@ -105,18 +113,18 @@ advance() {
|
||||||
|
|
||||||
set_color() {
|
set_color() {
|
||||||
local color="$1"
|
local color="$1"
|
||||||
local weight="$2"
|
local weight='22'
|
||||||
printf "\x1B[%d;%dm" $(( 30 + $color )) "$( [ "$weight" = "bold" ] && echo 1 || echo 22 )"
|
|
||||||
|
if [[ "$2" == 'bold' ]]; then
|
||||||
|
weight='1'
|
||||||
|
fi
|
||||||
|
printf "\x1B[%d;%dm" $(( 30 + $color )) "$weight"
|
||||||
}
|
}
|
||||||
|
|
||||||
clear_color() {
|
clear_color() {
|
||||||
printf "\x1B[0m"
|
printf "\x1B[0m"
|
||||||
}
|
}
|
||||||
|
|
||||||
plural() {
|
|
||||||
[ "$1" -eq 1 ] || echo "s"
|
|
||||||
}
|
|
||||||
|
|
||||||
_buffer=""
|
_buffer=""
|
||||||
|
|
||||||
buffer() {
|
buffer() {
|
||||||
|
|
|
@ -4,6 +4,7 @@ set -e
|
||||||
encode_name() {
|
encode_name() {
|
||||||
local name="$1"
|
local name="$1"
|
||||||
local result="test_"
|
local result="test_"
|
||||||
|
local hex_code
|
||||||
|
|
||||||
if [[ ! "$name" =~ [^[:alnum:]\ _-] ]]; then
|
if [[ ! "$name" =~ [^[:alnum:]\ _-] ]]; then
|
||||||
name="${name//_/-5f}"
|
name="${name//_/-5f}"
|
||||||
|
@ -21,27 +22,28 @@ encode_name() {
|
||||||
elif [[ "$char" =~ [[:alnum:]] ]]; then
|
elif [[ "$char" =~ [[:alnum:]] ]]; then
|
||||||
result+="$char"
|
result+="$char"
|
||||||
else
|
else
|
||||||
result+="$(printf -- "-%02x" \'"$char")"
|
printf -v 'hex_code' -- "-%02x" \'"$char"
|
||||||
|
result+="$hex_code"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "$result"
|
printf -v "$2" '%s' "$result"
|
||||||
}
|
}
|
||||||
|
|
||||||
tests=()
|
tests=()
|
||||||
index=0
|
index=0
|
||||||
pattern='^ *@test *([^ ].*) *\{ *(.*)$'
|
|
||||||
|
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
|
line="${line//$'\r'}"
|
||||||
let index+=1
|
let index+=1
|
||||||
if [[ "$line" =~ $pattern ]]; then
|
if [[ "$line" =~ $BATS_TEST_PATTERN ]]; then
|
||||||
quoted_name="${BASH_REMATCH[1]}"
|
name="${BASH_REMATCH[1]#[\'\"]}"
|
||||||
|
name="${name%[\'\"]}"
|
||||||
body="${BASH_REMATCH[2]}"
|
body="${BASH_REMATCH[2]}"
|
||||||
name="$(eval echo "$quoted_name")"
|
encode_name "$name" 'encoded_name'
|
||||||
encoded_name="$(encode_name "$name")"
|
|
||||||
tests["${#tests[@]}"]="$encoded_name"
|
tests["${#tests[@]}"]="$encoded_name"
|
||||||
echo "${encoded_name}() { bats_test_begin ${quoted_name} ${index}; ${body}"
|
echo "${encoded_name}() { bats_test_begin \"${name}\" ${index}; ${body}"
|
||||||
else
|
else
|
||||||
printf "%s\n" "$line"
|
printf "%s\n" "$line"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -89,12 +89,14 @@ ok 2 addition using dc
|
||||||
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\.
|
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"
|
.SH "SEE ALSO"
|
||||||
Bats wiki: \fIhttps://github\.com/sstephenson/bats/wiki/\fR
|
Bats wiki: \fIhttps://github\.com/bats\-core/bats\-core/wiki/\fR
|
||||||
.
|
.
|
||||||
.P
|
.P
|
||||||
\fBbash\fR(1), \fBbats\fR(7)
|
\fBbash\fR(1), \fBbats\fR(7)
|
||||||
.
|
.
|
||||||
.SH "COPYRIGHT"
|
.SH "COPYRIGHT"
|
||||||
|
|
||||||
|
(c) 2017 Bianca Tamayo (bats-core organization)
|
||||||
(c) 2014 Sam Stephenson
|
(c) 2014 Sam Stephenson
|
||||||
.
|
.
|
||||||
.P
|
.P
|
||||||
|
|
|
@ -93,7 +93,7 @@ or `1` if one or more test cases fail.
|
||||||
SEE ALSO
|
SEE ALSO
|
||||||
--------
|
--------
|
||||||
|
|
||||||
Bats wiki: _https://github.com/sstephenson/bats/wiki/_
|
Bats wiki: _https://github.com/bats\-core/bats\-core/wiki/_
|
||||||
|
|
||||||
`bash`(1), `bats`(7)
|
`bash`(1), `bats`(7)
|
||||||
|
|
||||||
|
@ -101,6 +101,7 @@ Bats wiki: _https://github.com/sstephenson/bats/wiki/_
|
||||||
COPYRIGHT
|
COPYRIGHT
|
||||||
---------
|
---------
|
||||||
|
|
||||||
|
(c) 2017 Bianca Tamayo (bats-core organization)
|
||||||
(c) 2014 Sam Stephenson
|
(c) 2014 Sam Stephenson
|
||||||
|
|
||||||
Bats is released under the terms of an MIT-style license.
|
Bats is released under the terms of an MIT-style license.
|
||||||
|
|
|
@ -41,25 +41,25 @@ fixtures bats
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "summary passing tests" {
|
@test "summary passing tests" {
|
||||||
run filter_control_sequences bats -p $FIXTURE_ROOT/passing.bats
|
run filter_control_sequences bats -p "$FIXTURE_ROOT/passing.bats"
|
||||||
[ $status -eq 0 ]
|
[ $status -eq 0 ]
|
||||||
[ "${lines[1]}" = "1 test, 0 failures" ]
|
[ "${lines[1]}" = "1 test, 0 failures" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "summary passing and skipping tests" {
|
@test "summary passing and skipping tests" {
|
||||||
run filter_control_sequences bats -p $FIXTURE_ROOT/passing_and_skipping.bats
|
run filter_control_sequences bats -p "$FIXTURE_ROOT/passing_and_skipping.bats"
|
||||||
[ $status -eq 0 ]
|
[ $status -eq 0 ]
|
||||||
[ "${lines[2]}" = "2 tests, 0 failures, 1 skipped" ]
|
[ "${lines[2]}" = "2 tests, 0 failures, 1 skipped" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "summary passing and failing tests" {
|
@test "summary passing and failing tests" {
|
||||||
run filter_control_sequences bats -p $FIXTURE_ROOT/failing_and_passing.bats
|
run filter_control_sequences bats -p "$FIXTURE_ROOT/failing_and_passing.bats"
|
||||||
[ $status -eq 0 ]
|
[ $status -eq 0 ]
|
||||||
[ "${lines[4]}" = "2 tests, 1 failure" ]
|
[ "${lines[4]}" = "2 tests, 1 failure" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "summary passing, failing and skipping tests" {
|
@test "summary passing, failing and skipping tests" {
|
||||||
run filter_control_sequences bats -p $FIXTURE_ROOT/passing_failing_and_skipping.bats
|
run filter_control_sequences bats -p "$FIXTURE_ROOT/passing_failing_and_skipping.bats"
|
||||||
[ $status -eq 0 ]
|
[ $status -eq 0 ]
|
||||||
[ "${lines[5]}" = "3 tests, 1 failure, 1 skipped" ]
|
[ "${lines[5]}" = "3 tests, 1 failure, 1 skipped" ]
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,8 @@ fixtures bats
|
||||||
@test "one failing test" {
|
@test "one failing test" {
|
||||||
run bats "$FIXTURE_ROOT/failing.bats"
|
run bats "$FIXTURE_ROOT/failing.bats"
|
||||||
[ $status -eq 1 ]
|
[ $status -eq 1 ]
|
||||||
|
printf 'lines:\n' >&2
|
||||||
|
printf '%s\n' "${lines[@]}" >&2
|
||||||
[ "${lines[0]}" = '1..1' ]
|
[ "${lines[0]}" = '1..1' ]
|
||||||
[ "${lines[1]}" = 'not ok 1 a failing test' ]
|
[ "${lines[1]}" = 'not ok 1 a failing test' ]
|
||||||
[ "${lines[2]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/failing.bats, line 4)" ]
|
[ "${lines[2]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/failing.bats, line 4)" ]
|
||||||
|
@ -86,6 +88,8 @@ fixtures bats
|
||||||
@test "failing test with significant status" {
|
@test "failing test with significant status" {
|
||||||
STATUS=2 run bats "$FIXTURE_ROOT/failing.bats"
|
STATUS=2 run bats "$FIXTURE_ROOT/failing.bats"
|
||||||
[ $status -eq 1 ]
|
[ $status -eq 1 ]
|
||||||
|
printf 'lines:\n' >&2
|
||||||
|
printf '%s\n' "${lines[@]}" >&2
|
||||||
[ "${lines[3]}" = "# \`eval \"( exit \${STATUS:-1} )\"' failed with status 2" ]
|
[ "${lines[3]}" = "# \`eval \"( exit \${STATUS:-1} )\"' failed with status 2" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,6 +157,8 @@ fixtures bats
|
||||||
cd "$TMP"
|
cd "$TMP"
|
||||||
run bats "$FIXTURE_ROOT/failing.bats"
|
run bats "$FIXTURE_ROOT/failing.bats"
|
||||||
[ $status -eq 1 ]
|
[ $status -eq 1 ]
|
||||||
|
printf 'lines:\n' >&2
|
||||||
|
printf '%s\n' "${lines[@]}" >&2
|
||||||
[ "${lines[2]}" = "# (in test file $FIXTURE_ROOT/failing.bats, line 4)" ]
|
[ "${lines[2]}" = "# (in test file $FIXTURE_ROOT/failing.bats, line 4)" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,3 +268,17 @@ fixtures bats
|
||||||
[ $status -eq 0 ]
|
[ $status -eq 0 ]
|
||||||
[ "${lines[1]}" = "ok 1 loop_func" ]
|
[ "${lines[1]}" = "ok 1 loop_func" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "expand variables in test name" {
|
||||||
|
SUITE='test/suite' run bats "$FIXTURE_ROOT/expand_var_in_test_name.bats"
|
||||||
|
[ $status -eq 0 ]
|
||||||
|
[ "${lines[1]}" = "ok 1 test/suite: test with variable in name" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "handle quoted and unquoted test names" {
|
||||||
|
run bats "$FIXTURE_ROOT/quoted_and_unquoted_test_names.bats"
|
||||||
|
[ $status -eq 0 ]
|
||||||
|
[ "${lines[1]}" = "ok 1 single-quoted name" ]
|
||||||
|
[ "${lines[2]}" = "ok 2 double-quoted name" ]
|
||||||
|
[ "${lines[3]}" = "ok 3 unquoted name" ]
|
||||||
|
}
|
||||||
|
|
3
test/fixtures/bats/expand_var_in_test_name.bats
vendored
Normal file
3
test/fixtures/bats/expand_var_in_test_name.bats
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
@test "$SUITE: test with variable in name" {
|
||||||
|
true
|
||||||
|
}
|
11
test/fixtures/bats/quoted_and_unquoted_test_names.bats
vendored
Normal file
11
test/fixtures/bats/quoted_and_unquoted_test_names.bats
vendored
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
@test 'single-quoted name' {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "double-quoted name" {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
@test unquoted name {
|
||||||
|
true
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
fixtures() {
|
fixtures() {
|
||||||
FIXTURE_ROOT="$BATS_TEST_DIRNAME/fixtures/$1"
|
FIXTURE_ROOT="$BATS_TEST_DIRNAME/fixtures/$1"
|
||||||
RELATIVE_FIXTURE_ROOT="$(bats_trim_filename "$FIXTURE_ROOT")"
|
bats_trim_filename "$FIXTURE_ROOT" 'RELATIVE_FIXTURE_ROOT'
|
||||||
}
|
}
|
||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user