File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,14 +28,14 @@ assert_ok() {
2828 local FUNCTION=$1
2929 shift
3030
31- $( $ FUNCTION $@ ) || die ' "' " $FUNCTION $@ " ' " should have succeeded, but failed'
31+ " $ FUNCTION" " $@ " || die ' "' " $FUNCTION $@ " ' " should have succeeded, but failed'
3232}
3333
3434assert_not_ok () {
3535 local FUNCTION=$1
3636 shift
3737
38- ! $( $ FUNCTION $@ ) || die ' "' " $FUNCTION $@ " ' " should have failed, but succeeded'
38+ ! " $ FUNCTION" " $@ " || die ' "' " $FUNCTION $@ " ' " should have failed, but succeeded'
3939}
4040
4141strip_colors () {
@@ -46,7 +46,7 @@ strip_colors() {
4646
4747make_echo () {
4848 echo " #!/bin/sh" > " $1 "
49- echo " echo \" ${2} \" " > " $1 "
49+ echo " echo \" ${2} \" " >> " $1 "
5050 chmod a+x " $1 "
5151}
5252
Original file line number Diff line number Diff line change 1+ #! /bin/sh
2+
3+ die () { echo " $@ " ; exit 1; }
4+
5+ \. ../../common.sh
6+
7+ _returns_zero () { return 0; }
8+ _returns_nonzero () { return 1; }
9+
10+ # assert_not_ok should pass for a non-zero-exit function
11+ assert_not_ok _returns_nonzero \
12+ || die ' assert_not_ok failed on a function that returns 1'
13+
14+ # assert_not_ok should fail for a zero-exit function
15+ if (assert_not_ok _returns_zero 2> /dev/null); then
16+ die ' assert_not_ok incorrectly passed for a function that returns 0'
17+ fi
Original file line number Diff line number Diff line change 1+ #! /bin/sh
2+
3+ die () { echo " $@ " ; exit 1; }
4+
5+ \. ../../common.sh
6+
7+ _returns_zero () { return 0; }
8+ _returns_nonzero () { return 1; }
9+
10+ # assert_ok should pass for a zero-exit function
11+ assert_ok _returns_zero \
12+ || die ' assert_ok failed on a function that returns 0'
13+
14+ # assert_ok should fail for a non-zero-exit function
15+ if (assert_ok _returns_nonzero 2> /dev/null); then
16+ die ' assert_ok incorrectly passed for a function that returns 1'
17+ fi
Original file line number Diff line number Diff line change 1+ #! /bin/sh
2+
3+ die () { echo " $@ " ; exit 1; }
4+
5+ \. ../../common.sh
6+
7+ TMPFILE=" $( mktemp) "
8+ trap ' rm -f "${TMPFILE}"' EXIT
9+
10+ make_echo " ${TMPFILE} " " hello_nvm" || die ' make_echo returned non-zero'
11+
12+ # shebang must still be on line 1
13+ [ " $( head -n 1 " ${TMPFILE} " ) " = ' #!/bin/sh' ] \
14+ || die ' make_echo overwrote the shebang'
15+
16+ # script body must be present
17+ grep -q ' hello_nvm' " ${TMPFILE} " \
18+ || die ' make_echo did not write the echo body'
19+
20+ # file must be executable
21+ [ -x " ${TMPFILE} " ] \
22+ || die ' make_echo did not chmod the file'
You can’t perform that action at this time.
0 commit comments