-
Notifications
You must be signed in to change notification settings - Fork 442
Emit correct trace after calling exported function #87
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 #34. Incorporates the test code from that PR. This fixes a problem whereby invoking an exported function within a test script would result in an incorrect stack trace. It does this by using `BATS_TEST_SOURCE` to capture a function's frame when its corresponding `BASH_SOURCE` entry is empty. Note: I believe the earlier problem described in sstephenson/bats#225 whereby no output was generated at all was fixed by commit 0f6dde5. My investigation revealed that in Bash versions all the way up through 4.3.48, before this code change, the test failed as @pawamoy reported, with the underlying test fixture producing the following output: not ok 1 failing test (in file , line 7, from function `bats_perform_test' in file libexec/bats-exec-test, line 339, from function `main' in test file , line 391) Starting with Bash 4.4, the test passed. The apparent reason for the failure is that the `BASH_SOURCE` entry corresponding to the test file was getting wiped out when the exported function was called. (Once I converged on this as a potential culprit, I verified it by printing the contents of `BASH_SOURCE` before and after the exported function call.) Since `bats_capture_stack_trace` depends on matching a `BASH_SOURCE` value against `BATS_TEST_SOURCE`, when the `BASH_SOURCE` corresponding to the test function was empty, it would keep collecting stack frames, resulting in the output above. As best I can currently tell, the change accounting for the fix in Bash 4.4 is (from the Bash 4.4 ChangeLog): 1/2/2014 -------- ...snip... 2/26 ---- [bash-4.3 released] ...snip... 11/28 ----- execute_cmd.c - struct func_array_state: new state to save state of BASH_LINENO, BASH_SOURCE, and FUNCNAME during function execution so it can be restored on a jump to top level - restore_funcarray_state: new function to restore func_array_state - execute_function: fill in func_array_state variable, add unwind- protect to restore it on jump to top level, call explicitly at end of function if subshell != 0 (may not be necessary, but safe for now). Fixes bug with local assignments to FUNCNAME reported by Arfrever Frehtes Taifersar Arahesis <arfrever.fta@gmail.com> 1/1/2015 -------- ...snip... 7/7 --- ...snip... [bash-4.4-alpha frozen]
Hmm, failing on the Alpine Docker image. Will take a look later. |
This makes it faster to iterate on running changes to Bats inside the container, since the apk packages are far less likely to change.
This allows the Docker tests to run even if the native tests fail, providing more information.
This fixes the build failure seen during #87 from the "execute exported function without breaking failing test output" test case. The failure was due to the Dockerfile copying the Bats files to /opt/bats, rendering the equality expression too rigid. The expression now uses a regex comparison, allowing the test to pass both natively and when running in the container.
OK, pushed a commit to fix the Alpine Docker run: The equality expression checking the expected stack trace was too rigid; changed it to a regex. Also pushed a commit to add Bash to the Alpine container before copying the Bats files (makes for faster local development) and a commit to run the native and Docker tests as two separate |
Should've done this in the previous commit rather than using a regex, but I'd forgotten until I looked over other test cases after-the-fact. This allows the "execute exported function without breaking failing test output" to pass both locally/natively and in the Alpine Docker container.
D'oh! Forgot about |
And today I just realized that the right-hand side of |
Going to merge this now; if there're any comments or concerns after-the-fact, I'm happy to address them. |
Closes #34. Incorporates the test code from that PR.
This fixes a problem whereby invoking an exported function within a test script would result in an incorrect stack trace. It does this by using
BATS_TEST_SOURCE
to capture a function's frame when its correspondingBASH_SOURCE
entry is empty.Note: I believe the earlier problem described in sstephenson/bats#225 whereby no output was generated at all was fixed by commit 0f6dde5.
My investigation revealed that in Bash versions all the way up through 4.3.48, before this code change, the test failed as @pawamoy reported, with the underlying test fixture producing the following output:
Starting with Bash 4.4, the test passed.
The apparent reason for the failure is that the
BASH_SOURCE
entry corresponding to the test file was getting wiped out when the exported function was called. (Once I converged on this as a potential culprit, I verified it by printing the contents ofBASH_SOURCE
before and after the exported function call.) Sincebats_capture_stack_trace
depends on matching aBASH_SOURCE
value againstBATS_TEST_SOURCE
, when theBASH_SOURCE
corresponding to the test function was empty, it would keep collecting stack frames, resulting in the output above.As best I can currently tell, the change accounting for the fix in Bash 4.4 is (from the Bash 4.4 ChangeLog):