Skip to content

temp_del waits for user's input when trying to remove write-protected file #71

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

Open
meleu opened this issue Mar 23, 2025 · 0 comments
Open

Comments

@meleu
Copy link

meleu commented Mar 23, 2025

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:

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-support

Create 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant