mirror of
https://source.denx.de/u-boot/u-boot.git
synced 2026-06-13 15:03:58 +03:00
Merge patch series "add [ as alias for test, fix 0/1 argument handling"
Rasmus Villemoes <ravi@prevas.dk> 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/20260312100106.702368-1-ravi@prevas.dk
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user