-
Notifications
You must be signed in to change notification settings - Fork 410
/
formatter.bats
101 lines (87 loc) · 3.37 KB
/
formatter.bats
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env bats
setup() {
load test_helper
fixtures formatter
}
@test "tap passing and skipping tests" {
run filter_control_sequences bats --formatter tap "$FIXTURE_ROOT/passing_and_skipping.bats"
[ $status -eq 0 ]
[ "${lines[0]}" = "1..3" ]
[ "${lines[1]}" = "ok 1 a passing test" ]
[ "${lines[2]}" = "ok 2 a skipped test with no reason # skip" ]
[ "${lines[3]}" = "ok 3 a skipped test with a reason # skip for a really good reason" ]
}
@test "tap passing, failing and skipping tests" {
run filter_control_sequences bats --formatter tap "$FIXTURE_ROOT/passing_failing_and_skipping.bats"
[ $status -eq 0 ]
[ "${lines[0]}" = "1..3" ]
[ "${lines[1]}" = "ok 1 a passing test" ]
[ "${lines[2]}" = "ok 2 a skipping test # skip" ]
[ "${lines[3]}" = "not ok 3 a failing test" ]
}
@test "skipped test with parens (pretty formatter)" {
run bats --pretty "$FIXTURE_ROOT/skipped_with_parens.bats"
[ $status -eq 0 ]
# Some systems (Alpine, for example) seem to emit an extra whitespace into
# entries in the 'lines' array when a carriage return is present from the
# pretty formatter. This is why a '+' is used after the 'skipped' note.
[[ "${lines[*]}" =~ "- a skipped test with parentheses in the reason (skipped: "+"a reason (with parentheses))" ]]
}
@test "pretty and tap formats" {
run bats --formatter 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-format-pretty < <(printf "This isn't TAP!\nGood day to you\n")
[ $status -eq 0 ]
[ "${lines[0]}" = "This isn't TAP!" ]
[ "${lines[1]}" = "Good day to you" ]
}
@test "All formatters (except cat) implement the callback interface" {
cd "$BATS_ROOT/libexec/bats-core/"
for formatter in bats-format-*; do
# the cat formatter is not expected to implement this interface
if [[ "$formatter" == *"bats-format-cat" ]]; then
continue
fi
tested_at_least_one_formatter=1
echo "Formatter: ${formatter}"
# the replay should be possible without errors
bash -u "$formatter" >/dev/null <<EOF
1..1
suite "$FIXTURE_ROOT/failing.bats"
# output from setup_file
begin 1 test_a_failing_test
# fd3 output from test
not ok 1 a failing test
# (in test file test/fixtures/bats/failing.bats, line 4)
# \`eval "( exit ${STATUS:-1} )"' failed
begin 2 test_a_successful_test
ok 2 a succesful test
unknown line
EOF
done
[[ -n "$tested_at_least_one_formatter" ]]
}
@test "absolute paths load external formatters" {
bats_require_minimum_version 1.5.0
run -0 bats "$FIXTURE_ROOT/passing.bats" --formatter "$FIXTURE_ROOT/dummy-formatter"
[ "$output" = "Dummy Formatter!" ]
}
@test "specifying nonexistent external formatter is an error" {
bats_require_minimum_version 1.5.0
run -1 bats "$FIXTURE_ROOT/passing.bats" --formatter "$FIXTURE_ROOT/non-existing-file"
[ "$output" = "ERROR: Formatter '$FIXTURE_ROOT/non-existing-file' is not readable!" ]
}
@test "specifying non executable external formatter is an error" {
bats_require_minimum_version 1.5.0
local non_executable="$BATS_TEST_TMPDIR/non-executable"
touch "$non_executable"
run -1 bats "$FIXTURE_ROOT/passing.bats" --formatter "$non_executable"
[ "$output" = "ERROR: Formatter '$non_executable' is not executable!" ]
}