Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix temp del #31

Merged
merged 5 commits into from
Mar 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@ on:

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
os: ['macos-10.15', 'ubuntu-latest']
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- run: ./script/install-bats.sh
- run: git clone --depth 1 https://github.com/bats-core/bats-support ../bats-support
- run: bats test
# set PATh to ensure we use bats from our local installation (looking at you Mac Runner!)
- name: bats test
run: |
PATH="$HOME/.local/bin:$PATH"
bats -v
bats test
2 changes: 1 addition & 1 deletion src/temp.bash
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ temp_del() {

# Delete directory.
local result
result="$(rm -r -- "$path" 2>&1)"
result="$(rm -r -- "$path" 2>&1 </dev/null)"
if (( $? )); then
echo "$result" \
| batslib_decorate 'ERROR: temp_del' \
Expand Down
14 changes: 14 additions & 0 deletions test/70-temp-11-temp_del.bats
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ fixtures 'temp'
[ ! -e "$TEST_TEMP_DIR" ]
}

@test 'temp_del() <path>: works even if wrote-protected file/directory exists within' {
TEST_TEMP_DIR="$(temp_make)"
touch $TEST_TEMP_DIR/nowritefile
chmod -w $TEST_TEMP_DIR/nowritefile
mkdir -p $TEST_TEMP_DIR/nowritefolder
chmod -w $TEST_TEMP_DIR/nowritefolder

run temp_del "$TEST_TEMP_DIR"

[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 0 ]
[ ! -e "$TEST_TEMP_DIR" ]
}

@test 'temp_del() <path>: returns 1 and displays an error message if <path> can not be deleted' {
local -r path="${TEST_FIXTURE_ROOT}/does/not/exist"
run temp_del "$path"
Expand Down