File: test_tap_format

package info (click to toggle)
bash-unit 2.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,304 kB
  • sloc: sh: 1,134; makefile: 10
file content (124 lines) | stat: -rw-r--r-- 2,233 bytes parent folder | download
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env bash

test_bash_unit_accepts_tap_format_option() {
  assert "$BASH_UNIT -f tap"
}

test_bash_unit_rejects_invalid_format() {
  assert_fails "$BASH_UNIT -f invalid_format"
}

test_tap_format_for_one_succesfull_test() {
  assert_equals \
"\
# Running tests in code
ok - test_ok
1..1" \
"$(bash_unit_out_for_code <<EOF
  test_ok() {
    assert true
  }
EOF
)"
}

test_tap_format_for_one_failing_test() {
   assert_equals \
"\
# Running tests in code
not ok - test_not_ok
# code:2:test_not_ok()
1..1" \
"$(bash_unit_out_for_code <<EOF
  test_not_ok() {
    assert false
  }
EOF
)"
}

test_tap_format_for_one_pending_test() {
   assert_equals \
"\
# Running tests in code
ok - pending_not_yet_implemented # todo test to be written
1..1" \
"$(bash_unit_out_for_code <<EOF
  pending_not_yet_implemented() {
    assert false
  }
EOF
)"
}

test_tap_format_with_skipped_tests() {
  bash_unit_output="$(bash_unit_out_for_code <<EOF
    test_one() { echo -n ; }
    test_two() { fail ; }
    skip_if true two
EOF
  )"

  assert_equals "\
# Running tests in code
ok - test_two # skip test not run
ok - test_one
1..2" \
  "$bash_unit_output"
}

test_tap_format_for_failing_test_with_stdout_stderr_outputs() {
   assert_equals \
"\
# Running tests in code
not ok - test_not_ok
# out> message on stdout
# err> message on stderr
# code:2:test_not_ok()
1..1" \
"$(bash_unit_out_for_code <<EOF
  test_not_ok() {
    assert_fails "echo message on stdout ; echo message on stderr >&2"
  }
EOF
)"
}

test_assertion_message_is_tap_formatted() {
   assert_equals \
"\
# Running tests in code
not ok - test_not_ok
# obvious failure
# code:2:test_not_ok()
1..1" \
"$(bash_unit_out_for_code <<EOF
  test_not_ok() {
    assert_fails true "obvious failure"
  }
EOF
)"
}

test_multi_lines_assertion_message_is_tap_formatted() {
   assert_equals \
"\
# Running tests in code
not ok - test_not_ok
# obvious failure
# on multiple lines
# code:2:test_not_ok()
1..1" \
"$(bash_unit_out_for_code <<EOF
  test_not_ok() {
    assert_fails true "obvious failure\non multiple lines"
  }
EOF
)"
}

bash_unit_out_for_code() {
  $BASH_UNIT -f tap <(cat) | sed -e 's:/dev/fd/[0-9]*:code:' -e 's/[0-9]*:/code:/'
}

BASH_UNIT="eval FORCE_COLOR=false ../bash_unit"