From a3c1cfbe7bdb513c5239ab4ad1b4be65f7dd2065 Mon Sep 17 00:00:00 2001 From: Salim Date: Mon, 24 Sep 2018 15:49:30 +0200 Subject: [PATCH] Modify README.md for assert_file_(not)executeable --- README.md | 46 +++++++++++++++++++ src/file.bash | 8 ++-- .../52-assert-10-assert_file_executeable.bats | 18 ++++---- ...assert-11-assert_file_not_executeable.bats | 20 ++++---- 4 files changed, 69 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index a22bab3..83d0b9c 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/src/file.bash b/src/file.bash index 3436400..009d8cf 100644 --- a/src/file.bash +++ b/src/file.bash @@ -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 @@ -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 @@ -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 @@ -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" diff --git a/test/52-assert-10-assert_file_executeable.bats b/test/52-assert-10-assert_file_executeable.bats index 76812ad..d837b61 100644 --- a/test/52-assert-10-assert_file_executeable.bats +++ b/test/52-assert-10-assert_file_executeable.bats @@ -4,16 +4,16 @@ load 'test_helper' fixtures 'exist' # Correctness -@test 'assert_file_executeable() : returns 0 if is executable' { +@test 'assert_file_executable() : returns 0 if 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() : returns 1 and displays path if is not executable' { +@test 'assert_file_executable() : returns 1 and displays path if 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 --' ] @@ -22,10 +22,10 @@ fixtures 'exist' } # Transforming path -@test 'assert_file_executeable() : replace prefix of displayed path' { +@test 'assert_file_executable() : 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 --' ] @@ -33,10 +33,10 @@ fixtures 'exist' [ "${lines[2]}" == '--' ] } -@test 'assert_file_executeable() : replace suffix of displayed path' { +@test 'assert_file_executable() : 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 --' ] @@ -44,7 +44,7 @@ fixtures 'exist' [ "${lines[2]}" == '--' ] } -@test 'assert_file_executeable() : replace infix of displayed path' { +@test 'assert_file_executable() : 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" diff --git a/test/52-assert-11-assert_file_not_executeable.bats b/test/52-assert-11-assert_file_not_executeable.bats index 1816538..e88d9cd 100644 --- a/test/52-assert-11-assert_file_not_executeable.bats +++ b/test/52-assert-11-assert_file_not_executeable.bats @@ -4,16 +4,16 @@ load 'test_helper' fixtures 'exist' # Correctness -@test 'assert_file_not_executeable() : returns 0 if is not executable' { +@test 'assert_file_not_executable() : returns 0 if 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() : returns 1 and displays path if is executable' { +@test 'assert_file_not_executable() : returns 1 and displays path if 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" ] @@ -21,30 +21,30 @@ fixtures 'exist' } # Transforming path -@test 'assert_file_not_executeable() : replace prefix of displayed path' { +@test 'assert_file_not_executable() : 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() : replace suffix of displayed path' { +@test 'assert_file_not_executable() : 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() : replace infix of displayed path' { +@test 'assert_file_not_executable() : 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" ]