1
0
mirror of https://github.com/sstephenson/bats.git synced 2026-02-26 09:48:10 +01:00

Warn about bare [[ ... ]] expressions

This commit is contained in:
Sam Stephenson
2014-06-02 21:00:46 -05:00
parent 49f533e4a7
commit bea06b9825
3 changed files with 91 additions and 5 deletions

View File

@@ -206,3 +206,14 @@ fixtures bats
[ "${lines[4]}" = "not ok 4 failing" ]
[ "${lines[5]}" = "# (in test file $FIXTURE_ROOT/single_line.bats, line 9)" ]
}
@test "bare double-bracket expressions trigger warnings" {
run bats "$FIXTURE_ROOT/double_brackets.bats"
[ $status -eq 0 ]
[ "${lines[1]}" = "ok 1 bare" ]
[ "${lines[2]}" = "# WARNING: Bare \`[[ ]]' expressions, when false, may not cause test failures." ]
[ "${lines[3]}" = "# Read more at https://github.com/sstephenson/bats/wiki/Double-Brackets" ]
[ "${lines[4]}" = "# (in file $FIXTURE_ROOT/double_brackets.bats, line 2)" ]
[ "${lines[5]}" = "ok 2 chained" ]
[ "${lines[6]}" = "ok 3 if" ]
}

15
test/fixtures/bats/double_brackets.bats vendored Normal file
View File

@@ -0,0 +1,15 @@
@test "bare" {
[[ 1 = 1 ]]
}
@test "chained" {
[[ 1 = 1 ]] || true
}
@test "if" {
if [[ 1 = 1 ]]; then
true
else
false
fi
}