Open ko1nksm opened 5 years ago
Actually, $SHELL is set by bash and some shells but not set by dash. So controlled build environment with cleaned environment variable under dash has undefined $SHELL.
This patch fixed error for testIssue84 for me for bash build-test started on dash. But dash still fails for dash build-test started on dash.
Key difference in set -x log is
BASH is lead by 3 +++
+++ assertTrue 'failure message for assertFalse was not generated' 0
DASH is lead by +
+ assertTrue failure message for assertFalse was not generated 1
Also right most value is different.
BASH (with set -x):
testIssue84
+++ unittestF=/tmp/shunit.b5sPS5/tmp/unittest
+++ sed 's/^#//'
+++ exec /bin/bash /tmp/shunit.b5sPS5/tmp/unittest
+++ grep '^FAILED' /tmp/shunit.b5sPS5/tmp/stdout
+++ assertTrue 'failure message for assertFalse was not generated' 0
+++ eval '__shunit_lineno="";' if command '[' '"${1:-}"' = '"--lineno"' '];' then command '[' -n '"$2"' ']' '&&' '__shunit_lineno="[$2]' '";' shift '2;' fi
++++ __shunit_lineno=
++++ command '[' 'failure message for assertFalse was not generated' = --lineno ']'
++++ '[' 'failure message for assertFalse was not generated' = --lineno ']'
+++ command '[' 2 -lt 1 -o 2 -gt 2 ']'
+++ '[' 2 -lt 1 -o 2 -gt 2 ']'
+++ _shunit_shouldSkip
+++ command '[' 1 -eq 1 ']'
+++ '[' 1 -eq 1 ']'
+++ return 1
+++ shunit_message_=
+++ command '[' 2 -eq 2 ']'
+++ '[' 2 -eq 2 ']'
+++ shunit_message_='failure message for assertFalse was not generated'
+++ shift
+++ shunit_condition_=0
++++ expr 0 : '\([0-9]*\)'
+++ shunit_match_=0
+++ shunit_return=0
+++ command '[' -z 0 ']'
+++ '[' -z 0 ']'
+++ command '[' -n 0 -a 0 = 0 ']'
+++ '[' -n 0 -a 0 = 0 ']'
+++ command '[' 0 -ne 0 ']'
+++ '[' 0 -ne 0 ']'
+++ command '[' 0 -eq 0 ']'
+++ '[' 0 -eq 0 ']'
+++ _shunit_assertPass
++++ expr 18 + 1
+++ __shunit_assertsPassed=19
++++ expr 18 + 1
+++ __shunit_assertsTotal=19
+++ unset shunit_message_ shunit_condition_ shunit_match_
+++ return 0
+++ set +x
DASH:
testIssue84
+ unittestF=/tmp/shunit.y5DlXm/tmp/unittest
+ sed s/^#//
+ exec /bin/dash /tmp/shunit.y5DlXm/tmp/unittest
+ grep ^FAILED /tmp/shunit.y5DlXm/tmp/stdout
+ assertTrue failure message for assertFalse was not generated 1
+ eval __shunit_lineno=""; if command [ "${1:-}" = "--lineno" ]; then command [ -n "$2" ] && __shunit_lineno="[$2] "; shift 2; fi
+ __shunit_lineno=
+ command [ failure message for assertFalse was not generated = --lineno ]
+ command [ 2 -lt 1 -o 2 -gt 2 ]
+ _shunit_shouldSkip
+ command [ 1 -eq 1 ]
+ return 1
+ shunit_message_=
+ command [ 2 -eq 2 ]
+ shunit_message_=failure message for assertFalse was not generated
+ shift
+ shunit_condition_=1
+ expr 1 : \([0-9]*\)
+ shunit_match_=1
+ shunit_return=0
+ command [ -z 1 ]
+ command [ -n 1 -a 1 = 1 ]
+ command [ 1 -ne 0 ]
+ shunit_return=1
+ command [ 1 -eq 0 ]
+ _shunit_assertFail failure message for assertFalse was not generated
+ __shunit_testSuccess=1
+ _shunit_incFailedCount
+ expr 0 + 1
+ __shunit_assertsFailed=1
+ expr 18 + 1
+ __shunit_assertsTotal=19
+ [ 1 -gt 0 ]
+ echo \033[1;31mASSERT:\033[0mfailure message for assertFalse was not generated
ASSERT:failure message for assertFalse was not generated
+ unset shunit_message_ shunit_condition_ shunit_match_
+ return 1
+ set +x
I have problem sourcing following script;
SH="/bin/dash"
echo "SHELL='$SHELL'"
env -i SHELL=$SHELL bash ./test_runner -s${SH} -tshunit2_misc_test.sh
env -i SHELL=$SHELL dash ./test_runner -s${SH} -tshunit2_misc_test.sh
env -i SHELL=$SHELL ksh ./test_runner -s${SH} -tshunit2_misc_test.sh
env -i SHELL=$SHELL mksh ./test_runner -s${SH} -tshunit2_misc_test.sh
By changing first line to use /bin/bash
, this thing works like charm.
Hmmm... even without patch, bash doesn't fail. even with patch, dash fails. Maybe I am getting confused.
I decided to test shunit2_misc_test.sh only for bash for Debian packaging for now. All others are tested for 5 shells: /bin/bash /bin/dash /bin/ksh /bin/mksh /bin/zsh
Is it OK to release 2.1.8pre to Debian unstable repository? Debian has 2.1.6 variant now.
Thanks for your nice package.
Now I see what was happening.
The strange ${SHELL-sh} in shunit2_misc_test.sh is almost meant to use bash no matter what shell test_runner requests. That means cheating on testing code for each shell. That is not right thing to do.
When this is invoked from interactive bash shell $SHELL is already set as bash and bash is used.
But it it is started from other shell like:
$ env -i dash ./test_runner -tshunit2_misc_test.sh
Things get bad nowadays.
This cheating worked mostly on old Ubuntu/Debian where /bin/sh was linked to bash. No more. /bin/sh is linked to dash now. So if you still want to cheat like this, ${SHELL-bash} needs to be here.
But that cheating fails on ksh since:
So if we really have to cheat, use "bash" there.
I think this cheating seems to beat the purpose of having these test scripts.
dash:
...
TestIssue84
ASSERT:failure message for assertFalse was not generated
shunit2:ERROR testIssue84() returned non-zero return code.
...
testColors
ASSERT:expected:<16> but was:<256>
shunit2:ERROR testColors() returned non-zero return code.
...
ksh:
shell name: ksh
shell version: AJM-93u+-2012-08-01-$
--- Executing the 'shunit2_misc' test suite. ---
./shunit2_misc_test.sh[315]: .: line 1282: PATH: parameter not set
./shunit2_misc_test.sh[970]: tearDown: not found [No such file or directory]
shunit2:WARN tearDown() returned non-zero return code.
./shunit2_misc_test.sh[973]: oneTimeTearDown: not found [No such file or directory]
shunit2:WARN oneTimeTearDown() returned non-zero return code.
ASSERT:unknown failure encountered running a test
Ran 0 tests.
FAILED (failures=1)
mksh, zsh -- looks same as dash since it uses dash by cheating under modern Debian.
(If I set SHELL to something, more errors come out from non-bash shells.)
I think we need to make test case for dash at least.
$ ./shunit2_misc_test.sh
testUnboundVariable
testIssue7
testIssue29
testIssue69
testIssue77
testIssue84
Shell : /bin/bash
/bin/bash /tmp/shunit.RUnlAy/tmp/unittest /tmp/shunit.RUnlAy/tmp/stdout /tmp/shunit.RUnlAy/tmp/stderr
----------- stdoutf -----------
--- test_syntax_error
Ran 1 test.
FAILED (failures=1)
----------- stdoutfend -----------
----------- stderrF -----------
/tmp/shunit.RUnlAy/tmp/unittest: ligne 2: ${!#3442} : mauvaise substitution
shunit2:ERROR test_syntax_error() returned non-zero return code.
----------- stderrFend -----------
testPrepForSourcing
testEscapeCharInStr
testEscapeCharInStr_specialChars
testExtractTestFunctions
testIssue54
testColors
testColorsWitoutTERM
Ran 13 tests.
OK
/app/shunit2-2.1.8 # ./shunit2_misc_test.sh
testUnboundVariable
testIssue7
testIssue29
testIssue69
testIssue77
testIssue84
Shell : sh
sh /tmp/shunit.PdGOOP/tmp/unittest /tmp/shunit.PdGOOP/tmp/stdout /tmp/shunit.PdGOOP/tmp/stderr
----------- stdoutf -----------
--- test_syntax_error
Ran 1 test.
OK
----------- stdoutfend -----------
----------- stderrF -----------
/tmp/shunit.PdGOOP/tmp/unittest: eval: line 2: -334: not found
----------- stderrFend -----------
ASSERT:failure message for assertFalse was not generated
shunit2:ERROR testIssue84() returned non-zero return code.
testPrepForSourcing
testEscapeCharInStr
testEscapeCharInStr_specialChars
testExtractTestFunctions
testIssue54
testColors
testColorsWitoutTERM
Ran 13 tests.
FAILED (failures=2)
SHELL="/bin/bash" ./test_runner
made it work, thank you !
Ref: https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/15811
env -i dash ./test_runner -tshunit2_misc_test.sh
did help me reproduce it
#------------------------------------------------------------------------------
# Running the test suite with /bin/zsh.
#
shell name: zsh
shell version: 5.8
--- Executing the 'shunit2_misc' test suite. ---
testUnboundVariable
testIssue7
testIssue29
testIssue69
testIssue77
testIssue84
Shell : sh
sh /tmp/shunit.OpClAb/tmp/unittest /tmp/shunit.OpClAb/tmp/stdout /tmp/shunit.OpClAb/tmp/stderr
----------- stdoutf -----------
--- test_syntax_error
Ran 1 test.
OK
----------- stdoutfend -----------
----------- stderrF -----------
/tmp/shunit.OpClAb/tmp/unittest: eval: line 2: -334: not found
----------- stderrFend -----------
ASSERT:failure message for assertFalse was not generated
shunit2:ERROR testIssue84() returned non-zero return code.
testPrepForSourcing
testEscapeCharInStr
testEscapeCharInStr_specialChars
testExtractTestFunctions
testIssue54
testColors
------- testColors ------------
got: 16
want: 16
------- testColorsend------------
------- testColors ------------
got:
want: 256
------- testColorsend------------
ASSERT:expected:<> but was:<256>
shunit2:ERROR testColors() returned non-zero return code.
[: out of range
testColorsWitoutTERM
Ran 13 tests.
FAILED (failures=4)
Could you let me know if these are still broken on HEAD?
It's still broken.
I am using zsh as my interactive shell on macOS. In other words, SHELL=/bin/zsh
.
When I run ./test_runner
, the test fails.
Additional test results.
Can someone help me fixing this error ? I am trying to package shunit2 into Debian (https://github.com/kward/shunit2/issues/155)
On my workstation tests pass but not on a CI: https://salsa.debian.org/debian/shunit2/-/jobs/2774040#L1015
shunit2:ERROR testIssue84() returned non-zero return code.
PS: https://github.com/cezanne/shunit2/commit/e736e3e789a7f8fc04aa8959aec55356554b9ea8 does not work
shunit2_misc_test.sh
is tested with the shell that set in the environment variable$SHELL
.e.g.
However
$SHELL
is not the current running shell, but the shell when login.test_runner
tries to test all installed shells, but it test only login shell (probably bash only).I did a quick hack to test, then the current (ba130d6 and v2.1.7) test failed.
(note:
$SHUNIT_SHELL
was used instead of$SHELL
on v2.1.7)Result of ./test_runner
```console $ ./test_runner #------------------------------------------------------------------------------ # System data. # $ uname -mprsv Linux 5.0.0-25-generic #26-Ubuntu SMP Thu Aug 1 12:04:58 UTC 2019 x86_64 x86_64 OS Name: Linux OS Version: Ubuntu 19.04 ### Test run info. shells: /bin/sh ash /bin/bash /bin/dash /bin/ksh /bin/pdksh /bin/zsh tests: shunit2_args_test.sh shunit2_asserts_test.sh shunit2_failures_test.sh shunit2_macros_test.sh shunit2_misc_test.sh shunit2_standalone_test.sh #------------------------------------------------------------------------------ # Running the test suite with /bin/sh. # shell name: sh shell version: unknown --- Executing the 'shunit2_args' test suite. --- non_default_test test_non_default_ran Ran 2 tests. OK --- Executing the 'shunit2_asserts' test suite. --- testAssertEquals testAssertNotEquals testAssertSame testAssertNotSame testAssertContains testAssertNotContains testAssertNull testAssertNotNull testAssertTrue testAssertFalse Ran 10 tests. OK --- Executing the 'shunit2_failures' test suite. --- testFail testFailNotEquals testFailSame Ran 3 tests. OK --- Executing the 'shunit2_macros' test suite. --- testAssertEquals testAssertNotEquals testSame testNotSame testNull testNotNull testAssertTrue testAssertFalse testFail testFailNotEquals testFailSame testFailNotSame Ran 12 tests. OK (skipped=24) --- Executing the 'shunit2_misc' test suite. --- testUnboundVariable testIssue7 testIssue29 testIssue69 testIssue77 testIssue84 ASSERT:failure message for assertFalse was not generated shunit2:ERROR testIssue84() returned non-zero return code. testPrepForSourcing testEscapeCharInStr testEscapeCharInStr_specialChars testExtractTestFunctions testIssue54 testColors testColorsWitoutTERM Ran 13 tests. FAILED (failures=2) --- Executing the 'shunit2_standalone' test suite. --- #------------------------------------------------------------------------------ # Running the test suite with ash. # shell name: ash shell version: 1.27.2 --- Executing the 'shunit2_args' test suite. --- non_default_test test_non_default_ran Ran 2 tests. OK --- Executing the 'shunit2_asserts' test suite. --- testAssertEquals testAssertNotEquals testAssertSame testAssertNotSame testAssertContains testAssertNotContains testAssertNull testAssertNotNull testAssertTrue testAssertFalse Ran 10 tests. OK --- Executing the 'shunit2_failures' test suite. --- testFail testFailNotEquals testFailSame Ran 3 tests. OK --- Executing the 'shunit2_macros' test suite. --- testAssertEquals testAssertNotEquals testSame testNotSame testNull testNotNull testAssertTrue testAssertFalse testFail testFailNotEquals testFailSame testFailNotSame Ran 12 tests. OK (skipped=24) --- Executing the 'shunit2_misc' test suite. --- testUnboundVariable testIssue7 testIssue29 testIssue69 testIssue77 testIssue84 ASSERT:failure message for assertFalse was not generated shunit2:ERROR testIssue84() returned non-zero return code. testPrepForSourcing testEscapeCharInStr testEscapeCharInStr_specialChars testExtractTestFunctions testIssue54 testColors testColorsWitoutTERM Ran 13 tests. FAILED (failures=2) --- Executing the 'shunit2_standalone' test suite. --- #------------------------------------------------------------------------------ # Running the test suite with /bin/bash. # shell name: bash shell version: 5.0.3(1)-release --- Executing the 'shunit2_args' test suite. --- non_default_test test_non_default_ran Ran 2 tests. OK --- Executing the 'shunit2_asserts' test suite. --- testAssertEquals testAssertNotEquals testAssertSame testAssertNotSame testAssertContains testAssertNotContains testAssertNull testAssertNotNull testAssertTrue testAssertFalse Ran 10 tests. OK --- Executing the 'shunit2_failures' test suite. --- testFail testFailNotEquals testFailSame Ran 3 tests. OK --- Executing the 'shunit2_macros' test suite. --- testAssertEquals testAssertNotEquals testSame testNotSame testNull testNotNull testAssertTrue testAssertFalse testFail testFailNotEquals testFailSame testFailNotSame Ran 12 tests. OK --- Executing the 'shunit2_misc' test suite. --- testUnboundVariable testIssue7 testIssue29 testIssue69 testIssue77 testIssue84 testPrepForSourcing testEscapeCharInStr testEscapeCharInStr_specialChars testExtractTestFunctions testIssue54 testColors testColorsWitoutTERM Ran 13 tests. OK --- Executing the 'shunit2_standalone' test suite. --- #------------------------------------------------------------------------------ # Running the test suite with /bin/dash. # shell name: dash shell version: 0.5.10.2-4ubuntu1 --- Executing the 'shunit2_args' test suite. --- non_default_test test_non_default_ran Ran 2 tests. OK --- Executing the 'shunit2_asserts' test suite. --- testAssertEquals testAssertNotEquals testAssertSame testAssertNotSame testAssertContains testAssertNotContains testAssertNull testAssertNotNull testAssertTrue testAssertFalse Ran 10 tests. OK --- Executing the 'shunit2_failures' test suite. --- testFail testFailNotEquals testFailSame Ran 3 tests. OK --- Executing the 'shunit2_macros' test suite. --- testAssertEquals testAssertNotEquals testSame testNotSame testNull testNotNull testAssertTrue testAssertFalse testFail testFailNotEquals testFailSame testFailNotSame Ran 12 tests. OK (skipped=24) --- Executing the 'shunit2_misc' test suite. --- testUnboundVariable testIssue7 testIssue29 testIssue69 testIssue77 testIssue84 ASSERT:failure message for assertFalse was not generated shunit2:ERROR testIssue84() returned non-zero return code. testPrepForSourcing testEscapeCharInStr testEscapeCharInStr_specialChars testExtractTestFunctions testIssue54 testColors testColorsWitoutTERM Ran 13 tests. FAILED (failures=2) --- Executing the 'shunit2_standalone' test suite. --- #------------------------------------------------------------------------------ # Running the test suite with /bin/ksh. # shell name: ksh shell version: AJM-93u+-2012-08-01-$ --- Executing the 'shunit2_args' test suite. --- non_default_test test_non_default_ran Ran 2 tests. OK --- Executing the 'shunit2_asserts' test suite. --- testAssertEquals testAssertNotEquals testAssertSame testAssertNotSame testAssertContains testAssertNotContains testAssertNull testAssertNotNull testAssertTrue testAssertFalse Ran 10 tests. OK --- Executing the 'shunit2_failures' test suite. --- testFail testFailNotEquals testFailSame Ran 3 tests. OK --- Executing the 'shunit2_macros' test suite. --- testAssertEquals testAssertNotEquals testSame testNotSame testNull testNotNull testAssertTrue testAssertFalse testFail testFailNotEquals testFailSame testFailNotSame Ran 12 tests. OK --- Executing the 'shunit2_misc' test suite. --- testUnboundVariable ASSERT:expected a non-zero exit value ASSERT:assert message was not generated ASSERT:failure message was not generated shunit2:ERROR testUnboundVariable() returned non-zero return code. testIssue7 testIssue29 testIssue69 testIssue77 testIssue84 ASSERT:failure message for assertFalse was not generated shunit2:ERROR testIssue84() returned non-zero return code. testPrepForSourcing testEscapeCharInStr testEscapeCharInStr_specialChars testExtractTestFunctions testIssue54 testColors testColorsWitoutTERM Ran 13 tests. FAILED (failures=6) --- Executing the 'shunit2_standalone' test suite. --- #------------------------------------------------------------------------------ # Running the test suite with /bin/pdksh. # runner:WARN unable to run tests with the pdksh shell #------------------------------------------------------------------------------ # Running the test suite with /bin/zsh. # shell name: zsh shell version: 5.5.1 --- Executing the 'shunit2_args' test suite. --- non_default_test test_non_default_ran Ran 2 tests. OK --- Executing the 'shunit2_asserts' test suite. --- testAssertEquals testAssertNotEquals testAssertSame testAssertNotSame testAssertContains testAssertNotContains testAssertNull testAssertNotNull testAssertTrue testAssertFalse Ran 10 tests. OK --- Executing the 'shunit2_failures' test suite. --- testFail testFailNotEquals testFailSame Ran 3 tests. OK --- Executing the 'shunit2_macros' test suite. --- testAssertEquals testAssertNotEquals testSame testNotSame testNull testNotNull testAssertTrue testAssertFalse testFail testFailNotEquals testFailSame testFailNotSame Ran 12 tests. OK --- Executing the 'shunit2_misc' test suite. --- testUnboundVariable ASSERT:assert message was not generated ASSERT:test count message was not generated ASSERT:failure message was not generated shunit2:ERROR testUnboundVariable() returned non-zero return code. testIssue7 testIssue29 ASSERT:expected:<0> but was:<1> testIssue69 ASSERT:failure message for assertEquals was not generated ASSERT:failure message for assertNotEquals was not generated ASSERT:failure message for assertNull was not generated ASSERT:failure message for assertNotNull was not generated ASSERT:failure message for assertSame was not generated ASSERT:failure message for assertNotSame was not generated ASSERT:failure message for assertTrue was not generated ASSERT:failure message for assertFalse was not generated shunit2:ERROR testIssue69() returned non-zero return code. testIssue77 ASSERT:failure of oneTimeSetUp() did not end test ASSERT:failure of setUp() did not end test ASSERT:failure of tearDown() did not end test ASSERT:failure of oneTimeTearDown() did not end test shunit2:ERROR testIssue77() returned non-zero return code. testIssue84 ASSERT:failure message for assertFalse was not generated shunit2:ERROR testIssue84() returned non-zero return code. testPrepForSourcing testEscapeCharInStr testEscapeCharInStr_specialChars testExtractTestFunctions testIssue54 testColors testColorsWitoutTERM Ran 13 tests. FAILED (failures=21) --- Executing the 'shunit2_standalone' test suite. --- ```