diff mbox series

[RFC,v1,21/21] test: hush: Fix loop tests for hush 2021.

Message ID 20211231161327.24918-22-francis.laniel@amarulasolutions.com
State RFC
Delegated to: Tom Rini
Headers show
Series Modernize U-Boot shell | expand

Commit Message

Francis Laniel Dec. 31, 2021, 4:13 p.m. UTC
This commit modifies return code got from while loop as hush 2021 always returns
0 from while loop.

Signed-off-by: Francis Laniel <francis.laniel@amarulasolutions.com>
---
 test/hush/loop.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Comments

Simon Glass Jan. 12, 2022, 8:03 p.m. UTC | #1
On Fri, 31 Dec 2021 at 09:14, Francis Laniel
<francis.laniel@amarulasolutions.com> wrote:
>
> This commit modifies return code got from while loop as hush 2021 always returns
> 0 from while loop.
>
> Signed-off-by: Francis Laniel <francis.laniel@amarulasolutions.com>
> ---
>  test/hush/loop.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>
diff mbox series

Patch

diff --git a/test/hush/loop.c b/test/hush/loop.c
index 519c78ef7e..56aae719dc 100644
--- a/test/hush/loop.c
+++ b/test/hush/loop.c
@@ -20,7 +20,12 @@  static int hush_test_for(struct unit_test_state *uts)
 	ut_assert_nextline("quux");
 	ut_assert_console_end();
 
+#if CONFIG_IS_ENABLED(HUSH_2021_PARSER)
+	/* Reset local variable. */
+	ut_assertok(run_command("loop_i=", 0));
+#else /* HUSH_OLD_PARSER */
 	puts("Beware: this test set local variable loop_i and it cannot be unset!");
+#endif /* HUSH_OLD_PARSER */
 
 	return 0;
 }
@@ -30,12 +35,27 @@  static int hush_test_while(struct unit_test_state *uts)
 {
 	console_record_reset_enable();
 
+#if CONFIG_IS_ENABLED(HUSH_2021_PARSER)
+	/*
+	 * Hush 2021 always returns 0 from while loop...
+	 * You can see code snippet near this line to have a better
+	 * understanding:
+	 * debug_printf_exec(": while expr is false: breaking (exitcode:EXIT_SUCCESS)\n");
+	 */
+	ut_assertok(run_command("while test -z \"$loop_foo\"; do echo bar; loop_foo=quux; done", 0));
+#else /* HUSH_OLD_PARSER */
 	/* Exit status is that of test, so 1 since test is false to quit the loop. */
 	ut_asserteq(1, run_command("while test -z \"$loop_foo\"; do echo bar; loop_foo=quux; done", 0));
+#endif /* HUSH_OLD_PARSER */
 	ut_assert_nextline("bar");
 	ut_assert_console_end();
 
+#if CONFIG_IS_ENABLED(HUSH_2021_PARSER)
+	/* Reset local variable. */
+	ut_assertok(run_command("loop_foo=", 0));
+#else /* HUSH_OLD_PARSER */
 	puts("Beware: this test set local variable loop_foo and it cannot be unset!");
+#endif /* HUSH_OLD_PARSER */
 
 	return 0;
 }