Skip to content
This repository has been archived by the owner on Apr 29, 2021. It is now read-only.

GitHub for Windows compatibility #128

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -e

resolve_link() {
$(type -p greadlink readlink | head -1) "$1"
type -t readlink > /dev/null && readlink "$1"
}

abs_dirname() {
Expand Down
2 changes: 1 addition & 1 deletion libexec/bats
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ help() {
}

resolve_link() {
$(type -p greadlink readlink | head -1) "$1"
type -t readlink > /dev/null && readlink "$1"
}

abs_dirname() {
Expand Down
4 changes: 3 additions & 1 deletion libexec/bats-exec-suite
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ for filename in "$@"; do
;;
esac
done
} < <( bats-exec-test $extended_syntax_flag "$filename" )
} <<EOF
$(bats-exec-test $extended_syntax_flag "$filename")
EOF
offset=$(($offset + $index))
done

Expand Down
6 changes: 3 additions & 3 deletions libexec/bats-exec-test
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ load() {

run() {
local e E T oldIFS
[[ ! "$-" =~ e ]] || e=1
[[ ! "$-" =~ E ]] || E=1
[[ ! "$-" =~ T ]] || T=1
[[ ! "$-" = *e* ]] || e=1
[[ ! "$-" = *E* ]] || E=1
[[ ! "$-" = *T* ]] || T=1
set +e
set +E
set +T
Expand Down
34 changes: 23 additions & 11 deletions libexec/bats-format-tap-stream
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#!/usr/bin/env bash
set -e
shopt -s extglob

# 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]+'
header_pattern='*+([0-9])..+([0-9])*'
IFS= read -r header

if [[ "$header" =~ $header_pattern ]]; then
if [[ "$header" = $header_pattern ]]; then
count="${header:3}"
index=0
failures=0
Expand All @@ -20,8 +18,14 @@ else
exec cat
fi

if [ "$TERM" != msys ] && type -t tput > /dev/null; then
COLUMNS_CMD='tput cols'
else
COLUMNS_CMD='echo 80'
fi

update_screen_width() {
screen_width="$(tput cols)"
screen_width="$( eval $COLUMNS_CMD )"
count_column_left=$(( $screen_width - $count_column_width ))
}

Expand All @@ -37,9 +41,17 @@ begin() {
go_to_column 1
}

if [[ $TERM != msys ]]; then
PASS_SYMBOL='✓'
FAIL_SYMBOL='✗'
else
PASS_SYMBOL='√'
FAIL_SYMBOL='×'
fi

pass() {
go_to_column 0
printf " %s" "$name"
printf " $PASS_SYMBOL %s" "$name"
advance
}

Expand All @@ -54,7 +66,7 @@ skip() {
fail() {
go_to_column 0
set_color 1 bold
printf " %s" "$name"
printf " $FAIL_SYMBOL %s" "$name"
advance
}

Expand Down Expand Up @@ -144,10 +156,10 @@ while IFS= read -r line; do
flush
;;
"ok "* )
skip_expr="ok $index # skip (\(([^)]*)\))?"
if [[ "$line" =~ $skip_expr ]]; then
skip_expr="ok $index # skip*"
if [[ "$line" = $skip_expr ]]; then
let skipped+=1
buffer skip "${BASH_REMATCH[2]}"
buffer skip "${line//@(*\(|\)*)}"
else
buffer pass
fi
Expand Down
13 changes: 7 additions & 6 deletions libexec/bats-preprocess
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env bash
set -e
shopt -s extglob

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

if [[ ! "$name" =~ [^[:alnum:]\ _-] ]]; then
if [[ ! "$name" = *[^[:alnum:]\ _-]* ]]; then
name="${name//_/-5f}"
name="${name//-/-2d}"
name="${name// /_}"
Expand All @@ -18,7 +19,7 @@ encode_name() {
char="${name:$i:1}"
if [ "$char" = " " ]; then
result+="_"
elif [[ "$char" =~ [[:alnum:]] ]]; then
elif [[ "$char" = [[:alnum:]] ]]; then
result+="$char"
else
result+="$(printf -- "-%02x" \'"$char")"
Expand All @@ -31,13 +32,13 @@ encode_name() {

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

while IFS= read -r line; do
let index+=1
if [[ "$line" =~ $pattern ]]; then
quoted_name="${BASH_REMATCH[1]}"
body="${BASH_REMATCH[2]}"
if [[ "$line" = $pattern ]]; then
quoted_name="${line//@(*@test+( )|+( )\{*)}"
body="${line##*\{*( )}"
name="$(eval echo "$quoted_name")"
encoded_name="$(encode_name "$name")"
tests["${#tests[@]}"]="$encoded_name"
Expand Down
13 changes: 13 additions & 0 deletions test/bats.bats
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,19 @@ fixtures bats
[ "${lines[1]}" = "Good day to you" ]
}

@test "pretty formatter uses different symbols in MSYS terminal" {
TERM=msys run bats --pretty "$FIXTURE_ROOT/passing_and_failing.bats"
msys_pass=${lines[0]}
msys_fail=${lines[1]}

TERM=other run bats --pretty "$FIXTURE_ROOT/passing_and_failing.bats"
default_pass=${lines[0]}
default_fail=${lines[1]}

[ "$msys_pass" != "$default_pass" ]
[ "$msys_fail" != "$default_fail" ]
}

@test "single-line tests" {
run bats "$FIXTURE_ROOT/single_line.bats"
[ $status -eq 1 ]
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/bats/single_line.bats
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

@test "passing" { true; }

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

Expand Down