-
Couldn't load subscription status.
- Fork 450
Fix BATS_ROOT resolution when /bin => /usr/bin #115
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
Conversation
Closes #113. This should be robust enough to handle the /bin => /usr/bin symlink on CentOS7 as originally reported, but any manner of symlink chains leading to the `bin/bats` executable in the installation directory. Maintains portability between `readlink` implementations by not relying on the GNU-specific `-e` option. There's no perceptible performance impact. This renames the original `bats_absolute_path` function to the more obvious `bats_resolve_absolute_root_dir`, and introduces the `BATS_MAX_SYMLINKS` variable to ensure symlink resolution short-circuits in case cycles appear. While this can be user-controlled, I've not documented it in the README, hoping that no one will need to change the setting in a real-world situation. Also tweaks the value of `BATS_TEST_SUITE_TMPDIR` from `tmp` to `bats-test-tmp` to avoid potential collisions with other `BATS_TMPDIR` directories.
I realized that the `while [[ -L "$PWD" && "$((--limit))" -ne -1 ]]` loop could drop `limit` to `-1` before reaching the following check for `[[ "$((--limit))" -ne -1 ]]`. Added the "parent directories exhaust BATS_MAX_SYMLINKS" test case to reproduce, which didn't cause an infinite loop, but failed when `cd`-ing to `/usr/bin` terminated the inner loop, causing `/usr/libexec/bats-core/bin/bats` not to be found. Also added the "find BATS_ROOT without symlinks" test case to ensure the loop executes correctly when `bin/bats` is executed directly, and added `BATS_MAX_SYMLINKS=8` to "set BATS_ROOT with extreme symlink resolution" to make sure the test traverses the exact number of expected symlinks.
Meant to remove this before the previous commit.
I realized that if the `bin/bats` script is executing, the operating system has already traversed all the symbolic links to it, so enforcing our own threshold is pointless.
|
Whoops... I realized that if the |
Today I learned about the `set -P` option, which causes `cd` to set `PWD` to the physical directory, containing no symlinks. This eliminated the need for the inner `while` loop to resolve `PWD` symlinks. The Bash man page wording is a little confusing, but there's a great example demonstrating the option at: https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html The result is the same, but subshells are only spawned to resolve target_name links, making the code a little smaller and improving the performance ever-so-slightly.
Should've been preserved by the previous commit.
|
And today I learned about |
Should've tried this two commits ago. Verified manually that Bash parses the options to `set` in order, such that you can safely disable and renable an option in the same invocation.
|
Whoops, I posted this to #113 yesterday, meant to post it here: @bats-core/bats-core barring any suggestions/objections, I'll look to merge this by tomorrow. |
Bats 1.1.0 - 2018-07-08 This is the first release with new features relative to the original Bats 0.4.0. Added: * The `-r, --recursive` flag to scan directory arguments recursively for `*.bats` files (bats-core#109) * The `contrib/rpm/bats.spec` file to build RPMs (bats-core#111) Changed: * Travis exercises latest versions of Bash from 3.2 through 4.4 (bats-core#116, bats-core#117) * Error output highlights invalid command line options (bats-core#45, bats-core#46, bats-core#118) * Replaced `echo` with `printf` (bats-core#120) Fixed: * Fixed `BATS_ERROR_STATUS` getting lost when `bats_error_trap` fired multiple times under Bash 4.2.x (bats-core#110) * Updated `bin/bats` symlink resolution, handling the case on CentOS where `/bin` is a symlink to `/usr/bin` (bats-core#113, bats-core#115)
Closes #113. This should be robust enough to handle the /bin => /usr/bin symlink on CentOS7 as originally reported, as well as any manner of symlink chains leading to the
bin/batsexecutable in the installation directory. Maintains portability betweenreadlinkimplementations by not relying on the GNU-specific-eoption.There's no perceptible performance impact.
This renames the original
bats_absolute_pathfunction to the more obviousbats_resolve_absolute_root_dir, and introduces theBATS_MAX_SYMLINKSvariable to ensure symlink resolution short-circuits in case cycles appear. While this can be user-controlled, I've not documented it in the README, hoping that no one will need to change the setting in a real-world situation.Also tweaks the value of
BATS_TEST_SUITE_TMPDIRfromtmptobats-test-tmpto avoid potential collisions with otherBATS_TMPDIRdirectories.cc: @rgm3