aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMu Qiao <qiaomuf@gentoo.org>2011-06-28 22:43:50 +0800
committerMu Qiao <qiaomuf@gentoo.org>2011-07-18 23:23:53 +0800
commit3bd66c03c5ad80c17b442bdd7a66c563bc6557ab (patch)
tree2df96140e6a2087c9459786402b2338f71cf6686
parentParser: support literal '$' in double quoted string (diff)
downloadlibbash-3bd66c03c5ad80c17b442bdd7a66c563bc6557ab.tar.gz
libbash-3bd66c03c5ad80c17b442bdd7a66c563bc6557ab.tar.bz2
libbash-3bd66c03c5ad80c17b442bdd7a66c563bc6557ab.zip
Build: use bash to verify test scripts
We keep the old style for some tests that behave differently depending on different bash versions.
-rw-r--r--.gitignore1
-rw-r--r--Makefile.am24
-rw-r--r--bashast/libbashWalker.g11
-rw-r--r--scripts/arithmetic_assignment.bash26
-rw-r--r--scripts/arithmetic_assignment.bash.result22
-rw-r--r--scripts/binary_arithmetic.bash120
-rw-r--r--scripts/binary_arithmetic.bash.result64
-rw-r--r--scripts/command_execution.bash9
-rw-r--r--scripts/compound_command.bash.result61
-rw-r--r--scripts/function_def.bash.result29
-rw-r--r--scripts/isolated_functions.bash1
-rw-r--r--scripts/isolated_functions.bash.result12
-rw-r--r--scripts/naughty_tests8
-rw-r--r--scripts/naughty_tests.result (renamed from scripts/command_execution.bash.result)46
-rw-r--r--scripts/test_expr.bash.result28
-rw-r--r--scripts/var_def.bash39
-rw-r--r--scripts/var_def.bash.result35
-rw-r--r--scripts/var_expansion.bash182
-rw-r--r--scripts/var_expansion.bash.result110
-rw-r--r--src/builtins/echo_builtin.cpp2
-rw-r--r--src/core/interpreter.cpp8
-rwxr-xr-xtest/bash_compiler.sh21
-rwxr-xr-xtest/bash_result_tests.sh3
-rwxr-xr-xtest/script_compiler.sh14
-rw-r--r--utils/bash.cpp63
25 files changed, 339 insertions, 600 deletions
diff --git a/.gitignore b/.gitignore
index 93c80f9..0aef229 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,6 +24,7 @@ Makefile
autom4te.cache
cppunittests
variable_printer
+bash
metadata_generator
ast_printer
instruo
diff --git a/Makefile.am b/Makefile.am
index f974d3f..2702338 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -46,7 +46,7 @@ GUNIT_TESTS = bashast/gunit/arith_main.gunit \
bashast/gunit/simp_command.gunit \
bashast/gunit/simp_prog.gunit
-BASH_LOG_COMPILER = $(srcdir)/test/script_compiler.sh
+BASH_LOG_COMPILER = $(srcdir)/test/bash_compiler.sh
BASH_TESTS = scripts/var_def.bash \
scripts/var_expansion.bash \
scripts/command_execution.bash \
@@ -56,15 +56,6 @@ BASH_TESTS = scripts/var_def.bash \
scripts/compound_command.bash \
scripts/test_expr.bash \
scripts/binary_arithmetic.bash
-BASH_RESULT = scripts/var_def.bash.result \
- scripts/var_expansion.bash.result \
- scripts/command_execution.bash.result \
- scripts/function_def.bash.result \
- scripts/arithmetic_assignment.bash.result \
- scripts/isolated_functions.bash.result \
- scripts/compound_command.bash.result \
- scripts/test_expr.bash.result \
- scripts/binary_arithmetic.bash.result
EBUILD_LOG_COMPILER = $(srcdir)/test/ebuild_compiler.sh
EBUILD_TESTS = scripts/sunpinyin-2.0.3-r1.ebuild
@@ -95,7 +86,8 @@ if HAVE_GTEST
TESTS += cppunittests \
test/ast_printer_test.sh \
test/verify_bashs_test.sh \
- test/verify_error_output_test.sh
+ test/verify_error_output_test.sh \
+ test/bash_result_tests.sh
check_PROGRAMS = cppunittests
cppunittests_SOURCES = test/run_tests.cpp \
@@ -132,11 +124,15 @@ noinst_LIBRARIES = libmetadata.a
libmetadata_a_SOURCES = utils/metadata.h utils/metadata.cpp
libmetadata_a_CPPFLAGS = $(AM_CPPFLAGS) -Iutils
-noinst_PROGRAMS = variable_printer metadata_generator ast_printer instruo
+noinst_PROGRAMS = variable_printer metadata_generator ast_printer instruo bash
variable_printer_SOURCES = utils/variable_printer.cpp
variable_printer_LDADD = libcppbash.la
+bash_SOURCES = utils/bash.cpp test/test.h test/test.cpp
+bash_LDADD = libcppbash.la
+bash_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/test/
+
metadata_generator_SOURCES = utils/metadata_generator.cpp
metadata_generator_LDADD = libcppbash.la libmetadata.a
metadata_generator_CPPFLAGS = $(AM_CPPFLAGS) -Iutils
@@ -280,6 +276,9 @@ EXTRA_DIST = bashast/bashast.g \
test/ast_printer_test.sh \
test/verify_bashs_test.sh \
test/verify_error_output_test.sh \
+ test/bash_result_tests.sh \
+ scripts/naughty_tests \
+ scripts/naughty_tests.result \
scripts/source_false.sh \
scripts/source_true.sh \
scripts/source_return.sh \
@@ -292,7 +291,6 @@ EXTRA_DIST = bashast/bashast.g \
test_coverage.sh \
autogen.sh \
$(BASH_TESTS) \
- $(BASH_RESULT) \
$(EBUILD_TESTS) \
$(EBUILD_RESULT) \
$(GUNIT_TESTS) \
diff --git a/bashast/libbashWalker.g b/bashast/libbashWalker.g
index fe9e004..1edf10d 100644
--- a/bashast/libbashWalker.g
+++ b/bashast/libbashWalker.g
@@ -638,10 +638,13 @@ redirect_destination_input[std::unique_ptr<std::istream>& in]
argument[std::vector<std::string>& args]
: string_expr {
- if($string_expr.quoted)
- args.push_back($string_expr.libbash_value);
- else
- walker->split_word($string_expr.libbash_value, args);
+ if(!$string_expr.libbash_value.empty())
+ {
+ if($string_expr.quoted)
+ args.push_back($string_expr.libbash_value);
+ else
+ walker->split_word($string_expr.libbash_value, args);
+ }
};
logic_command_list
diff --git a/scripts/arithmetic_assignment.bash b/scripts/arithmetic_assignment.bash
index d8b1fe4..49f6751 100644
--- a/scripts/arithmetic_assignment.bash
+++ b/scripts/arithmetic_assignment.bash
@@ -1,19 +1,21 @@
value="$((100))"
-FOO001="$((value*=10))"
-FOO002="$((value/=10))"
-FOO003="$((value%=9))"
-FOO004="$((value+=10))"
-FOO005="$((value-=10))"
-FOO006="$((value<<=2))"
-FOO007="$((value>>=2))"
-FOO008="$((value&=10))"
-FOO009="$((value^=5))"
-FOO010="$((value|=10))"
+echo "$((value*=10))"
+echo "$((value/=10))"
+echo "$((value%=9))"
+echo "$((value+=10))"
+echo "$((value-=10))"
+echo "$((value<<=2))"
+echo "$((value>>=2))"
+echo "$((value&=10))"
+echo "$((value^=5))"
+echo "$((value|=10))"
FOO011=("CREATED" 2)
-FOO012="$((${FOO011[0]}=10))"
-FOO013="$((3!=5))"
+echo "$((${FOO011[0]}=10))"
+echo "$((3!=5))"
value=100
+echo $value
let "value=${value}"
+echo $value
a=c
b=d
c=1
diff --git a/scripts/arithmetic_assignment.bash.result b/scripts/arithmetic_assignment.bash.result
deleted file mode 100644
index dd8a219..0000000
--- a/scripts/arithmetic_assignment.bash.result
+++ /dev/null
@@ -1,22 +0,0 @@
-3
-4
-CREATED=10
-FOO001=1000
-FOO002=100
-FOO003=1
-FOO004=11
-FOO005=1
-FOO006=4
-FOO007=1
-FOO008=0
-FOO009=5
-FOO010=15
-FOO011=CREATED 2
-FOO012=10
-FOO013=1
-a=c
-b=d
-c=1
-d=2
-e=1+2
-value=100
diff --git a/scripts/binary_arithmetic.bash b/scripts/binary_arithmetic.bash
index 577ddbc..8aca099 100644
--- a/scripts/binary_arithmetic.bash
+++ b/scripts/binary_arithmetic.bash
@@ -1,67 +1,69 @@
ARRAY=(1 2 3 4 5)
-FOO001="$((0 || -2))"
-FOO002="$((0 || 0))"
-FOO003="$((-1 && 10))"
-FOO004="$((-1 && 0))"
-FOO005="$((1 | 2))"
-FOO006="$((4 & 2))"
-FOO007="$((5 ^ 10))"
-FOO008="$((5 <= 5))"
-FOO009="$((5 <= -10))"
-FOO010="$((5 >= 5))"
-FOO011="$((-5 >= 5))"
-FOO012="$((5 < 6))"
-FOO013="$((-5 < -5))"
-FOO014="$((5 > 4))"
-FOO015="$((-5 > -5))"
-FOO016="$((-5 << 2))"
-FOO017="$((-5 >> 2))"
-FOO018="$((1 + 1))"
-FOO019="$((10 - 5))"
-FOO020="$((10 * 5))"
-FOO021="$((10 / 4))"
-FOO022="$((10 % 4))"
-FOO023="$((10 ** 4))"
-FOO024="$((!10))"
-FOO025="$((~ 10))"
-FOO026="$((1?10:5))"
-FOO027="$((0?10:5))"
+echo "$((0 || -2))"
+echo "$((0 || 0))"
+echo "$((-1 && 10))"
+echo "$((-1 && 0))"
+echo "$((1 | 2))"
+echo "$((4 & 2))"
+echo "$((5 ^ 10))"
+echo "$((5 <= 5))"
+echo "$((5 <= -10))"
+echo "$((5 >= 5))"
+echo "$((-5 >= 5))"
+echo "$((5 < 6))"
+echo "$((-5 < -5))"
+echo "$((5 > 4))"
+echo "$((-5 > -5))"
+echo "$((-5 << 2))"
+echo $foo
+echo "$((-5 >> 2))"
+echo $foo
+echo "$((1 + 1))"
+echo "$((10 - 5))"
+echo "$((10 * 5))"
+echo "$((10 / 4))"
+echo "$((10 % 4))"
+echo "$((10 ** 4))"
+echo "$((!10))"
+echo "$((~ 10))"
+echo "$((1?10:5))"
+echo "$((0?10:5))"
value="$((100))"
-FOO028="$((++value))"
-FOO029="$((--value))"
-FOO030="$((value++))"
-FOO031="$((value--))"
+echo "$((++value))"
+echo "$((--value))"
+echo "$((value++))"
+echo "$((value--))"
value="$((100))"
-FOO032="$((value+++value++))"
-FOO033="$((++value+value++))"
-FOO034="$((10*(2+5)<<3%2**5))"
-FOO035="$((10*value<<3%2**5))"
-FOO036="$(( (20&5|3||1*100-20&5*10)+~(2*5) ))"
-FOO037="$((ARRAY[0]++))"
-FOO038="$((++ARRAY[0]))"
-FOO039="$((ARRAY[0]--))"
-FOO040="$((--ARRAY[0]))"
-FOO041="$((ARRAY[8]=9))"
-FOO042="$((ARRAY[8]*=10))"
-FOO043="$((ARRAY[8]/=10))"
-FOO044="$((ARRAY[8]%=2))"
-FOO045="$((ARRAY[8]+=8))"
-FOO046="$((ARRAY[8]-=0))"
-FOO047="$((ARRAY[8]<<=1))"
-FOO048="$((ARRAY[8]>>=1))"
-FOO049="$((ARRAY[8]&=5))"
-FOO050="$((ARRAY[8]|=10))"
-FOO051="$((ARRAY[8]^=3))"
+echo "$((value+++value++))"
+echo "$((++value+value++))"
+echo "$((10*(2+5)<<3%2**5))"
+echo "$((10*value<<3%2**5))"
+echo "$(( (20&5|3||1*100-20&5*10)+~(2*5) ))"
+echo "$((ARRAY[0]++))"
+echo "$((++ARRAY[0]))"
+echo "$((ARRAY[0]--))"
+echo "$((--ARRAY[0]))"
+echo "$((ARRAY[8]=9))"
+echo "$((ARRAY[8]*=10))"
+echo "$((ARRAY[8]/=10))"
+echo "$((ARRAY[8]%=2))"
+echo "$((ARRAY[8]+=8))"
+echo "$((ARRAY[8]-=0))"
+echo "$((ARRAY[8]<<=1))"
+echo "$((ARRAY[8]>>=1))"
+echo "$((ARRAY[8]&=5))"
+echo "$((ARRAY[8]|=10))"
+echo "$((ARRAY[8]^=3))"
PARTIAL[8]=5
-FOO052="$((PARTIAL[8]*=1))"
-FOO053="$((${#ARRAY[@]}))"
-FOO054="$((${ARRAY[5]:-10}))"
-FOO055="$((${ARRAY:0}))"
+echo "$((PARTIAL[8]*=1))"
+echo "$((${#ARRAY[@]}))"
+echo "$((${ARRAY[5]:-10}))"
+echo "$((${ARRAY:0}))"
value=100
FOO056="value"
-FOO057="$((${FOO056}++))"
-FOO058="$((${FOO056}+=10))"
+echo "$((${FOO056}++))"
+echo "$((${FOO056}+=10))"
ARRAY=(1 2 3 4 5)
FOO059="$((100**0))"
-FOO060="$((FOO059||FOO059++))"
-FOO061="$((0&&FOO059++))"
+echo "$((FOO059||FOO059++))"
+echo "$((0&&FOO059++))"
diff --git a/scripts/binary_arithmetic.bash.result b/scripts/binary_arithmetic.bash.result
deleted file mode 100644
index 926b23a..0000000
--- a/scripts/binary_arithmetic.bash.result
+++ /dev/null
@@ -1,64 +0,0 @@
-ARRAY=1 2 3 4 5
-FOO001=1
-FOO002=0
-FOO003=1
-FOO004=0
-FOO005=3
-FOO006=0
-FOO007=15
-FOO008=1
-FOO009=0
-FOO010=1
-FOO011=0
-FOO012=1
-FOO013=0
-FOO014=1
-FOO015=0
-FOO016=-20
-FOO017=-2
-FOO018=2
-FOO019=5
-FOO020=50
-FOO021=2
-FOO022=2
-FOO023=10000
-FOO024=0
-FOO025=-11
-FOO026=10
-FOO027=5
-FOO028=101
-FOO029=100
-FOO030=100
-FOO031=101
-FOO032=201
-FOO033=206
-FOO034=560
-FOO035=8320
-FOO036=-10
-FOO037=1
-FOO038=3
-FOO039=3
-FOO040=1
-FOO041=9
-FOO042=90
-FOO043=9
-FOO044=1
-FOO045=9
-FOO046=9
-FOO047=18
-FOO048=9
-FOO049=1
-FOO050=11
-FOO051=8
-FOO052=5
-FOO053=6
-FOO054=10
-FOO055=1
-FOO056=value
-FOO057=100
-FOO058=111
-FOO059=1
-FOO060=1
-FOO061=0
-PARTIAL=5
-value=111
diff --git a/scripts/command_execution.bash b/scripts/command_execution.bash
index dff9984..33200bd 100644
--- a/scripts/command_execution.bash
+++ b/scripts/command_execution.bash
@@ -7,7 +7,9 @@ echo hello world
true
false
FOO001=$(echo hello)
+echo $FOO001
FOO002=$(hi)
+echo $FOO002
true &&
echo "right"
false && echo "wrong"
@@ -19,8 +21,9 @@ echo "end"
: ${DEFAULTED:="yes"}
FOO="abc" echo "command environment"
export FOO003=1 FOO004=abc FOO005=(1 2 3) FOO002
+echo $FOO003 $FOO004 $FOO005 $FOO002
export foo
-abc=1 export foo
+echo $foo
echo "hi" > /dev/null
function unset_inner()
@@ -49,13 +52,15 @@ declare -F unset_outer
echo '$FOO006 "abc" $(( 1 + 2 )) $(echo hi) ...'
echo "abc $(echo def) ghi"
FOO008="abc $(echo def) ghi"
+echo $FOO008
eval "FOO009=10"
+echo $FOO009
eval "echo abc" "def" "xyz"
shopt -s extglob
-shopt -p
printf "%s %s\n" abc def
printf "%s %s\n" $FOO001, def
((FOO010=1))
+echo $FOO010
echo "abc #av### ##" # for comment
echo $'abc\tdef\nxyz'
echo -e "\'\"\t\n"
diff --git a/scripts/compound_command.bash.result b/scripts/compound_command.bash.result
deleted file mode 100644
index c083e6a..0000000
--- a/scripts/compound_command.bash.result
+++ /dev/null
@@ -1,61 +0,0 @@
-foo bar
-abc
-def
-ghi
-1
-2
-3
-5
-6
-7
-8
-9
-10
-bar
-foo
-foo
-2 foo
-2 bar
-3 foo
-3 bar
-1
-2
-3
-4
-2
-3
-4
-2
-1
-2
-3
-4
-2
-3
-4
-2
-1
-2
-1
-1
-yep
-default
-yep
-yep
-yep
-yep
-yep
-yep
-yep
-yep
-yep
-case end
-a=1
-b=2
-bar=
-file=foo
-foo=ghi
-i=1
-j=1
-outer=1
-target=_
diff --git a/scripts/function_def.bash.result b/scripts/function_def.bash.result
deleted file mode 100644
index a4af30a..0000000
--- a/scripts/function_def.bash.result
+++ /dev/null
@@ -1,29 +0,0 @@
-1 2 3
-
-3
-0
-2
-0
-hi
-right
-hi 1 1
-
-overloaded let
-1 2 3
-1 2 3
-1a2a3
-1 2 3
-function_in_compound_statement
-ARG1=100
-ARG2=2
-ARG3=3
-ARG4=4
-ARG5=
-ARG6=4
-ARG7=
-ARRAY=1 2 3
-EAPI=5
-FOO001=4 5
-MY_PV=2.0.3-r1
-RETURN_STATUS=1
-RETURN_STATUS2=0
diff --git a/scripts/isolated_functions.bash b/scripts/isolated_functions.bash
index ffdc14d..bf65f3e 100644
--- a/scripts/isolated_functions.bash
+++ b/scripts/isolated_functions.bash
@@ -1,3 +1,4 @@
+source $srcdir/utils/isolated-functions.sh
die "something wrong"
has 123 456 123 456 && echo true
has 123 456 13 456 && echo false
diff --git a/scripts/isolated_functions.bash.result b/scripts/isolated_functions.bash.result
deleted file mode 100644
index a56974f..0000000
--- a/scripts/isolated_functions.bash.result
+++ /dev/null
@@ -1,12 +0,0 @@
-Die is called: something wrong
-true
-Die is called: EXPORT_FUNCTIONS without a defined ECLASS
-hi
-use shouldn't be called
-useq shouldn't be called
-use_with shouldn't be called
-use_enable shouldn't be called
-eerror: foo
-debug-print: foo
-ewarn: foo
-item=123
diff --git a/scripts/naughty_tests b/scripts/naughty_tests
new file mode 100644
index 0000000..3c440f4
--- /dev/null
+++ b/scripts/naughty_tests
@@ -0,0 +1,8 @@
+# The following tests may generate different results depending on the version of bash
+FOO039="Hello World"
+shopt -s extglob
+echo ${FOO039//*(l)}
+echo ${FOO039//*(l|e)}
+echo ${FOO039//?(l)}
+echo ${FOO039//?(l|e|o)}
+shopt -p
diff --git a/scripts/command_execution.bash.result b/scripts/naughty_tests.result
index 0e2e1d6..a5d2ae5 100644
--- a/scripts/command_execution.bash.result
+++ b/scripts/naughty_tests.result
@@ -1,20 +1,7 @@
-Hello World
-hello world
-right
-right
-end
-command environment
-We do not support command env before the export builtin.
-FOO006=1 in unset_outer
-FOO007= in unset_outer
-FOO006= in unset_outer
-FOO006= in global
-FOO006=0 in global
-FOO006= in global
-unset_outer
-$FOO006 "abc" $(( 1 + 2 )) $(echo hi) ...
-abc def ghi
-abc def xyz
+Heo Word
+Ho Word
+Heo Word
+H Wrd
shopt -u autocd
shopt -u cdable_vars
shopt -u cdspell
@@ -23,13 +10,15 @@ shopt -u checkjobs
shopt -u checkwinsize
shopt -u cmdhist
shopt -u compat31
+shopt -u compat32
+shopt -u compat40
shopt -u dirspell
shopt -u dotglob
shopt -u execfail
shopt -u expand_aliases
shopt -u extdebug
shopt -s extglob
-shopt -u extquote
+shopt -s extquote
shopt -u failglob
shopt -u force_fignore
shopt -u globstar
@@ -39,7 +28,7 @@ shopt -u histreedit
shopt -u histverify
shopt -u hostcomplete
shopt -u huponexit
-shopt -u interactive
+shopt -u interactive_comments
shopt -u lithist
shopt -u login_shell
shopt -u mailwarn
@@ -49,23 +38,8 @@ shopt -u nocasematch
shopt -u nullglob
shopt -u progcomp
shopt -u promptvars
-shopt -u restricted
+shopt -u restricted_shell
shopt -u shift_verbose
shopt -u sourcepath
shopt -u xpg_echo
-abc def
-hello, def
-abc #av### ##
-abc def
-xyz
-\'"
-
-DEFAULTED=yes
-FOO001=hello
-FOO002=Hello World
-FOO003=1
-FOO004=abc
-FOO005=1 2 3
-FOO008=abc def ghi
-FOO009=10
-FOO010=1
+FOO039=Hello World
diff --git a/scripts/test_expr.bash.result b/scripts/test_expr.bash.result
deleted file mode 100644
index fb147eb..0000000
--- a/scripts/test_expr.bash.result
+++ /dev/null
@@ -1,28 +0,0 @@
-1
-0
-0
-1
-1
-0
-1
-1
-0
-true1
-true2
-true3
-true4
-true5
-true6
-true7
-true8
-true9
-true10
-true11
-true12
-true13
-true14
-true15
-true16
-true17
-true18
-true19
diff --git a/scripts/var_def.bash b/scripts/var_def.bash
index fa07952..fe2441d 100644
--- a/scripts/var_def.bash
+++ b/scripts/var_def.bash
@@ -1,42 +1,77 @@
EAPI="1"
+echo $EAPI
DESCRIPTION="SunPinyin is a SLM (Statistical Language Model) based IME"
+echo $DESCRIPTION
HOMEPAGE="http://sunpinyin.googlecode.com"
+echo $HOMEPAGE
SRC_URI="http://open-gram.googlecode.com/files/dict.utf8.tar.bz2
+echo $SRC_URI
http://open-gram.googlecode.com/files/lm_sc.t3g.arpa.tar.bz2"
LICENSE="LGPL-2.1 CDDL"
+echo $LICENSE
SLOT="0"
+echo $SLOT
KEYWORDS="~amd64 ~x86"
+echo $KEYWORDS
IUSE=""
+echo $IUSE
RDEPEND="dev-db/sqlite:3"
+echo $RDEPEND
DEPEND="${RDEPEND}
+echo $DEPEND
dev-util/pkgconfig"
MY_PATCH=ldflags.patch
+echo $MY_PATCH
PATCH=("1.patch" 2.patch)
+echo ${PATCH[@]}
ARRAY01=(1 2 3 [5]=4 5)
+echo ${ARRAY01[@]}
ARRAY02=(1 2 3)
+echo ${ARRAY02[@]}
ARRAY02[2]=4
ARRAY02[3]=5
+echo ${ARRAY02[@]}
EMPTY=
+echo $EMPTY
PARTIAL[5]=5
+echo ${PARTIAL[@]}
ARRAY_LAST=${ARRAY01[6]}
+echo $ARRAY_LAST
EMPTY_ARRAY=()
+echo ${EMPTY_ARRAY[@]}
ARRAY03=(1 2 3)
+echo ${ARRAY03[@]}
ARRAY03[0]=
+echo ${ARRAY03[@]}
ARRAY04=(1 2 3)
+echo ${ARRAY04[@]}
# The following one is equivalent to ARRAY04[0]=
ARRAY04=
+echo ${ARRAY04[@]}
ARRAY05=(1 2 3 4 5)
+echo ${ARRAY05[@]}
ARRAY06=${ARRAY05[@]}
+echo ${ARRAY06[@]}
ARRAY07=${ARRAY05[*]}
+echo ${ARRAY07[@]}
ARRAY08="${ARRAY05[@]}"
+echo ${ARRAY08[@]}
ARRAY09="${ARRAY05[*]}"
+echo ${ARRAY09[@]}
IFS=";,:"
+echo "$IFS"
ARRAY10="${ARRAY05[*]}"
+echo ${ARRAY10[@]}
FOO001="networkmanager"
+echo $FOO001
FOO002="0.8.2"
+echo $FOO002
FOO003=${FOO001}-${FOO002}
+echo $FOO003
FOO004=$?
-FOO004=$!
+echo $FOO004
+echo $FOO004
FOO005=abc
+echo $FOO005
FOO005+=def
-echo $-
+echo $FOO005
diff --git a/scripts/var_def.bash.result b/scripts/var_def.bash.result
deleted file mode 100644
index 667c3e0..0000000
--- a/scripts/var_def.bash.result
+++ /dev/null
@@ -1,35 +0,0 @@
-$! has not been implemented yet
-Bh
-ARRAY01=1 2 3 4 5
-ARRAY02=1 2 4 5
-ARRAY03= 2 3
-ARRAY04= 2 3
-ARRAY05=1 2 3 4 5
-ARRAY06=1 2 3 4 5
-ARRAY07=1 2 3 4 5
-ARRAY08=1 2 3 4 5
-ARRAY09=1 2 3 4 5
-ARRAY10=1;2;3;4;5
-ARRAY_LAST=5
-DEPEND=dev-db/sqlite:3
- dev-util/pkgconfig
-DESCRIPTION=SunPinyin is a SLM (Statistical Language Model) based IME
-EAPI=1
-EMPTY=
-EMPTY_ARRAY=
-FOO001=networkmanager
-FOO002=0.8.2
-FOO003=networkmanager-0.8.2
-FOO004=
-FOO005=abcdef
-HOMEPAGE=http://sunpinyin.googlecode.com
-IUSE=
-KEYWORDS=~amd64 ~x86
-LICENSE=LGPL-2.1 CDDL
-MY_PATCH=ldflags.patch
-PARTIAL=5
-PATCH=1.patch 2.patch
-RDEPEND=dev-db/sqlite:3
-SLOT=0
-SRC_URI=http://open-gram.googlecode.com/files/dict.utf8.tar.bz2
- http://open-gram.googlecode.com/files/lm_sc.t3g.arpa.tar.bz2
diff --git a/scripts/var_expansion.bash b/scripts/var_expansion.bash
index 16573a9..f1f5e52 100644
--- a/scripts/var_expansion.bash
+++ b/scripts/var_expansion.bash
@@ -1,103 +1,99 @@
shopt -s extglob
ARRAY=(hi hello 1 2 3)
EAPI="3"
-EAPI4="$((EAPI+1))"
-FOO001="${EAPI:-hello}"
-FOO002="${EAPI3:-hello}"
-FOO003=123
-FOO004=$EAPI
-FOO005=$(( 1+1 ))
-FOO006=${EAPI:=hello}
-FOO007=${FOO008:=hello world}
+echo "$((EAPI+1))"
+echo "${EAPI:-hello}"
+echo "${EAPI3:-hello}"
+echo 123
+echo $EAPI
+echo $(( 1+1 ))
+echo ${EAPI:=hello}
+echo ${FOO008:=hello world}
FOO009=${EAPI:+hello}
-FOO010=${NOT_EXIST:+hello}
-FOO011=${FOO009:0}
-FOO012=${FOO009:2}
-FOO013=${FOO009: -2}
-FOO014=${FOO009:100}
-FOO015=${FOO009: -100}
-FOO016=${FOO009:(-5 + 5)}
-FOO017=${NOT_EXIST:0}
-FOO018=${FOO009:0:2}
-FOO019=${FOO009:2:2}
-FOO020=${FOO009: -2:2}
-FOO021=${FOO009:2:100}
-FOO022=${FOO009: -2:100}
-FOO023=${NOT_EXIST:0:2}
-FOO024=${#FOO009}
-FOO025=${#NOT_EXIST}
-FOO026="${ARRAY[0]:-hello}"
-FOO028="${ARRAY[5]:-hello}"
-FOO029="${ARRAY2[0]:=hello}"
-FOO030="${ARRAY2[0]:=hi}"
-FOO031="${ARRAY2[0]:+hi}"
-FOO032="${ARRAY2[1]:+hi}"
-FOO033="${ARRAY[1]:1}"
-FOO034="${ARRAY[1]:1:3}"
-FOO035="${#ARRAY[0]}"
-FOO036="${#ARRAY[@]}"
-FOO037="${#ARRAY[*]}"
-FOO038="${#ARRAY}"
+echo ${NOT_EXIST:+hello}
+echo ${FOO009:0}
+echo ${FOO009:2}
+echo ${FOO009: -2}
+echo ${FOO009:100}
+echo ${FOO009: -100}
+echo ${FOO009:(-5 + 5)}
+echo ${NOT_EXIST:0}
+echo ${FOO009:0:2}
+echo ${FOO009:2:2}
+echo ${FOO009: -2:2}
+echo ${FOO009:2:100}
+echo ${FOO009: -2:100}
+echo ${NOT_EXIST:0:2}
+echo ${#FOO009}
+echo ${#NOT_EXIST}
+echo "${ARRAY[0]:-hello}"
+echo "${ARRAY[5]:-hello}"
+echo "${ARRAY2[0]:=hello}"
+echo "${ARRAY2[0]:=hi}"
+echo "${ARRAY2[0]:+hi}"
+echo "${ARRAY2[1]:+hi}"
+echo "${ARRAY[1]:1}"
+echo "${ARRAY[1]:1:3}"
+echo "${#ARRAY[0]}"
+echo "${#ARRAY[@]}"
+echo "${#ARRAY[*]}"
+echo "${#ARRAY}"
FOO039="Hello World"
-FOO040=${FOO039/nothing/nothing}
-FOO041=${FOO039/o W/ow}
-FOO042=${FOO039//o/e}
-FOO043=${FOO039/#He/he}
-FOO044=${FOO039/#he/he}
-FOO045=${FOO039/%rld/rlD}
-FOO046=${FOO039/%rlD/rlD}
-FOO047=${FOO039/o W}
-FOO048=${FOO039//o}
-FOO049=${FOO039/#He}
-FOO050=${FOO039/#he}
-FOO051=${FOO039/%rld}
-FOO052=${FOO039/%rlD}
-FOO053=${FOO039/aaaaaaaaaaaa}
-FOO054=${FOO039#hello}
-FOO055=${FOO039##hello}
-FOO056=${FOO039#Hello}
-FOO057=${FOO039##Hello}
-FOO058=${FOO039%world}
-FOO059=${FOO039%%world}
-FOO060=${FOO039%World}
-FOO061=${FOO039%%World}
-FOO062=${FOO039#Hel*}
-FOO063=${FOO039##Hel*}
-FOO064=${FOO039%*rld}
-FOO065=${FOO039%%*rld}
-FOO066=${FOO039/l/r}
-FOO067=${FOO039//l/r}
-FOO068=${FOO039/#He/he}
-FOO069=${FOO039/#ello/i}
-FOO070=${FOO039/%ld/d}
-FOO071=${FOO039/%rl/r}
-FOO072=${FOO039/+(l)/}
-FOO073=${FOO039/+(l|e)}
-FOO074=${FOO039/*(l)}
-FOO075=${FOO039//*(l)}
-FOO076=${FOO039//*(l|e)}
-FOO077=${FOO039/?(l)}
-FOO078=${FOO039//?(l)}
-FOO079=${FOO039//?(l|e|o)}
-FOO080=${FOO039/@([a-c]|[k-m])}
-FOO081=${FOO039//@([a-c]|[k-m])}
+echo ${FOO039/nothing/nothing}
+echo ${FOO039/o W/ow}
+echo ${FOO039//o/e}
+echo ${FOO039/#He/he}
+echo ${FOO039/#he/he}
+echo ${FOO039/%rld/rlD}
+echo ${FOO039/%rlD/rlD}
+echo ${FOO039/o W}
+echo ${FOO039//o}
+echo ${FOO039/#He}
+echo ${FOO039/#he}
+echo ${FOO039/%rld}
+echo ${FOO039/%rlD}
+echo ${FOO039/aaaaaaaaaaaa}
+echo ${FOO039#hello}
+echo ${FOO039##hello}
+echo ${FOO039#Hello}
+echo ${FOO039##Hello}
+echo ${FOO039%world}
+echo ${FOO039%%world}
+echo ${FOO039%World}
+echo ${FOO039%%World}
+echo ${FOO039#Hel*}
+echo ${FOO039##Hel*}
+echo ${FOO039%*rld}
+echo ${FOO039%%*rld}
+echo ${FOO039/l/r}
+echo ${FOO039//l/r}
+echo ${FOO039/#He/he}
+echo ${FOO039/#ello/i}
+echo ${FOO039/%ld/d}
+echo ${FOO039/%rl/r}
+echo ${FOO039/+(l)/}
+echo ${FOO039/+(l|e)}
+echo ${FOO039/*(l)}
+echo ${FOO039/?(l)}
+echo ${FOO039/@([a-c]|[k-m])}
+echo ${FOO039//@([a-c]|[k-m])}
target="abc123abc"
-FOO082="${target##+(ab[c])*([[:digit:]])}"
+echo "${target##+(ab[c])*([[:digit:]])}"
function positional_parameter_test(){
- FOO083=$*
- FOO084=${*}
- FOO085=${*:1}
- FOO086=${*:1:2}
- FOO087=${*: -1}
- FOO088=${*: -2:5}
- FOO089=${*:0}
- FOO090=$@
- FOO091=${@}
- FOO092=${@:1}
- FOO093=${@:1:2}
- FOO094=${@: -1}
- FOO095=${@: -2:5}
- FOO096=${@:0}
+ echo $*
+ echo ${*}
+ echo ${*:1}
+ echo ${*:1:2}
+ echo ${*: -1}
+ echo ${*: -2:5}
+ echo ${*:0}
+ echo $@
+ echo ${@}
+ echo ${@:1}
+ echo ${@:1:2}
+ echo ${@: -1}
+ echo ${@: -2:5}
+ echo ${@:0}
echo $#
}
positional_parameter_test 1 2 3 4 5
diff --git a/scripts/var_expansion.bash.result b/scripts/var_expansion.bash.result
deleted file mode 100644
index 52c87c0..0000000
--- a/scripts/var_expansion.bash.result
+++ /dev/null
@@ -1,110 +0,0 @@
-5
-
-abcabc
-abcabc
-2 3 4 5
-2 3 4
-0
-abd acd
-aadef aadf abcdef abcdf
-aabdef aabdgh acddef acddgh
-ARRAY=1 2 3 4 5
-ARRAY2=hello
-EAPI=3
-EAPI4=4
-FOO001=3
-FOO002=hello
-FOO003=123
-FOO004=3
-FOO005=2
-FOO006=3
-FOO007=hello world
-FOO008=hello world
-FOO009=hello
-FOO010=
-FOO011=hello
-FOO012=llo
-FOO013=lo
-FOO014=
-FOO015=
-FOO016=hello
-FOO017=
-FOO018=he
-FOO019=ll
-FOO020=lo
-FOO021=llo
-FOO022=lo
-FOO023=
-FOO024=5
-FOO025=0
-FOO026=hi
-FOO028=hello
-FOO029=hello
-FOO030=hello
-FOO031=hi
-FOO032=
-FOO033=ello
-FOO034=ell
-FOO035=2
-FOO036=5
-FOO037=5
-FOO038=2
-FOO039=Hello World
-FOO040=Hello World
-FOO041=Helloworld
-FOO042=Helle Werld
-FOO043=hello World
-FOO044=Hello World
-FOO045=Hello WorlD
-FOO046=Hello World
-FOO047=Hellorld
-FOO048=Hell Wrld
-FOO049=llo World
-FOO050=Hello World
-FOO051=Hello Wo
-FOO052=Hello World
-FOO053=Hello World
-FOO054=Hello World
-FOO055=Hello World
-FOO056= World
-FOO057= World
-FOO058=Hello World
-FOO059=Hello World
-FOO060=Hello
-FOO061=Hello
-FOO062=lo World
-FOO063=
-FOO064=Hello Wo
-FOO065=
-FOO066=Herlo World
-FOO067=Herro Worrd
-FOO068=hello World
-FOO069=Hello World
-FOO070=Hello Word
-FOO071=Hello World
-FOO072=Heo World
-FOO073=Ho World
-FOO074=Hello World
-FOO075=Heo Word
-FOO076=Ho Word
-FOO077=Hello World
-FOO078=Heo Word
-FOO079=H Wrd
-FOO080=Helo World
-FOO081=Heo Word
-FOO082=abc
-FOO083=1 2 3 4 5
-FOO084=1 2 3 4 5
-FOO085=1 2 3 4 5
-FOO086=1 2
-FOO087=5
-FOO088=4 5
-FOO089=@srcdir@/scripts/var_expansion.bash 1 2 3 4 5
-FOO090=1 2 3 4 5
-FOO091=1 2 3 4 5
-FOO092=1 2 3 4 5
-FOO093=1 2
-FOO094=5
-FOO095=4 5
-FOO096=@srcdir@/scripts/var_expansion.bash 1 2 3 4 5
-target=abc*abc
diff --git a/src/builtins/echo_builtin.cpp b/src/builtins/echo_builtin.cpp
index 9440232..d3a1f27 100644
--- a/src/builtins/echo_builtin.cpp
+++ b/src/builtins/echo_builtin.cpp
@@ -91,7 +91,7 @@ bool echo_builtin::determine_options(const std::string &string, bool &suppress_n
bool n_matched = false, e_matched = false, E_matched = false;
- auto options = '-' >
+ auto options = '-' >>
+(
char_('n')[ref(n_matched) = true] |
char_('e')[ref(e_matched) = true, ref(E_matched) = false] |
diff --git a/src/core/interpreter.cpp b/src/core/interpreter.cpp
index 539b9f1..a92bea3 100644
--- a/src/core/interpreter.cpp
+++ b/src/core/interpreter.cpp
@@ -68,13 +68,15 @@ interpreter::interpreter(): _out(&std::cout), _err(&std::cerr), _in(&std::cin),
{"checkwinsize", false},
{"cmdhist", false},
{"compat31", false},
+ {"compat32", false},
+ {"compat40", false},
{"dirspell", false},
{"dotglob", false},
{"execfail", false},
{"expand_aliases", false},
{"extdebug", false},
{"extglob", false},
- {"extquote", false},
+ {"extquote", true},
{"failglob", false},
{"force_fignore", false},
{"globstar", false},
@@ -84,7 +86,7 @@ interpreter::interpreter(): _out(&std::cout), _err(&std::cerr), _in(&std::cin),
{"histverify", false},
{"hostcomplete", false},
{"huponexit", false},
- {"interactive", false},
+ {"interactive_comments", false},
{"lithist", false},
{"login_shell", false},
{"mailwarn", false},
@@ -94,7 +96,7 @@ interpreter::interpreter(): _out(&std::cout), _err(&std::cerr), _in(&std::cin),
{"nullglob", false},
{"progcomp", false},
{"promptvars", false},
- {"restricted", false},
+ {"restricted_shell", false},
{"shift_verbose", false},
{"sourcepath", false},
{"xpg_echo", false},
diff --git a/test/bash_compiler.sh b/test/bash_compiler.sh
new file mode 100755
index 0000000..54b8178
--- /dev/null
+++ b/test/bash_compiler.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+declare -i error=0
+result=$(mktemp)
+
+for script in $@
+do
+ srcdir=$srcdir ./bash $script > $result 2>&1
+ srcdir=$srcdir bash +O cmdhist \
+ +O force_fignore \
+ +O hostcomplete \
+ +O interactive_comments \
+ +O progcomp \
+ +O promptvars \
+ +O sourcepath \
+ $script | diff -u $result -
+ error+=$?
+done
+
+rm -rf $result
+exit $error
diff --git a/test/bash_result_tests.sh b/test/bash_result_tests.sh
new file mode 100755
index 0000000..a118cc3
--- /dev/null
+++ b/test/bash_result_tests.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+./variable_printer $srcdir/scripts/naughty_tests | diff -u $srcdir/scripts/naughty_tests.result -
diff --git a/test/script_compiler.sh b/test/script_compiler.sh
deleted file mode 100755
index 6ff5672..0000000
--- a/test/script_compiler.sh
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/bin/sh
-
-declare -i error=0
-result=$(mktemp)
-
-for script in $@
-do
- sed "s/@srcdir@/$srcdir/" $script.result > $result
- ./variable_printer $script 2>&1 | diff -u $result -
- error+=$?
-done
-
-rm -rf $result
-exit $error
diff --git a/utils/bash.cpp b/utils/bash.cpp
new file mode 100644
index 0000000..efb51f9
--- /dev/null
+++ b/utils/bash.cpp
@@ -0,0 +1,63 @@
+/*
+ Please use git log for copyright holder and year information
+
+ This file is part of libbash.
+
+ libbash is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ libbash is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libbash. If not, see <http://www.gnu.org/licenses/>.
+*/
+///
+/// \file bash_runner.cpp
+/// \brief a program to write variables in a script into standard output
+///
+
+#include <algorithm>
+#include <iostream>
+#include <map>
+
+#include <gtest/gtest.h>
+#include <boost/spirit/include/karma.hpp>
+#include <boost/fusion/include/std_pair.hpp>
+
+#include "libbash.h"
+#include "test.h"
+
+static const std::vector<std::string> special_variables
+{
+ "IFS", "*", "0", "-"
+};
+
+int main(int argc, char** argv)
+{
+ if(argc != 2)
+ {
+ std::cerr<<"Please provide your script as an argument"<<std::endl;
+ exit(EXIT_FAILURE);
+ }
+
+ std::unordered_map<std::string, std::vector<std::string>> variables{
+ {"srcdir", std::vector<std::string>({get_src_dir()})}
+ };
+ std::vector<std::string> functions;
+ try
+ {
+ libbash::interpret(argv[1], variables, functions);
+ }
+ catch(libbash::interpreter_exception& e)
+ {
+ std::cerr << e.what() << std::endl;
+ return EXIT_FAILURE;
+ }
+
+ return 0;
+}