summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRasmus Villemoes <[email protected]>2026-03-12 11:01:05 +0100
committerTom Rini <[email protected]>2026-03-25 14:37:55 -0600
commit6f9cc3310a764aaae4478b5a8a0c0cae3b2be4a1 (patch)
tree3a46b352362277181ce12f2771c7eaf514a3a549 /test
parentd44f61582947564991cce7501f2e5db0b29ebad6 (diff)
test: add tests for left-bracket alias for 'test' command
Duplicate a few of the existing test cases, using the [ spelling, and also ensure that the presence of a matching ] as a separate and last argument is enforced. Signed-off-by: Rasmus Villemoes <[email protected]> Tested-by: Anshul Dalal <[email protected]>
Diffstat (limited to 'test')
-rw-r--r--test/hush/if.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/hush/if.c b/test/hush/if.c
index ea615b246a9..5f75ea68b32 100644
--- a/test/hush/if.c
+++ b/test/hush/if.c
@@ -315,3 +315,46 @@ 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));
+
+ return 0;
+}
+HUSH_TEST(hush_test_lbracket_alias, UTF_CONSOLE);