forked from ztombol/bats-file
-
Notifications
You must be signed in to change notification settings - Fork 37
Open
Description
Issue
I faced a scenario where my test was stuck, and after a Ctrl+C I noticed it was happening because the rm command in temp_del was waiting for user's input.
Specifically this line:
Line 174 in c0e3a26
| if ! result="$(rm -r -- "$path" 2>&1 >/dev/null )"; then |
I'm wondering if we should use rm -rf here (which probably requires extra care).
Using --interactive=never would be The Perfect™ solution, but I'm afraid it's not portable (GNU coreutils only).
Expected behavior
Given the fact that temp_del is supposed to be used programatically (never in an interactive session), it should never wait for user's input (it should either succeed or fail).
Steps to reproduce
Start a dummy project:
mkdir -p deleteme/test
cd deleteme
git init
git submodule add \
https://github.com/bats-core/bats-file.git \
test/test_helper/bats-file
git submodule add \
https://github.com/bats-core/bats-support.git \
test/test_helper/bats-supportCreate a sample.bats like this:
setup() {
load 'test/test_helper/bats-support/load'
load 'test/test_helper/bats-file/load'
TEST_TEMP_DIR="$(temp_make)"
}
teardown() {
temp_del "${TEST_TEMP_DIR}"
}
@test "temp_del waits for user input" {
cd "${TEST_TEMP_DIR}"
mkdir my_dir
chmod a=r my_dir
}Run the test and see it getting stuck.
$ bats sample.bats
sample.bats
temp_del waits for user input # 👈 Hit Ctrl+C
✗ temp_del waits for user input
(from function `temp_del' in file test/test_helper/bats-file/src/temp.bash, line 1,
from function `teardown' in test file sample.bats, line 11)
`temp_del "${TEST_TEMP_DIR}"' failed
-- ERROR: temp_del --
rm: remove write-protected directory '/tmp/sample.bats-1-YgMpb7/my_dir'?
--
Received SIGINT, aborting ...
1 test, 1 failure
Metadata
Metadata
Assignees
Labels
No labels