|
| 1 | +#!/usr/bin/env bats |
| 2 | +load 'test_helper' |
| 3 | +fixtures 'empty' |
| 4 | +# Correctness |
| 5 | +@test 'assert_file_not_contains() <file>: returns 0 and displays content if <file> does not match string' { |
| 6 | + local -r file="${TEST_FIXTURE_ROOT}/dir/non-empty-file" |
| 7 | + run assert_file_not_contains "$file" "XXX" |
| 8 | + [ "$status" -eq 0 ] |
| 9 | +} |
| 10 | +@test 'assert_file_not_contains() <file>: returns 1 and displays content if <file> does match string' { |
| 11 | + local -r file="${TEST_FIXTURE_ROOT}/dir/non-empty-file" |
| 12 | + run assert_file_not_contains "$file" "Not empty" |
| 13 | + [ "$status" -eq 1 ] |
| 14 | +} |
| 15 | +# Transforming path |
| 16 | +@test 'assert_file_not_contains() <file>: replace prefix of displayed path' { |
| 17 | + local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}" |
| 18 | + local -r BATSLIB_FILE_PATH_ADD='..' |
| 19 | + run assert_file_not_contains "${TEST_FIXTURE_ROOT}/dir/non-empty-file" "Not empty" |
| 20 | + [ "$status" -eq 1 ] |
| 21 | +} |
| 22 | +@test 'assert_file_not_contains() <file>: replace suffix of displayed path' { |
| 23 | + local -r BATSLIB_FILE_PATH_REM='%non-empty-file' |
| 24 | + local -r BATSLIB_FILE_PATH_ADD='..' |
| 25 | + run assert_file_not_contains "${TEST_FIXTURE_ROOT}/dir/non-empty-file" "Not empty" |
| 26 | + [ "$status" -eq 1 ] |
| 27 | +} |
| 28 | +@test 'assert_file_not_contains() <file>: replace infix of displayed path' { |
| 29 | + local -r BATSLIB_FILE_PATH_REM='dir' |
| 30 | + local -r BATSLIB_FILE_PATH_ADD='..' |
| 31 | + run assert_file_not_contains "${TEST_FIXTURE_ROOT}/dir/non-empty-file" "Not empty" |
| 32 | + [ "$status" -eq 1 ] |
| 33 | +} |
| 34 | +@test 'assert_file_not_contains() <file>: show missing regex in case of failure' { |
| 35 | + local -r file="${TEST_FIXTURE_ROOT}/dir/non-empty-file" |
| 36 | + run assert_file_not_contains "$file" "Not empty" |
| 37 | + [ "$status" -eq 1 ] |
| 38 | + [ "${#lines[@]}" -eq 4 ] |
| 39 | + [ "${lines[0]}" == '-- file contains regex --' ] |
| 40 | + [ "${lines[1]}" == "path : $file" ] |
| 41 | + [ "${lines[2]}" == "regex : Not empty" ] |
| 42 | + [ "${lines[3]}" == '--' ] |
| 43 | +} |
| 44 | +@test 'assert_file_not_contains() <file>: returns 1 and displays path if <file> does not exist' { |
| 45 | + local -r file="${TEST_FIXTURE_ROOT}/missing" |
| 46 | + run assert_file_not_contains "$file" "XXX" |
| 47 | + [ "$status" -eq 1 ] |
| 48 | + [ "${#lines[@]}" -eq 4 ] |
| 49 | + [ "${lines[0]}" == '-- file does not exist --' ] |
| 50 | + [ "${lines[1]}" == "path : $file" ] |
| 51 | + [ "${lines[2]}" == "regex : XXX" ] |
| 52 | + [ "${lines[3]}" == '--' ] |
| 53 | +} |
0 commit comments