Skip to content

Conversation

@jnasbyupgrade
Copy link

Fixes #1132

Problem

When using --gather-test-outputs-in with a relative path, if a test changes directory using cd, the cp command fails with "No such file or directory" because relative paths become invalid when the current working directory changes.

Solution

Convert relative paths to absolute paths when processing the --gather-test-outputs-in option in the bats script, ensuring the path remains valid regardless of directory changes within tests.

Also add a defensive check to ensure BATS_OUT exists before copying, preventing errors if a test produces no output.

Changes

  • libexec/bats-core/bats: Convert relative output directory paths to absolute paths
  • libexec/bats-core/bats-exec-test: Check BATS_OUT exists before copying
  • test/fixtures/bats/cd_in_test.bats: Add test fixture that changes directory
  • test/bats.bats: Add test case to verify fix works with relative paths

Testing

  • ✅ Test passes with relative paths when tests change directory
  • ✅ Test passes with absolute paths (backward compatible)
  • ✅ Existing tests continue to pass

Fixes bats-core#1132

Convert relative paths to absolute when processing --gather-test-outputs-in
to ensure paths remain valid when tests change directory with 'cd'.

Also add defensive check for BATS_OUT existence before copying.
@jnasbyupgrade jnasbyupgrade force-pushed the fix-gather-test-outputs-in-cd-issue branch from a60f921 to 509e2d7 Compare January 5, 2026 21:16
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

Successfully merging this pull request may close these issues.

gather-test-outputs-in fails if test cd's somewhere

1 participant