[RFC PATCH v1 19/21] test: hush: Fix if tests for hush 2021.

Francis Laniel francis.laniel at amarulasolutions.com
Fri Dec 31 17:13:25 CET 2021


This commit modifies the command run for hush 2021 when using string comparison
operator.
Indeed, '<' and '>' must be escaped to be used as string comparison operator.

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

diff --git a/test/hush/if.c b/test/hush/if.c
index a57d88850f..b2f1f247f5 100644
--- a/test/hush/if.c
+++ b/test/hush/if.c
@@ -39,6 +39,10 @@ static int hush_test_if_basic_operators(struct unit_test_state *uts)
 {
 	char if_formatted[128];
 
+#if CONFIG_IS_ENABLED(HUSH_2021_PARSER)
+	console_record_reset_enable();
+#endif /* HUSH_2021_PARSER */
+
 	sprintf(if_formatted, if_format, "test aaa = aaa");
 	ut_assertok(run_command(if_formatted, 0));
 
@@ -52,15 +56,54 @@ static int hush_test_if_basic_operators(struct unit_test_state *uts)
 	ut_asserteq(1, run_command(if_formatted, 0));
 
 	sprintf(if_formatted, if_format, "test aaa < bbb");
+#if CONFIG_IS_ENABLED(HUSH_2021_PARSER)
+	/*
+	 * We need to escape < and > to use as them as string comparison
+	 * operator.
+	 * Otherwise, they are interprated as redirection operators which is not
+	 * supported in U-Boot.
+	 */
+	ut_asserteq(1, run_command(if_formatted, 0));
+	/* Next lines contains error message (which is on two lines). */
+	ut_assert_skipline();
+	ut_assert_skipline();
+	ut_assert_console_end();
+
+	sprintf(if_formatted, if_format, R"(test aaa \< bbb)");
+#endif /* HUSH_2021_PARSER */
 	ut_assertok(run_command(if_formatted, 0));
 
 	sprintf(if_formatted, if_format, "test bbb < aaa");
+#if CONFIG_IS_ENABLED(HUSH_2021_PARSER)
+	ut_asserteq(1, run_command(if_formatted, 0));
+	ut_assert_skipline();
+	ut_assert_skipline();
+	ut_assert_console_end();
+
+	sprintf(if_formatted, if_format, R"(test bbb \< aaa)");
+#endif /* HUSH_2021_PARSER */
 	ut_asserteq(1, run_command(if_formatted, 0));
 
 	sprintf(if_formatted, if_format, "test bbb > aaa");
+#if CONFIG_IS_ENABLED(HUSH_2021_PARSER)
+	ut_asserteq(1, run_command(if_formatted, 0));
+	ut_assert_skipline();
+	ut_assert_skipline();
+	ut_assert_console_end();
+
+	sprintf(if_formatted, if_format, R"(test bbb \> aaa)");
+#endif /* HUSH_2021_PARSER */
 	ut_assertok(run_command(if_formatted, 0));
 
 	sprintf(if_formatted, if_format, "test aaa > bbb");
+#if CONFIG_IS_ENABLED(HUSH_2021_PARSER)
+	ut_asserteq(1, run_command(if_formatted, 0));
+	ut_assert_skipline();
+	ut_assert_skipline();
+	ut_assert_console_end();
+
+	sprintf(if_formatted, if_format, R"(test aaa \> bbb)");
+#endif /* HUSH_2021_PARSER */
 	ut_asserteq(1, run_command(if_formatted, 0));
 
 	sprintf(if_formatted, if_format, "test 123 -eq 123");
-- 
2.25.1



More information about the U-Boot mailing list