1 // SPDX-License-Identifier: GPL-2.0
11 #include <asm/global_data.h>
13 DECLARE_GLOBAL_DATA_PTR;
15 static int hush_test_for(struct unit_test_state *uts)
17 ut_assertok(run_command("for loop_i in foo bar quux quux; do echo $loop_i; done", 0));
18 ut_assert_nextline("foo");
19 ut_assert_nextline("bar");
20 ut_assert_nextline("quux");
21 ut_assert_nextline("quux");
22 ut_assert_console_end();
24 if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) {
25 /* Reset local variable. */
26 ut_assertok(run_command("loop_i=", 0));
27 } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
28 puts("Beware: this test set local variable loop_i and it cannot be unset!\n");
33 HUSH_TEST(hush_test_for, UTF_CONSOLE);
35 static int hush_test_while(struct unit_test_state *uts)
37 if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) {
39 * Hush 2021 always returns 0 from while loop...
40 * You can see code snippet near this line to have a better
42 * debug_printf_exec(": while expr is false: breaking (exitcode:EXIT_SUCCESS)\n");
44 ut_assertok(run_command("while test -z \"$loop_foo\"; do echo bar; loop_foo=quux; done", 0));
45 } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
47 * Exit status is that of test, so 1 since test is false to quit
50 ut_asserteq(1, run_command("while test -z \"$loop_foo\"; do echo bar; loop_foo=quux; done", 0));
52 ut_assert_nextline("bar");
53 ut_assert_console_end();
55 if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) {
56 /* Reset local variable. */
57 ut_assertok(run_command("loop_foo=", 0));
58 } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
59 puts("Beware: this test set local variable loop_foo and it cannot be unset!\n");
64 HUSH_TEST(hush_test_while, UTF_CONSOLE);
66 static int hush_test_until(struct unit_test_state *uts)
68 env_set("loop_bar", "bar");
71 * WARNING We have to use environment variable because it is not possible
72 * resetting local variable.
74 ut_assertok(run_command("until test -z \"$loop_bar\"; do echo quux; setenv loop_bar; done", 0));
75 ut_assert_nextline("quux");
76 ut_assert_console_end();
79 * Loop normally resets foo environment variable, but we reset it here in
80 * case the test failed.
82 env_set("loop_bar", NULL);
85 HUSH_TEST(hush_test_until, UTF_CONSOLE);