File: 58-assert-11-assert_not_equal_files.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 (86 lines) | stat: -rw-r--r-- 3,276 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
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
#!/usr/bin/env bats

load 'test_helper'
fixtures 'exist'

setup () {
 touch ${TEST_FIXTURE_ROOT}/dir/file_with_text ${TEST_FIXTURE_ROOT}/dir/same_file_with_text 
}
teardown () {
    rm -f ${TEST_FIXTURE_ROOT}/dir/file_with_text ${TEST_FIXTURE_ROOT}/dir/same_file_with_text
}

# Correctness
@test 'assert_files_not_equal() <file1> <file2>: returns 0 if <file1> and <file2> are not the same' {
  local -r file1="${TEST_FIXTURE_ROOT}/dir/file_with_text"
  local -r file2="${TEST_FIXTURE_ROOT}/dir/file"
  run assert_files_not_equal "$file1" "$file2"
  [ "$status" -eq 0 ]
  [ "${#lines[@]}" -eq 0 ]
}


@test 'assert_files_not_equal() <file1> <file2>: returns 1 if <file1> and <file2> are the same' {
  local -r file1="${TEST_FIXTURE_ROOT}/dir/same_file_with_text"
  local -r file2="${TEST_FIXTURE_ROOT}/dir/file_with_text"
  run assert_files_not_equal "$file1" "$file2"
  [ "$status" -eq 1 ]
  [ "${#lines[@]}" -eq 4 ]
  [ "${lines[0]}" == '-- files are the same --' ]
  [ "${lines[1]}" == "path : $file1" ]
  [ "${lines[2]}" == "path : $file2" ]
  [ "${lines[3]}" == "--" ]
}

# Transforming path
@test 'assert_files_not_equal() <file1> <file2>: used <file2> as a directory' {
  local -r file2="${TEST_FIXTURE_ROOT}/dir/same_file_with_text"
  local -r file1="${TEST_FIXTURE_ROOT}/dir"
  run assert_files_not_equal "$file1" "$file2"
  [ "$status" -eq 0 ]
  [ "${#lines[@]}" -eq 1 ]
  REGEX="cmp: ${TEST_FIXTURE_ROOT}/dir: (Is a directory|I/O error)"
  [[ "${lines[0]}" =~ $REGEX ]] || false
}

@test 'assert_files_not_equal() <file>: replace prefix of displayed path' {
  local -r file2="${TEST_FIXTURE_ROOT}/dir/same_file_with_text"
  local -r file1="${TEST_FIXTURE_ROOT}/dir/file_with_text"
  local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}"
  local -r BATSLIB_FILE_PATH_ADD='..'
  run assert_files_not_equal "$file1" "$file2"
  [ "$status" -eq 1 ]
  [ "${#lines[@]}" -eq 4 ]
  [ "${lines[0]}" == '-- files are the same --' ]
  [ "${lines[1]}" == "path : ../dir/file_with_text" ]
  [ "${lines[2]}" == "path : ../dir/same_file_with_text" ]
  [ "${lines[3]}" == "--" ]
}

@test 'assert_files_not_equal() <file>: replace suffix of displayed path' {
  local -r file2="${TEST_FIXTURE_ROOT}/dir/same_file_with_text"
  local -r file1="${TEST_FIXTURE_ROOT}/dir/file_with_text"
  local -r BATSLIB_FILE_PATH_REM='%same_file_with_text'
  local -r BATSLIB_FILE_PATH_ADD='..'
  run assert_files_not_equal "$file1" "$file2"
  [ "$status" -eq 1 ]
  [ "${#lines[@]}" -eq 4 ]
  [ "${lines[0]}" == '-- files are the same --' ]
  [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/dir/file_with_text" ]
  [ "${lines[2]}" == "path : ${TEST_FIXTURE_ROOT}/dir/.." ]
  [ "${lines[3]}" == "--" ]
}

@test 'assert_files_not_equal() <file>: replace infix of displayed path' {
  local -r file2="${TEST_FIXTURE_ROOT}/dir/same_file_with_text"
  local -r file1="${TEST_FIXTURE_ROOT}/dir/file_with_text"
  local -r BATSLIB_FILE_PATH_REM='dir'
  local -r BATSLIB_FILE_PATH_ADD='..'
  run assert_files_not_equal "$file1" "$file2"
  [ "$status" -eq 1 ]
  [ "${#lines[@]}" -eq 4 ]
  [ "${lines[0]}" == '-- files are the same --' ]
  [ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/../file_with_text" ]
  [ "${lines[2]}" == "path : ${TEST_FIXTURE_ROOT}/../same_file_with_text" ]
  [ "${lines[3]}" == "--" ]
}