summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRasmus Villemoes <[email protected]>2026-03-12 11:01:06 +0100
committerTom Rini <[email protected]>2026-03-25 14:37:55 -0600
commit8b0619579b2282050e7fb0d92fbc645b79d18bae (patch)
tree9f2fd0ce8625dc8a5709f423420ec232c9a9f51b /test
parent6f9cc3310a764aaae4478b5a8a0c0cae3b2be4a1 (diff)
cmd: test: fix handling of single-argument form of test
POSIX states that 0 arguments: Exit false (1). 1 argument: Exit true (0) if $1 is not null; otherwise, exit false. and at least bash and busybox sh behave that way. The current 'argc < 3' does the right thing for a non-existing or empty argv[1], but not for a non-empty argv[1]. Fix that and add corresponding test cases. Signed-off-by: Rasmus Villemoes <[email protected]> Tested-by: Anshul Dalal <[email protected]>
Diffstat (limited to 'test')
-rw-r--r--test/hush/if.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/hush/if.c b/test/hush/if.c
index 5f75ea68b32..6129e2c530c 100644
--- a/test/hush/if.c
+++ b/test/hush/if.c
@@ -32,6 +32,15 @@ static int hush_test_if_base(struct unit_test_state *uts)
sprintf(if_formatted, if_format, "false");
ut_asserteq(1, run_command(if_formatted, 0));
+ sprintf(if_formatted, if_format, "test");
+ ut_asserteq(1, run_command(if_formatted, 0));
+
+ sprintf(if_formatted, if_format, "test ''");
+ ut_asserteq(1, run_command(if_formatted, 0));
+
+ sprintf(if_formatted, if_format, "test 'abc'");
+ ut_assertok(run_command(if_formatted, 0));
+
return 0;
}
HUSH_TEST(hush_test_if_base, 0);
@@ -355,6 +364,27 @@ static int hush_test_lbracket_alias(struct unit_test_state *uts)
sprintf(if_formatted, if_format, "[ ! aaa != aaa -o ! bbb = bbb ]");
ut_assertok(run_command(if_formatted, 0));
+ sprintf(if_formatted, if_format, "[ ]");
+ ut_asserteq(1, run_command(if_formatted, 0));
+
+ sprintf(if_formatted, if_format, "[");
+ ut_asserteq(1, run_command(if_formatted, 0));
+ ut_assert_nextline(missing_rbracket_error);
+
+ sprintf(if_formatted, if_format, "[ '' ]");
+ ut_asserteq(1, run_command(if_formatted, 0));
+
+ sprintf(if_formatted, if_format, "[ ''");
+ ut_asserteq(1, run_command(if_formatted, 0));
+ ut_assert_nextline(missing_rbracket_error);
+
+ sprintf(if_formatted, if_format, "[ 'abc' ]");
+ ut_assertok(run_command(if_formatted, 0));
+
+ sprintf(if_formatted, if_format, "[ 'abc'");
+ ut_asserteq(1, run_command(if_formatted, 0));
+ ut_assert_nextline(missing_rbracket_error);
+
return 0;
}
HUSH_TEST(hush_test_lbracket_alias, UTF_CONSOLE);