Skip to content

Commit

Permalink
Modify README.md for assert_file_(not)executeable
Browse files Browse the repository at this point in the history
  • Loading branch information
SalimHouari committed Sep 24, 2018
1 parent bead629 commit a3c1cfb
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 23 deletions.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,33 @@ path : /path/to/non-existent-fifo-file
--
```


### `assert_file_executable`

Fail if the given file is not executable.

```bash
@test 'assert_file_executable() {
assert_file_executable /path/to/executable-file
}
```
On failure, the path is displayed.
```
-- file is not executable --
path : /path/to/executable-file
--
```
### `assert_file_not_exist`
Fail if the given file or directory exists.
```bash
@test 'assert_file_not_exist() {
assert_file_not_exist /path/to/existing-file
Expand Down Expand Up @@ -297,6 +320,29 @@ path : /path/to/existing-fifo-file
--
```


### `assert_file_not_executable`

Fail if the given file is executable.

```bash
@test 'assert_file_not_executable() {
assert_file_not_executable /path/to/executable-file
}
```
On failure, the path is displayed.
```
-- file is executable --
path : /path/to/executable-file
--
```
## Working with temporary directories
When testing code that manipulates the filesystem, it is good practice
Expand Down
8 changes: 4 additions & 4 deletions src/file.bash
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ assert_fifo_exist() {


# Fail and display path of the named file if it is not executable.
# This function is the logical complement of `assert_file_not_executeable'.
# This function is the logical complement of `assert_file_not_executable'.
#
# Globals:
# BATSLIB_FILE_PATH_REM
Expand All @@ -231,7 +231,7 @@ assert_fifo_exist() {
# 1 - otherwise
# Outputs:
# STDERR - details, on failure
assert_file_executeable() {
assert_file_executable() {

local -r file="$1"
if [[ ! -x "$file" ]]; then
Expand Down Expand Up @@ -456,7 +456,7 @@ assert_fifo_not_exist() {


# Fail and display path of the named file if it is executable. This
# function is the logical complement of `assert_file_executeable'.
# function is the logical complement of `assert_file_executable'.
#
# Globals:
# BATSLIB_FILE_PATH_REM
Expand All @@ -468,7 +468,7 @@ assert_fifo_not_exist() {
# 1 - otherwise
# Outputs:
# STDERR - details, on failure
assert_file_not_executeable() {
assert_file_not_executable() {
local -r file="$1"
if [[ -x "$file" ]]; then
local -r rem="$BATSLIB_FILE_PATH_REM"
Expand Down
18 changes: 9 additions & 9 deletions test/52-assert-10-assert_file_executeable.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ load 'test_helper'
fixtures 'exist'

# Correctness
@test 'assert_file_executeable() <file>: returns 0 if <file> is executable' {
@test 'assert_file_executable() <file>: returns 0 if <file> is executable' {
local -r file="${TEST_FIXTURE_ROOT}/dir/execfile"
run assert_file_executeable "$file"
run assert_file_executable "$file"
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 0 ]
}

@test 'assert_file_executeable() <file>: returns 1 and displays path if <file> is not executable' {
@test 'assert_file_executable() <file>: returns 1 and displays path if <file> is not executable' {
local -r file="${TEST_FIXTURE_ROOT}/dir/file"
run assert_file_executeable "$file"
run assert_file_executable "$file"
[ "$status" -eq 1 ]
[ "${#lines[@]}" -eq 3 ]
[ "${lines[0]}" == '-- file is not executable --' ]
Expand All @@ -22,29 +22,29 @@ fixtures 'exist'
}

# Transforming path
@test 'assert_file_executeable() <file>: replace prefix of displayed path' {
@test 'assert_file_executable() <file>: replace prefix of displayed path' {
local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}"
local -r BATSLIB_FILE_PATH_ADD='..'
run assert_file_executeable "${TEST_FIXTURE_ROOT}/nodir"
run assert_file_executable "${TEST_FIXTURE_ROOT}/nodir"
[ "$status" -eq 1 ]
[ "${#lines[@]}" -eq 3 ]
[ "${lines[0]}" == '-- file is not executable --' ]
[ "${lines[1]}" == "path : ../nodir" ]
[ "${lines[2]}" == '--' ]
}

@test 'assert_file_executeable() <file>: replace suffix of displayed path' {
@test 'assert_file_executable() <file>: replace suffix of displayed path' {
local -r BATSLIB_FILE_PATH_REM='%file.does_not_exist'
local -r BATSLIB_FILE_PATH_ADD='..'
run assert_file_executeable "${TEST_FIXTURE_ROOT}/nodir"
run assert_file_executable "${TEST_FIXTURE_ROOT}/nodir"
[ "$status" -eq 1 ]
[ "${#lines[@]}" -eq 3 ]
[ "${lines[0]}" == '-- file is not executable --' ]
[ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/nodir" ]
[ "${lines[2]}" == '--' ]
}

@test 'assert_file_executeable() <file>: replace infix of displayed path' {
@test 'assert_file_executable() <file>: replace infix of displayed path' {
local -r BATSLIB_FILE_PATH_REM='nodir'
local -r BATSLIB_FILE_PATH_ADD='..'
run assert_file_exist "${TEST_FIXTURE_ROOT}/nodir"
Expand Down
20 changes: 10 additions & 10 deletions test/52-assert-11-assert_file_not_executeable.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,47 @@ load 'test_helper'
fixtures 'exist'

# Correctness
@test 'assert_file_not_executeable() <file>: returns 0 if <file> is not executable' {
@test 'assert_file_not_executable() <file>: returns 0 if <file> is not executable' {
local -r file="${TEST_FIXTURE_ROOT}/dir/noexecfile"
run assert_file_not_executeable "$file"
run assert_file_not_executable "$file"
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 0 ]
}

@test 'assert_file_not_executeable() <file>: returns 1 and displays path if <file> is executable' {
@test 'assert_file_not_executable() <file>: returns 1 and displays path if <file> is executable' {
local -r file="${TEST_FIXTURE_ROOT}/dir/execfile"
run assert_file_not_executeable "$file"
run assert_file_not_executable "$file"
[ "$status" -eq 1 ]
[ "${#lines[@]}" -eq 3 ]
[ "${lines[1]}" == "path : $file" ]
[ "${lines[2]}" == '--' ]
}

# Transforming path
@test 'assert_file_not_executeable() <file>: replace prefix of displayed path' {
@test 'assert_file_not_executable() <file>: replace prefix of displayed path' {
local -r BATSLIB_FILE_PATH_REM="#${TEST_FIXTURE_ROOT}"
local -r BATSLIB_FILE_PATH_ADD='..'
run assert_file_not_executeable "${TEST_FIXTURE_ROOT}/dir/execfile"
run assert_file_not_executable "${TEST_FIXTURE_ROOT}/dir/execfile"
[ "$status" -eq 1 ]
[ "${#lines[@]}" -eq 3 ]
[ "${lines[1]}" == "path : ../dir/execfile" ]
[ "${lines[2]}" == '--' ]
}

@test 'assert_file_not_executeable() <file>: replace suffix of displayed path' {
@test 'assert_file_not_executable() <file>: replace suffix of displayed path' {
local -r BATSLIB_FILE_PATH_REM='%file'
local -r BATSLIB_FILE_PATH_ADD='..'
run assert_file_not_executeable "${TEST_FIXTURE_ROOT}/dir"
run assert_file_not_executable "${TEST_FIXTURE_ROOT}/dir"
[ "$status" -eq 1 ]
[ "${#lines[@]}" -eq 3 ]
[ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/dir" ]
[ "${lines[2]}" == '--' ]
}

@test 'assert_file_not_executeable() <file>: replace infix of displayed path' {
@test 'assert_file_not_executable() <file>: replace infix of displayed path' {
local -r BATSLIB_FILE_PATH_REM='dir'
local -r BATSLIB_FILE_PATH_ADD='..'
run assert_file_not_executeable "${TEST_FIXTURE_ROOT}/dir/execfile"
run assert_file_not_executable "${TEST_FIXTURE_ROOT}/dir/execfile"
[ "$status" -eq 1 ]
[ "${#lines[@]}" -eq 3 ]
[ "${lines[1]}" == "path : ${TEST_FIXTURE_ROOT}/../execfile" ]
Expand Down

0 comments on commit a3c1cfb

Please sign in to comment.