File: assert_failure.bats

package info (click to toggle)
bats-assert 2.2.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 344 kB
  • sloc: sh: 606; makefile: 4
file content (94 lines) | stat: -rwxr-xr-x 1,893 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
#!/usr/bin/env bats

load test_helper

@test "assert_failure(): returns 0 if \`\$status' is not 0" {
  run false
  run assert_failure
  assert_test_pass
}

@test "assert_failure(): returns 1 and displays details if \`\$status' is 0" {
  run bash -c 'echo "a"
               exit 0'
  run assert_failure

  assert_test_fail <<'ERR_MSG'

-- command succeeded, but it was expected to fail --
output : a
--
ERR_MSG
}

@test "assert_failure(): returns 1 and displays \`\$stderr' if it is set" {
  bats_require_minimum_version 1.5.0
	run --separate-stderr \
			bash -c 'echo "a"
							 echo "b" >&2
							 exit 0'
  echo "Stderr: $stderr" >&3
	run assert_failure

	assert_test_fail <<'ERR_MSG'

-- command succeeded, but it was expected to fail --
output : a
stderr : b
--
ERR_MSG
}

@test "assert_failure(): displays \`\$output' in multi-line format if it is longer then one line" {
  run bash -c 'printf "a 0\na 1"
               exit 0'
  run assert_failure

  assert_test_fail <<'ERR_MSG'

-- command succeeded, but it was expected to fail --
output (2 lines):
  a 0
  a 1
--
ERR_MSG
}

@test "assert_failure() <status>: returns 0 if \`\$status' equals <status>" {
  run bash -c 'exit 1'
  run assert_failure 1
  assert_test_pass
}

@test "assert_failure() <status>: returns 1 and displays details if \`\$status' does not equal <status>" {
  run bash -c 'echo "a"
               exit 1'
  run assert_failure 2

  assert_test_fail <<'ERR_MSG'

-- command failed as expected, but status differs --
expected : 2
actual   : 1
output   : a
--
ERR_MSG
}

@test "assert_failure() <status>: displays \`\$output' in multi-line format if it is longer then one line" {
  run bash -c 'printf "a 0\na 1"
               exit 1'
  run assert_failure 2

  assert_test_fail <<'ERR_MSG'

-- command failed as expected, but status differs --
expected : 2
actual   : 1
output (2 lines):
  a 0
  a 1
--
ERR_MSG
}