-
Notifications
You must be signed in to change notification settings - Fork 519
IFS broken after first run #89
Comments
a patch that works here, may be other IFS should be saved too. bash --version git diff
diff --git a/libexec/bats-exec-test b/libexec/bats-exec-test
index 5a07665..8f3bd51 100755
--- a/libexec/bats-exec-test
+++ b/libexec/bats-exec-test
@@ -48,7 +48,7 @@ load() {
}
run() {
- local e E T
+ local e E T oldIFS
[[ ! "$-" =~ e ]] || e=1
[[ ! "$-" =~ E ]] || E=1
[[ ! "$-" =~ T ]] || T=1
@@ -57,10 +57,12 @@ run() {
set +T
output="$("$@" 2>&1)"
status="$?"
+ oldIFS=$IFS
IFS=$'\n' lines=($output)
[ -z "$e" ] || set -e
[ -z "$E" ] || set -E
[ -z "$T" ] || set -T
+ IFS=$oldIFS
}
setup() { |
Patch looks good. You should submit a pull request with it! Thanks |
Ok, I'm preparing it. Curliously this patch brakes one test, in some strange way:
and this test seems dumy simple… cat fixtures/bats/passing.bats
@test "a passing test" {
true
} but:
hum and in the test/ dir too, this run fails too bats . but still 43 tests, 8 failures, without my patch bash --version I'm not yet sure the expected behavior of the command |
Found! The test in bats.bats line 40 was false, relaying on the IFS wrongly set, before the patch. Last test is wrong @test "one passing test" {
run bats "$FIXTURE_ROOT/passing.bats"
[ $status -eq 0 ]
[ ${lines[0]} = "1..1" ]
[ ${lines[1]} = "ok 1 a passing test" ] # <-- wrong
} |
IFS was modified by run() becoming '\n' and so relying to its bash default was failing tests. Also some wrong tests corrected because was relying on this behavior to pass. Fix sstephenson#89
Do you need more test to merge the request? |
Hi there, I see a fix was merged and then the issue was closed, but subsequently the fix was reverted (but the issue was not reopened?) Any chance this could be addressed? It would avoid needing to do workarounds in tests. I see some comments in the corresponding PR (#90) talking about a requirement to document the breaking changes? Thanks |
@alzadude This issue has been bugging me too. I think the sooner this is addressed the less painful it'll be. It's already on my list of issues I'm planning to propose for the next release. |
IFS was modified by run() becoming '\n' and so relying to its bash default was failing tests. Also some wrong tests corrected because was relying on this behavior to pass. Fix sstephenson#89
I managed to stumble across a bug in BATS where the run() function screwed with the global IFS. The bug has been fixed in git, but isn't in a release yet. sstephenson/bats#89 Anyway, this bug breaks __getCheckSum(). Fortunately, we have avoided tripping it so far because luck has it that we never call __getCheckSum() after run() in the same test. So, there's nothing actually broken here, but it makes me nervous. So go ahead and modify __getCheckSum to not rely on IFS. And, while we're at it: declare the result variable and set it as separate commands. Doing both in the same command masks the exit code of the subshell expansion. We don't explicitly check the exit code, but BATS runs the test suite with `set -e`, so splitting it does mean that BATS will now detect errors from sha1sum. We don't really expect that to happen, but if BATS will give us error checking on it for free, why not?
CentOS, as of bats-0.4.0-1.20141016git3b33a5a.el7.noarch, misses the fix for sstephenson/bats#89 , causing (read) not to split words at white space. Set IFS to the default value explicitly to work around this. Signed-off-by: Miloslav Trmač <[email protected]>
CentOS, as of bats-0.4.0-1.20141016git3b33a5a.el7.noarch, misses the fix for sstephenson/bats#89 , causing (read) not to split words at white space. Set IFS to the default value explicitly to work around this. Signed-off-by: Miloslav Trmač <[email protected]>
CentOS, as of bats-0.4.0-1.20141016git3b33a5a.el7.noarch, misses the fix for sstephenson/bats#89 , causing (read) not to split words at white space. Set IFS to the default value explicitly to work around this. Signed-off-by: Miloslav Trmač <[email protected]>
CentOS, as of bats-0.4.0-1.20141016git3b33a5a.el7.noarch, misses the fix for sstephenson/bats#89 , causing (read) not to split words at white space. Set IFS to the default value explicitly to work around this. Signed-off-by: Miloslav Trmač <[email protected]>
CentOS, as of bats-0.4.0-1.20141016git3b33a5a.el7.noarch, misses the fix for sstephenson/bats#89 , causing (read) not to split words at white space. Set IFS to the default value explicitly to work around this. Signed-off-by: Miloslav Trmač <[email protected]>
CentOS, as of bats-0.4.0-1.20141016git3b33a5a.el7.noarch, misses the fix for sstephenson/bats#89 , causing (read) not to split words at white space. Set IFS to the default value explicitly to work around this. Signed-off-by: Miloslav Trmač <[email protected]>
CentOS, as of bats-0.4.0-1.20141016git3b33a5a.el7.noarch, misses the fix for sstephenson/bats#89 , causing (read) not to split words at white space. Set IFS to the default value explicitly to work around this. Signed-off-by: Miloslav Trmač <[email protected]>
CentOS, as of bats-0.4.0-1.20141016git3b33a5a.el7.noarch, misses the fix for sstephenson/bats#89 , causing (read) not to split words at white space. Set IFS to the default value explicitly to work around this. Signed-off-by: Miloslav Trmač <[email protected]>
CentOS, as of bats-0.4.0-1.20141016git3b33a5a.el7.noarch, misses the fix for sstephenson/bats#89 , causing (read) not to split words at white space. Set IFS to the default value explicitly to work around this. Signed-off-by: Miloslav Trmač <[email protected]>
CentOS, as of bats-0.4.0-1.20141016git3b33a5a.el7.noarch, misses the fix for sstephenson/bats#89 , causing (read) not to split words at white space. Set IFS to the default value explicitly to work around this. Signed-off-by: Miloslav Trmač <[email protected]>
CentOS, as of bats-0.4.0-1.20141016git3b33a5a.el7.noarch, misses the fix for sstephenson/bats#89 , causing (read) not to split words at white space. Set IFS to the default value explicitly to work around this. Signed-off-by: Miloslav Trmač <[email protected]>
CentOS, as of bats-0.4.0-1.20141016git3b33a5a.el7.noarch, misses the fix for sstephenson/bats#89 , causing (read) not to split words at white space. Set IFS to the default value explicitly to work around this. Signed-off-by: Miloslav Trmač <[email protected]>
CentOS, as of bats-0.4.0-1.20141016git3b33a5a.el7.noarch, misses the fix for sstephenson/bats#89 , causing (read) not to split words at white space. Set IFS to the default value explicitly to work around this. Signed-off-by: Miloslav Trmač <[email protected]>
CentOS, as of bats-0.4.0-1.20141016git3b33a5a.el7.noarch, misses the fix for sstephenson/bats#89 , causing (read) not to split words at white space. Set IFS to the default value explicitly to work around this. Signed-off-by: Miloslav Trmač <[email protected]>
CentOS, as of bats-0.4.0-1.20141016git3b33a5a.el7.noarch, misses the fix for sstephenson/bats#89 , causing (read) not to split words at white space. Set IFS to the default value explicitly to work around this. Signed-off-by: Miloslav Trmač <[email protected]>
CentOS, as of bats-0.4.0-1.20141016git3b33a5a.el7.noarch, misses the fix for sstephenson/bats#89 , causing (read) not to split words at white space. Set IFS to the default value explicitly to work around this. Signed-off-by: Miloslav Trmač <[email protected]>
CentOS, as of bats-0.4.0-1.20141016git3b33a5a.el7.noarch, misses the fix for sstephenson/bats#89 , causing (read) not to split words at white space. Set IFS to the default value explicitly to work around this. Signed-off-by: Miloslav Trmač <[email protected]>
CentOS, as of bats-0.4.0-1.20141016git3b33a5a.el7.noarch, misses the fix for sstephenson/bats#89 , causing (read) not to split words at white space. Set IFS to the default value explicitly to work around this. Signed-off-by: Miloslav Trmač <[email protected]>
CentOS, as of bats-0.4.0-1.20141016git3b33a5a.el7.noarch, misses the fix for sstephenson/bats#89 , causing (read) not to split words at white space. Set IFS to the default value explicitly to work around this. Signed-off-by: Miloslav Trmač <[email protected]>
CentOS, as of bats-0.4.0-1.20141016git3b33a5a.el7.noarch, misses the fix for sstephenson/bats#89 , causing (read) not to split words at white space. Set IFS to the default value explicitly to work around this. Signed-off-by: Miloslav Trmač <[email protected]>
CentOS, as of bats-0.4.0-1.20141016git3b33a5a.el7.noarch, misses the fix for sstephenson/bats#89 , causing (read) not to split words at white space. Set IFS to the default value explicitly to work around this. Signed-off-by: Miloslav Trmač <[email protected]>
CentOS, as of bats-0.4.0-1.20141016git3b33a5a.el7.noarch, misses the fix for sstephenson/bats#89 , causing (read) not to split words at white space. Set IFS to the default value explicitly to work around this. Signed-off-by: Miloslav Trmač <[email protected]>
CentOS, as of bats-0.4.0-1.20141016git3b33a5a.el7.noarch, misses the fix for sstephenson/bats#89 , causing (read) not to split words at white space. Set IFS to the default value explicitly to work around this. Signed-off-by: Miloslav Trmač <[email protected]>
CentOS, as of bats-0.4.0-1.20141016git3b33a5a.el7.noarch, misses the fix for sstephenson/bats#89 , causing (read) not to split words at white space. Set IFS to the default value explicitly to work around this. Signed-off-by: Miloslav Trmač <[email protected]>
Here follows a bats that fails. First run passes,not the second.
outputs:
The text was updated successfully, but these errors were encountered: