|
| 1 | +#!/usr/bin/env bats |
| 2 | + |
| 3 | +load ../bats-assertion |
| 4 | + |
| 5 | +@test "assert_equal <expected>, using \$output as <actual> - returns 0 exit code" { |
| 6 | + run bash -c 'echo "abc"' |
| 7 | + run assert_equal "abc" |
| 8 | + |
| 9 | + [ "$status" -eq 0 ] |
| 10 | + |
| 11 | +} |
| 12 | + |
| 13 | +@test "assert_equal <expected>, using \$output as <actual> - returns 1 exit code" { |
| 14 | + run bash -c 'echo "abc"' |
| 15 | + run assert_equal "cba" |
| 16 | + |
| 17 | + [ "$status" -eq 1 ] |
| 18 | + |
| 19 | + local expected="$(cat <<EXPECTED |
| 20 | +Expected: cba |
| 21 | +Actual : abc |
| 22 | +EXPECTED |
| 23 | +)" |
| 24 | + |
| 25 | + [ "$output" = "$expected" ] |
| 26 | + |
| 27 | +} |
| 28 | + |
| 29 | +@test "assert_equal <expected> <actual> - returns 0 exit code" { |
| 30 | + run bash -c 'echo "abc"' |
| 31 | + run assert_equal "abc" "abc" |
| 32 | + |
| 33 | + [ "$status" -eq 0 ] |
| 34 | + |
| 35 | +} |
| 36 | + |
| 37 | +@test "assert_equal <expected> <actual> - returns 1 exit code" { |
| 38 | + run bash -c 'echo "abc"' |
| 39 | + run assert_equal "cba" "abc" |
| 40 | + |
| 41 | + [ "$status" -eq 1 ] |
| 42 | + |
| 43 | + local expected="$(cat <<EXPECTED |
| 44 | +Expected: cba |
| 45 | +Actual : abc |
| 46 | +EXPECTED |
| 47 | +)" |
| 48 | + |
| 49 | + [ "$output" = "$expected" ] |
| 50 | + |
| 51 | +} |
| 52 | + |
| 53 | +@test "assert_equal <expected>, using \$output as <actual> - multi-line format - returns 0 exit code" { |
| 54 | + run bash -c 'echo -e "abc\ndef\nghi"' |
| 55 | + |
| 56 | + local expected="$(cat <<EXPECTED |
| 57 | +abc |
| 58 | +def |
| 59 | +ghi |
| 60 | +EXPECTED |
| 61 | +)" |
| 62 | + |
| 63 | + run assert_equal "$expected" |
| 64 | + |
| 65 | + [ "$status" -eq 0 ] |
| 66 | + |
| 67 | +} |
| 68 | + |
| 69 | +@test "assert_equal <expected>, using \$output as <actual> - multi-line format - returns 1 exit code" { |
| 70 | + run bash -c 'echo -e "abc\ndef\nghi"' |
| 71 | + |
| 72 | + local expected="$(cat <<EXPECTED |
| 73 | +ihg |
| 74 | +fed |
| 75 | +cba |
| 76 | +EXPECTED |
| 77 | +)" |
| 78 | + |
| 79 | + run assert_equal "$expected" |
| 80 | + |
| 81 | + [ "$status" -eq 1 ] |
| 82 | + |
| 83 | + local expected="$(cat <<EXPECTED |
| 84 | +Expected: ihg |
| 85 | +fed |
| 86 | +cba |
| 87 | +Actual : abc |
| 88 | +def |
| 89 | +ghi |
| 90 | +EXPECTED |
| 91 | +)" |
| 92 | + |
| 93 | + [ "$output" = "$expected" ] |
| 94 | + |
| 95 | +} |
| 96 | + |
| 97 | +@test "assert_equal <expected> <actual> - multi-line format - returns 0 exit code" { |
| 98 | + local actual="$(cat <<ACTUAL |
| 99 | +abc |
| 100 | +def |
| 101 | +ghi |
| 102 | +ACTUAL |
| 103 | +)" |
| 104 | + |
| 105 | + run bash -c 'echo -e "$actual"' |
| 106 | + |
| 107 | + local expected="$(cat <<EXPECTED |
| 108 | +abc |
| 109 | +def |
| 110 | +ghi |
| 111 | +EXPECTED |
| 112 | +)" |
| 113 | + |
| 114 | + run assert_equal "$expected" "$actual" |
| 115 | + |
| 116 | + [ "$status" -eq 0 ] |
| 117 | + |
| 118 | +} |
| 119 | + |
| 120 | +@test "assert_equal <expected> <actual> - multi-line format - returns 1 exit code" { |
| 121 | + local actual="$(cat <<ACTUAL |
| 122 | +abc |
| 123 | +def |
| 124 | +ghi |
| 125 | +ACTUAL |
| 126 | +)" |
| 127 | + |
| 128 | + run bash -c 'echo -e "$actual"' |
| 129 | + |
| 130 | + local expected="$(cat <<EXPECTED |
| 131 | +ihg |
| 132 | +fed |
| 133 | +cba |
| 134 | +EXPECTED |
| 135 | +)" |
| 136 | + |
| 137 | + run assert_equal "$expected" "$actual" |
| 138 | + |
| 139 | + [ "$status" -eq 1 ] |
| 140 | + |
| 141 | + local expected="$(cat <<EXPECTED |
| 142 | +Expected: ihg |
| 143 | +fed |
| 144 | +cba |
| 145 | +Actual : abc |
| 146 | +def |
| 147 | +ghi |
| 148 | +EXPECTED |
| 149 | +)" |
| 150 | + |
| 151 | + [ "$output" = "$expected" ] |
| 152 | + |
| 153 | +} |
| 154 | + |
| 155 | +@test "assert_fail_equal <expected>, using \$output as <actual> - returns 0 exit code" { |
| 156 | + run bash -c 'echo "abc"' |
| 157 | + run assert_fail_equal "cba" |
| 158 | + |
| 159 | + [ "$status" -eq 0 ] |
| 160 | + |
| 161 | +} |
| 162 | + |
| 163 | +@test "assert_fail_equal <expected>, using \$output as <actual> - returns 1 exit code" { |
| 164 | + run bash -c 'echo "abc"' |
| 165 | + run assert_fail_equal "abc" |
| 166 | + |
| 167 | + [ "$status" -eq 1 ] |
| 168 | + |
| 169 | + local expected="$(cat <<EXPECTED |
| 170 | +Unexpected: abc |
| 171 | +Actual : abc |
| 172 | +EXPECTED |
| 173 | +)" |
| 174 | + |
| 175 | + [ "$output" = "$expected" ] |
| 176 | + |
| 177 | +} |
| 178 | + |
| 179 | +@test "assert_fail_equal <expected> <actual> - returns 0 exit code" { |
| 180 | + run bash -c 'echo "abc"' |
| 181 | + run assert_fail_equal "cba" "abc" |
| 182 | + |
| 183 | + [ "$status" -eq 0 ] |
| 184 | + |
| 185 | +} |
| 186 | + |
| 187 | +@test "assert_fail_equal <expected> <actual> - returns 1 exit code" { |
| 188 | + run bash -c 'echo "abc"' |
| 189 | + run assert_fail_equal "abc" "abc" |
| 190 | + |
| 191 | + [ "$status" -eq 1 ] |
| 192 | + |
| 193 | + local expected="$(cat <<EXPECTED |
| 194 | +Unexpected: abc |
| 195 | +Actual : abc |
| 196 | +EXPECTED |
| 197 | +)" |
| 198 | + |
| 199 | + [ "$output" = "$expected" ] |
| 200 | + |
| 201 | +} |
| 202 | + |
| 203 | +@test "assert_fail_equal <expected>, using \$output as <actual> - multi-line format - returns 0 exit code" { |
| 204 | + run bash -c 'echo -e "abc\ndef\nghi"' |
| 205 | + |
| 206 | + local expected="$(cat <<EXPECTED |
| 207 | +ihg |
| 208 | +fed |
| 209 | +cba |
| 210 | +EXPECTED |
| 211 | +)" |
| 212 | + |
| 213 | + run assert_fail_equal "$expected" |
| 214 | + |
| 215 | + [ "$status" -eq 0 ] |
| 216 | + |
| 217 | +} |
| 218 | + |
| 219 | +@test "assert_fail_equal <expected>, using \$output as <actual> - multi-line format - returns 1 exit code" { |
| 220 | + run bash -c 'echo -e "abc\ndef\nghi"' |
| 221 | + |
| 222 | + local expected="$(cat <<EXPECTED |
| 223 | +abc |
| 224 | +def |
| 225 | +ghi |
| 226 | +EXPECTED |
| 227 | +)" |
| 228 | + |
| 229 | + run assert_fail_equal "$expected" |
| 230 | + |
| 231 | + [ "$status" -eq 1 ] |
| 232 | + |
| 233 | + local expected="$(cat <<EXPECTED |
| 234 | +Unexpected: abc |
| 235 | +def |
| 236 | +ghi |
| 237 | +Actual : abc |
| 238 | +def |
| 239 | +ghi |
| 240 | +EXPECTED |
| 241 | +)" |
| 242 | + |
| 243 | + [ "$output" = "$expected" ] |
| 244 | + |
| 245 | +} |
| 246 | + |
| 247 | +@test "assert_fail_equal <expected> <actual> - multi-line format - returns 0 exit code" { |
| 248 | + local actual="$(cat <<ACTUAL |
| 249 | +ihg |
| 250 | +fed |
| 251 | +cba |
| 252 | +ACTUAL |
| 253 | +)" |
| 254 | + |
| 255 | + run bash -c 'echo -e "$actual"' |
| 256 | + |
| 257 | + local expected="$(cat <<EXPECTED |
| 258 | +abc |
| 259 | +def |
| 260 | +ghi |
| 261 | +EXPECTED |
| 262 | +)" |
| 263 | + |
| 264 | + run assert_fail_equal "$expected" "$actual" |
| 265 | + |
| 266 | + [ "$status" -eq 0 ] |
| 267 | + |
| 268 | +} |
| 269 | + |
| 270 | +@test "assert_fail_equal <expected> <actual> - multi-line format - returns 1 exit code" { |
| 271 | + local actual="$(cat <<ACTUAL |
| 272 | +abc |
| 273 | +def |
| 274 | +ghi |
| 275 | +ACTUAL |
| 276 | +)" |
| 277 | + |
| 278 | + run bash -c 'echo -e "$actual"' |
| 279 | + |
| 280 | + local expected="$(cat <<EXPECTED |
| 281 | +abc |
| 282 | +def |
| 283 | +ghi |
| 284 | +EXPECTED |
| 285 | +)" |
| 286 | + |
| 287 | + run assert_fail_equal "$expected" "$actual" |
| 288 | + |
| 289 | + [ "$status" -eq 1 ] |
| 290 | + |
| 291 | + local expected="$(cat <<EXPECTED |
| 292 | +Unexpected: abc |
| 293 | +def |
| 294 | +ghi |
| 295 | +Actual : abc |
| 296 | +def |
| 297 | +ghi |
| 298 | +EXPECTED |
| 299 | +)" |
| 300 | + |
| 301 | + [ "$output" = "$expected" ] |
| 302 | + |
| 303 | +} |
| 304 | + |
| 305 | +@test "out of \$output" { |
| 306 | + run assert_equal "" |
| 307 | + |
| 308 | + [ "$status" -eq 0 ] |
| 309 | + |
| 310 | + local expected="$(cat <<EXPECTED |
| 311 | +
|
| 312 | +EXPECTED |
| 313 | +)" |
| 314 | + |
| 315 | + [ "$output" = "$expected" ] |
| 316 | + |
| 317 | +} |
0 commit comments