File: 68-assert-10-assert_file_empty.bats

package info (click to toggle)
bats-file 0.3.0%2Bgit20230131-gbba751f-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 408 kB
  • sloc: sh: 566; makefile: 2
file content (54 lines) | stat: -rw-r--r-- 2,113 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env bats
load 'test_helper'
fixtures 'empty'
# Correctness
@test 'assert_file_empty() <file>: returns 0 if <file> empty' {
  local -r file="${TEST_FIXTURE_ROOT}/dir/empty-file"
  run assert_file_empty "$file"
  [ "$status" -eq 0 ]
  [ "${#lines[@]}" -eq 0 ]
}
@test 'assert_file_empty() <file>: returns 1 and displays content if <file> is not empty' {
  local -r file="${TEST_FIXTURE_ROOT}/dir/non-empty-file"
  run assert_file_empty "$file"
  [ "$status" -eq 1 ]
  [ "${#lines[@]}" -eq 4 ]
  [ "${lines[0]}" == '-- file is not empty --' ]
  [ "${lines[1]}" == "path     : ${TEST_FIXTURE_ROOT}/dir/non-empty-file" ]
  [ "${lines[2]}" == 'output   : Not empty' ]
  [ "${lines[3]}" == '--' ]
}
# Transforming path
@test 'assert_file_empty() <file>: replace prefix of displayed path' {
  local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}"
  local -r BATSLIB_FILE_PATH_ADD='..'
  run assert_file_empty "${TEST_FIXTURE_ROOT}/dir/non-empty-file"
  [ "$status" -eq 1 ]
  [ "${#lines[@]}" -eq 4 ]
  [ "${lines[0]}" == '-- file is not empty --' ]
  [ "${lines[1]}" == "path     : ../dir/non-empty-file" ]
  [ "${lines[2]}" == 'output   : Not empty' ]
  [ "${lines[3]}" == '--' ]
}
@test 'assert_file_empty() <file>: replace suffix of displayed path' {
  local -r BATSLIB_FILE_PATH_REM='%non-empty-file'
  local -r BATSLIB_FILE_PATH_ADD='..'
  run assert_file_empty "${TEST_FIXTURE_ROOT}/dir/non-empty-file"
  [ "$status" -eq 1 ]
  [ "${#lines[@]}" -eq 4 ]
  [ "${lines[0]}" == '-- file is not empty --' ]
  [ "${lines[1]}" == "path     : ${TEST_FIXTURE_ROOT}/dir/.." ]
  [ "${lines[2]}" == 'output   : Not empty' ]
  [ "${lines[3]}" == '--' ]
}
@test 'assert_file_empty() <file>: replace infix of displayed path' {
  local -r BATSLIB_FILE_PATH_REM='dir'
  local -r BATSLIB_FILE_PATH_ADD='..'
  run assert_file_empty "${TEST_FIXTURE_ROOT}/dir/non-empty-file"
  [ "$status" -eq 1 ]
  [ "${#lines[@]}" -eq 4 ]
  [ "${lines[0]}" == '-- file is not empty --' ]
  [ "${lines[1]}" == "path     : ${TEST_FIXTURE_ROOT}/../non-empty-file" ]
  [ "${lines[2]}" == 'output   : Not empty' ]
  [ "${lines[3]}" == '--' ]
}