Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ build: off
test_script:
- where bash
- bash --version
- bash -c 'time libexec/bats test'
- bash -c 'export'
- bash -c 'time bin/bats test'
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@
- [`skip`: Easily skip tests](#skip-easily-skip-tests)
- [`setup` and `teardown`: Pre- and post-test hooks](#setup-and-teardown-pre--and-post-test-hooks)
- [Code outside of test cases](#code-outside-of-test-cases)
- [File descriptor 3](#file-descriptor-3-read-this-if-bats-hangs)
- [Printing to the terminal](#printing-to-the-terminal)
- [Special variables](#special-variables)
- [Installation](#installation)
- [Supported Bash versions](#supported-bash-versions)
- [Installing Bats from source](#installing-bats-from-source)
- [Running Bats in Docker](#running-bats-in-docker)
- [Using Bats](#using-bats)
- [Support](#support)
- [Version history](#version-history)

Expand Down
1 change: 0 additions & 1 deletion bin/bats

This file was deleted.

3 changes: 3 additions & 0 deletions bin/bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /usr/bin/env bash

exec "${0%/*}/../libexec/bats" "$@"
7 changes: 0 additions & 7 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ 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

# fix broken symbolic link file
if [ ! -L "$PREFIX"/bin/bats ]; then
dir="$(readlink -e "$PREFIX")"
rm -f "$dir"/bin/bats
ln -s "$dir"/libexec/bats "$dir"/bin/bats
fi

# fix file permission
chmod a+x "$PREFIX"/bin/*
chmod a+x "$PREFIX"/libexec/*
Expand Down
48 changes: 25 additions & 23 deletions libexec/bats
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,24 @@ help() {
echo
}

BATS_READLINK=
export BATS_READLINK='true'
if command -v 'greadlink' >/dev/null; then
BATS_READLINK='greadlink'
elif command -v 'readlink' >/dev/null; then
BATS_READLINK='readlink'
fi

resolve_link() {
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
if ! "$BATS_READLINK" "$1"; then
return 0
fi
"$BATS_READLINK" "$1" || return 0
}

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

while [ -n "$path" ]; do
while [[ -n "$path" ]]; do
cd "${path%/*}"
local name="${path##*/}"
path="$(resolve_link "$name")"
Expand Down Expand Up @@ -83,13 +81,15 @@ export PATH="$BATS_LIBEXEC:$PATH"
options=()
arguments=()
for arg in "$@"; do
if [ "${arg:0:1}" = "-" ]; then
if [ "${arg:1:1}" = "-" ]; then
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
if [[ -z "$option" ]]; then
break
fi
options[${#options[*]}]="$option"
let index+=1
done
Expand All @@ -102,10 +102,11 @@ done
unset count_flag pretty
count_flag=''
pretty=''
[ -t 0 ] && [ -t 1 ] && pretty="1"
[ -n "${CI:-}" ] && pretty=""
if [[ -z "${CI:-}" && -t 0 && -t 1 ]]; then
pretty=1
fi

if [[ "${#options[@]}" -ne '0' ]]; then
if [[ "${#options[@]}" -ne 0 ]]; then
for option in "${options[@]}"; do
case "$option" in
"h" | "help" )
Expand All @@ -123,7 +124,7 @@ if [[ "${#options[@]}" -ne '0' ]]; then
pretty=""
;;
"p" | "pretty" )
pretty="1"
pretty=1
;;
* )
usage >&2
Expand All @@ -133,7 +134,7 @@ if [[ "${#options[@]}" -ne '0' ]]; then
done
fi

if [ "${#arguments[@]}" -eq 0 ]; then
if [[ "${#arguments[@]}" -eq 0 ]]; then
usage >&2
exit 1
fi
Expand All @@ -142,7 +143,7 @@ filenames=()
for filename in "${arguments[@]}"; do
expand_path "$filename" 'filename'

if [ -d "$filename" ]; then
if [[ -d "$filename" ]]; then
shopt -s nullglob
for suite_filename in "$filename"/*.bats; do
filenames["${#filenames[@]}"]="$suite_filename"
Expand All @@ -153,17 +154,18 @@ for filename in "${arguments[@]}"; do
fi
done

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

set -o pipefail execfail
if [ -z "$pretty" ]; then
if [[ -z "$pretty" ]]; then
exec "$command" $count_flag "${filenames[@]}"
else
extended_syntax_flag="-x"
formatter="bats-format-tap-stream"
exec "$command" $count_flag $extended_syntax_flag "${filenames[@]}" | "$formatter"
exec "$command" $count_flag $extended_syntax_flag "${filenames[@]}" |
"$formatter"
fi
14 changes: 9 additions & 5 deletions libexec/bats-exec-suite
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
set -e

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

extended_syntax_flag=""
if [ "$1" = "-x" ]; then
if [[ "$1" = "-x" ]]; then
extended_syntax_flag="-x"
shift
fi
Expand All @@ -24,7 +24,7 @@ for filename in "$@"; do
done <"$filename"
done

if [ -n "$count_only_flag" ]; then
if [[ -n "$count_only_flag" ]]; then
echo "$count"
exit
fi
Expand All @@ -43,9 +43,13 @@ for filename in "$@"; do
echo "${line/ $index / $(($offset + $index)) }"
;;
"ok "* | "not ok "* )
[ -n "$extended_syntax_flag" ] || let index+=1
if [[ -z "$extended_syntax_flag" ]]; then
let index+=1
fi
echo "${line/ $index / $(($offset + $index)) }"
[ "${line:0:6}" != "not ok" ] || status=1
if [[ "${line:0:6}" == "not ok" ]]; then
status=1
fi
;;
* )
echo "$line"
Expand Down
Loading