Skip to content
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

Consider 'set -e' in lib/test-lib.sh #3721

Open
kevina opened this issue Feb 23, 2017 · 3 comments
Open

Consider 'set -e' in lib/test-lib.sh #3721

kevina opened this issue Feb 23, 2017 · 3 comments
Labels
need/community-input Needs input from the wider community

Comments

@kevina
Copy link
Contributor

kevina commented Feb 23, 2017

Without it simple typos may be hard to catch. For example, this trivial test script should fail:

#!/bin/sh
test_description="A trival test that should fail"
. lib/test-lib.sh
#set -e
test_expect_successs "false" 'false'
test_expect_success "true" 'true'
test_done

But it doesn't because I misspelled successs. Instead here is the output:

./t9999-example.sh: 8: ./t9999-example.sh: test_expect_successs: not found
ok 1 - true
# passed all 1 test(s)
1..1

It shows the error, but in a large script with lots of tests it may be very easy to miss.

If the set -e in uncommented than the script will abort and make the typo more obvious:

./t9999-example.sh: 5: ./t9999-example.sh: test_expect_successs: not found
FATAL: Unexpected exit with code 127

I am not sure what consequences using set -e globally will have though.

@kevina kevina mentioned this issue Feb 23, 2017
@kevina
Copy link
Contributor Author

kevina commented Feb 23, 2017

Note that set -e does not cause the script to abort if a test fails. For example if the script was (with both set -e and the typo fixed)

#!/bin/sh
test_description="A trival test that should fail"
. lib/test-lib.sh
set -e
test_expect_success "false" 'false'
test_expect_success "true" 'true'
test_done

the output will be:

not ok 1 - false
#       false
ok 2 - true
# failed 1 among 2 test(s)
1..2

@whyrusleeping
Copy link
Member

mmm, i see. set -e doesnt apply like i thought it would because the test_expect_success commands are essentially running a subshell by calling eval and actually not returning a non-zero value even on test failure

@whyrusleeping
Copy link
Member

cc @chriscool

@Kubuxu Kubuxu added the need/community-input Needs input from the wider community label Mar 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need/community-input Needs input from the wider community
Projects
None yet
Development

No branches or pull requests

3 participants