Skip to content

Commit

Permalink
feat(tests): Improve test setup for better isolation
Browse files Browse the repository at this point in the history
This commit enhances the setup process of our tests to ensure they run in a more isolated environment. This is achieved by changing the current directory to the one containing the test file before executing it.

Changes:
- In `gsht.bats`, added a command to change the current directory to that of the test file.
- Also in `gsht.bats`, moved gsht.sh execution into a subshell to prevent side effects on the global environment.
- In `input.bats`, added similar code to change working directory, ensuring all tests run from their respective directories.
  • Loading branch information
NekoOs committed Aug 27, 2024
1 parent d9cb80b commit 8febf39
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/gsht.bats
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/env bats

setup_file() {
cd "$(dirname "$BATS_TEST_FILENAME")" || exit

(cd ../src && ./gsht.sh gsht.sh --output "$BATS_RUN_TMPDIR/gsht")

chmod +x "$BATS_RUN_TMPDIR/gsht"
}

Expand Down
4 changes: 4 additions & 0 deletions tests/input.bats
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bats

setup_file() {
cd "$(dirname "$BATS_TEST_FILENAME")" || exit
}

input() {
source ../src/input.sh "$@"

Expand Down

0 comments on commit 8febf39

Please sign in to comment.