Permalink
Browse files

Move tests of 'source' and 'eval' to their own file.

  • Loading branch information...
Andy Chu
Andy Chu committed Jun 22, 2018
1 parent cb9850f commit 094636c1101659be2a237b952bb9512ed808535a
Showing with 64 additions and 58 deletions.
  1. +59 −0 spec/builtin-eval-source.test.sh
  2. +0 −58 spec/builtins.test.sh
  3. +5 −0 test/spec.sh
@@ -0,0 +1,59 @@
#!/usr/bin/env bash
### Eval
eval "a=3"
echo $a
# stdout: 3
### Source
lib=$TMP/spec-test-lib.sh
echo 'LIBVAR=libvar' > $lib
. $lib # dash doesn't have source
echo $LIBVAR
# stdout: libvar
### Source nonexistent
source /nonexistent/path
echo status=$?
# stdout: status=1
# OK dash/zsh stdout: status=127
### Source with no arguments
source
echo status=$?
# stdout: status=1
# OK bash stdout: status=2
# OK dash stdout: status=127
### Source with arguments
. spec/testdata/show-argv.sh foo bar # dash doesn't have source
## STDOUT:
show-argv: foo bar
## END
## N-I dash STDOUT:
show-argv:
## END
### Source from a function, mutating argv and defining a local var
f() {
. spec/testdata/source-argv.sh # no argv
. spec/testdata/source-argv.sh args to src # new argv
echo $@
echo foo=$foo # defined in source-argv.sh
}
f args to func
echo foo=$foo # not defined
## STDOUT:
source-argv: args to func
source-argv: args to src
to func
foo=foo_val
foo=
## END
## N-I dash STDOUT:
source-argv: args to func
source-argv: to func
func
foo=foo_val
foo=
## END
View
@@ -131,64 +131,6 @@ pwd
# status: 0
# N-I dash/mksh status: 127
### Eval
eval "a=3"
echo $a
# stdout: 3
### Source
lib=$TMP/spec-test-lib.sh
echo 'LIBVAR=libvar' > $lib
. $lib # dash doesn't have source
echo $LIBVAR
# stdout: libvar
### Source nonexistent
source /nonexistent/path
echo status=$?
# stdout: status=1
# OK dash stdout: status=127
### Source with no arguments
source
echo status=$?
# stdout: status=1
# OK bash stdout: status=2
# OK dash stdout: status=127
### Source with arguments
. spec/testdata/show-argv.sh foo bar # dash doesn't have source
## STDOUT:
show-argv: foo bar
## END
## N-I dash STDOUT:
show-argv:
## END
### Source from a function, mutating argv and defining a local var
f() {
. spec/testdata/source-argv.sh # no argv
. spec/testdata/source-argv.sh args to src # new argv
echo $@
echo foo=$foo # defined in source-argv.sh
}
f args to func
echo foo=$foo # not defined
## STDOUT:
source-argv: args to func
source-argv: args to src
to func
foo=foo_val
foo=
## END
## N-I dash STDOUT:
source-argv: args to func
source-argv: to func
func
foo=foo_val
foo=
## END
### Exit out of function
f() { exit 3; }
f
View
@@ -272,6 +272,11 @@ builtins() {
${REF_SHELLS[@]} $OSH "$@"
}
builtin-eval-source() {
sh-spec spec/builtin-eval-source.test.sh \
${REF_SHELLS[@]} $ZSH $OSH "$@"
}
builtin-io() {
sh-spec spec/builtin-io.test.sh \
${REF_SHELLS[@]} $ZSH $BUSYBOX_ASH $OSH "$@"

0 comments on commit 094636c

Please sign in to comment.