Skip to content

Commit

Permalink
Merge branch 'master' into assert_symlink_to
Browse files Browse the repository at this point in the history
  • Loading branch information
SalimHouari authored Nov 15, 2018
2 parents 777a9e6 + ddc08e1 commit 6bc8d86
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).


## [0.3.0] - 2018-10-28

### Added

- Added assert_files_equal assert_files_not_equal functions!
- Added 2 test scripts for assert_files_equal assert_files_not_equal


## [0.2.0] - 2016-12-07

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ path1 : /path/to/file
path2 : /path/to/same_file
--
```

### `assert_symlink_to`
Fail if the given file is not a symbolic to a defined target.
```bash
Expand All @@ -222,7 +223,6 @@ path : /path/to/symlink
--
```
### `assert_file_not_exist`
Fail if the given file or directory exists.
Expand Down
1 change: 0 additions & 1 deletion src/file.bash
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ RESULT=$PHYS_DIR/$TARGET_FILE
echo $RESULT
}


if [ ! -L $link ]; then
local -r rem="$BATSLIB_FILE_PATH_REM"
local -r add="$BATSLIB_FILE_PATH_ADD"
Expand Down
83 changes: 83 additions & 0 deletions test/58-assert-10-assert_equal_files.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env bats

load 'test_helper'
fixtures 'exist'

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


@test 'assert_files_equal() <file>: returns 1 if <file1> and <file2> are not the same' {
local -r file1="${TEST_FIXTURE_ROOT}/dir/same_file_with_text"
local -r file2="${TEST_FIXTURE_ROOT}/dir/file"
run assert_files_equal "$file1" "$file2"

[ "$status" -eq 1 ]
[ "${#lines[@]}" -eq 4 ]
[ "${lines[0]}" == '-- files are not the same --' ]
[ "${lines[1]}" == "path : $file1" ]
[ "${lines[2]}" == "path : $file2" ]
[ "${lines[3]}" == "--" ]
}

# Transforming path
@test 'assert_files_equal() <file>: 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_equal "$file1" "$file2"
[ "$status" -eq 1 ]
[ "${#lines[@]}" -eq 5 ]
[ "${lines[0]}" == "cmp: ${TEST_FIXTURE_ROOT}/dir: Is a directory" ]
[ "${lines[1]}" == "-- files are not the same --" ]
[ "${lines[2]}" == "path : $file1" ]
[ "${lines[3]}" == "path : $file2" ]
[ "${lines[4]}" == "--" ]
}

@test 'assert_files_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"
local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}"
local -r BATSLIB_FILE_PATH_ADD='..'
run assert_files_equal "$file1" "$file2"
[ "$status" -eq 1 ]
[ "${#lines[@]}" -eq 4 ]
[ "${lines[0]}" == '-- files are not the same --' ]
[ "${lines[1]}" == "path : ../dir/file" ]
[ "${lines[2]}" == "path : ../dir/same_file_with_text" ]
[ "${lines[3]}" == "--" ]
}

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

@test 'assert_files_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"
local -r BATSLIB_FILE_PATH_REM='dir'
local -r BATSLIB_FILE_PATH_ADD='..'
run assert_files_equal "$file1" "$file2"
[ "$status" -eq 1 ]
[ "${#lines[@]}" -eq 4 ]
[ "${lines[0]}" == '-- files are not the same --' ]
[ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/../file" ]
[ "${lines[2]}" == "path : ${TEST_FIXTURE_ROOT}/../same_file_with_text" ]
[ "${lines[3]}" == "--" ]
}
78 changes: 78 additions & 0 deletions test/58-assert-11-assert_not_equal_files.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env bats

load 'test_helper'
fixtures 'exist'

# 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 ]
[ "${lines[0]}" == "cmp: ${TEST_FIXTURE_ROOT}/dir: Is a directory" ]
}

@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]}" == "--" ]
}
8 changes: 8 additions & 0 deletions test/fixtures/exist/dir/file_with_text
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sesetsetasdfasfdjlsakjdfklasjd
sldkfjaslkdfjasdkfj
slkdfjhaskldfjhlakshdfklasjdfh
sdkfjhslkjfhsdlkjhfg
lksajdfklöjsafkljsadafsjflkjdf
sadfasfsad
sadfasfdsadsfasdfasf

8 changes: 8 additions & 0 deletions test/fixtures/exist/dir/same_file_with_text
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sesetsetasdfasfdjlsakjdfklasjd
sldkfjaslkdfjasdkfj
slkdfjhaskldfjhlakshdfklasjdfh
sdkfjhslkjfhsdlkjhfg
lksajdfklöjsafkljsadafsjflkjdf
sadfasfsad
sadfasfdsadsfasdfasf

0 comments on commit 6bc8d86

Please sign in to comment.