aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-11-23 18:31:48 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2016-11-23 18:31:48 +0100
commit15fb91cefb22d64952f34fe246fc8f257172af63 (patch)
treeb26c3168f2ea5e185eee1041c6f521855398783a
parent73f743a381dc389287d2d0e56a2b7988f67c0bfc (diff)
downloadbusybox-15fb91cefb22d64952f34fe246fc8f257172af63.tar.gz
test: make [ and [[ forms individually selectable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--coreutils/test.c26
-rwxr-xr-xinclude/applets.h.sh8
-rw-r--r--shell/ash.c4
3 files changed, 29 insertions, 9 deletions
diff --git a/coreutils/test.c b/coreutils/test.c
index 81c9b7dfe..9e18ee986 100644
--- a/coreutils/test.c
+++ b/coreutils/test.c
@@ -27,19 +27,33 @@
//config: returning an appropriate exit code. The bash shell
//config: has test built in, ash can build it in optionally.
//config:
+//config:config TEST1
+//config: bool "test as ["
+//config: default y
+//config: help
+//config: Provide test command in the "[ EXPR ]" form
+//config:
+//config:config TEST2
+//config: bool "test as [["
+//config: default y
+//config: help
+//config: Provide test command in the "[[ EXPR ]]" form
+//config:
//config:config FEATURE_TEST_64
//config: bool "Extend test to 64 bit"
//config: default y
-//config: depends on TEST || ASH_BUILTIN_TEST || HUSH
+//config: depends on TEST || TEST1 || TEST2 || ASH_BUILTIN_TEST || HUSH
//config: help
//config: Enable 64-bit support in test.
-//applet:IF_TEST(APPLET_NOFORK([, test, BB_DIR_USR_BIN, BB_SUID_DROP, test))
-//applet:IF_TEST(APPLET_NOFORK([[, test, BB_DIR_USR_BIN, BB_SUID_DROP, test))
//applet:IF_TEST(APPLET_NOFORK(test, test, BB_DIR_USR_BIN, BB_SUID_DROP, test))
+//applet:IF_TEST1(APPLET_NOFORK([, test, BB_DIR_USR_BIN, BB_SUID_DROP, test))
+//applet:IF_TEST2(APPLET_NOFORK([[, test, BB_DIR_USR_BIN, BB_SUID_DROP, test))
//kbuild:lib-$(CONFIG_TEST) += test.o test_ptr_hack.o
-//kbuild:lib-$(CONFIG_ASH) += test.o test_ptr_hack.o
+//kbuild:lib-$(CONFIG_TEST1) += test.o test_ptr_hack.o
+//kbuild:lib-$(CONFIG_TEST2) += test.o test_ptr_hack.o
+//kbuild:lib-$(CONFIG_ASH_BUILTIN_TEST) += test.o test_ptr_hack.o
//kbuild:lib-$(CONFIG_HUSH) += test.o test_ptr_hack.o
/* "test --help" is special-cased to ignore --help */
@@ -827,7 +841,9 @@ int test_main(int argc, char **argv)
const char *arg0;
arg0 = bb_basename(argv[0]);
- if (arg0[0] == '[') {
+ if ((ENABLE_TEST1 || ENABLE_TEST2 || ENABLE_ASH_BUILTIN_TEST || ENABLE_HUSH)
+ && (arg0[0] == '[')
+ ) {
--argc;
if (!arg0[1]) { /* "[" ? */
if (NOT_LONE_CHAR(argv[argc], ']')) {
diff --git a/include/applets.h.sh b/include/applets.h.sh
index 6b8046c4b..bab4e0d72 100755
--- a/include/applets.h.sh
+++ b/include/applets.h.sh
@@ -5,13 +5,17 @@
# CONFIG_applet names
grep ^IF_ applets.h | grep -v IF_FEATURE_ | sed 's/IF_\([A-Z0-9._-]*\)(.*/\1/' \
-| grep -v MODPROBE_SMALL | sed 's/BB_SYSCTL/SYSCTL/' \
+| grep -v MODPROBE_SMALL \
+| sed 's/BB_SYSCTL/SYSCTL/' \
+| sed 's/TEST1/[/' \
+| sed 's/TEST2/[[/' \
| sort | uniq \
>applets_APP1
# command line applet names
grep ^IF_ applets.h | sed -e's/ //g' -e's/.*(\([a-z[][^,]*\),.*/\1/' \
-| grep -v '^bash$' | grep -v '^sh$' \
+| grep -v '^bash$' \
+| grep -v '^sh$' \
| tr a-z A-Z \
| sort | uniq \
>applets_APP2
diff --git a/shell/ash.c b/shell/ash.c
index 87f2127a1..15246f55f 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -9282,9 +9282,9 @@ static const struct builtincmd builtintab[] = {
{ BUILTIN_SPEC_REG ":" , truecmd },
#if ENABLE_ASH_BUILTIN_TEST
{ BUILTIN_REGULAR "[" , testcmd },
-#if ENABLE_ASH_BASH_COMPAT
+# if ENABLE_ASH_BASH_COMPAT
{ BUILTIN_REGULAR "[[" , testcmd },
-#endif
+# endif
#endif
#if ENABLE_ASH_ALIAS
{ BUILTIN_REG_ASSG "alias" , aliascmd },