summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTom Rini <[email protected]>2026-03-25 14:38:02 -0600
committerTom Rini <[email protected]>2026-03-25 14:38:02 -0600
commit6701997e9ca2cab0c0e1cde96437ac1dabefdaa1 (patch)
tree66be5429de16b766e7eef0132b498e71bbfcfd27 /test
parent1e2052f76e98ae70ab29113d271bb376ed23e8bb (diff)
parent8b0619579b2282050e7fb0d92fbc645b79d18bae (diff)
Merge patch series "add [ as alias for test, fix 0/1 argument handling"
Rasmus Villemoes <[email protected]> says: Make 'test' behave a little more like its cousins in other shells, by allowing the [ ... ] spelling, and while here, fix up the handling of a single, non-empty argument to comply with POSIX. Link: https://lore.kernel.org/r/[email protected]
Diffstat (limited to 'test')
-rw-r--r--test/hush/if.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/test/hush/if.c b/test/hush/if.c
index ea615b246a9..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);
@@ -315,3 +324,67 @@ static int hush_test_if_z_operator(struct unit_test_state *uts)
return 0;
}
HUSH_TEST(hush_test_if_z_operator, 0);
+
+static int hush_test_lbracket_alias(struct unit_test_state *uts)
+{
+ char if_formatted[128];
+ const char *missing_rbracket_error = "[: missing terminating ]";
+
+ sprintf(if_formatted, if_format, "[ aaa = aaa ]");
+ ut_assertok(run_command(if_formatted, 0));
+
+ sprintf(if_formatted, if_format, "[ aaa = bbb ]");
+ ut_asserteq(1, run_command(if_formatted, 0));
+
+ sprintf(if_formatted, if_format, "[ aaa = aaa");
+ ut_asserteq(1, run_command(if_formatted, 0));
+ ut_assert_nextline(missing_rbracket_error);
+
+ sprintf(if_formatted, if_format, "[ aaa = bbb");
+ ut_asserteq(1, run_command(if_formatted, 0));
+ ut_assert_nextline(missing_rbracket_error);
+
+ sprintf(if_formatted, if_format, "[ aaa = aaa]");
+ ut_asserteq(1, run_command(if_formatted, 0));
+ ut_assert_nextline(missing_rbracket_error);
+
+ sprintf(if_formatted, if_format, "[ aaa = bbb]");
+ ut_asserteq(1, run_command(if_formatted, 0));
+ ut_assert_nextline(missing_rbracket_error);
+
+ sprintf(if_formatted, if_format, "[ aaa != aaa -o bbb != bbb ]");
+ ut_asserteq(1, run_command(if_formatted, 0));
+
+ sprintf(if_formatted, if_format, "[ aaa != aaa -o bbb = bbb ]");
+ ut_assertok(run_command(if_formatted, 0));
+
+ sprintf(if_formatted, if_format, "[ ! aaa != aaa -o ! bbb != bbb ]");
+ ut_assertok(run_command(if_formatted, 0));
+
+ 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);