diff mbox series

[v1,1/2] test: run some test commands only if HUSH_PARSER is enabled

Message ID 20250416135744.1995084-2-jerome.forissier@linaro.org
State Accepted
Commit 83fc6005cdaf703ff26d635d72bcccf2081ad5d8
Headers show
Series Enable UNIT_TEST for all qemu* generic targets | expand

Commit Message

Jerome Forissier April 16, 2025, 1:57 p.m. UTC
Some test commands (such as "false", or the empty string) need
CONFIG_HUSH_PARSER=y. Fix test/cmd/command.c.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
---

 test/cmd/command.c | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)
diff mbox series

Patch

diff --git a/test/cmd/command.c b/test/cmd/command.c
index 5ec93d490ba..5b1e5a77e5d 100644
--- a/test/cmd/command.c
+++ b/test/cmd/command.c
@@ -45,31 +45,32 @@  static int command_test(struct unit_test_state *uts)
 		"setenv list ${list}3", strlen("setenv list 1"), 0);
 	ut_assert(!strcmp("1", env_get("list")));
 
-	ut_asserteq(1, run_command("false", 0));
 	ut_assertok(run_command("echo", 0));
-	ut_asserteq(1, run_command_list("false", -1, 0));
 	ut_assertok(run_command_list("echo", -1, 0));
 
-#ifdef CONFIG_HUSH_PARSER
-	run_command("setenv foo 'setenv black 1\nsetenv adder 2'", 0);
-	run_command("run foo", 0);
-	ut_assertnonnull(env_get("black"));
-	ut_asserteq(0, strcmp("1", env_get("black")));
-	ut_assertnonnull(env_get("adder"));
-	ut_asserteq(0, strcmp("2", env_get("adder")));
-#endif
-
-	ut_assertok(run_command("", 0));
-	ut_assertok(run_command(" ", 0));
+	if (IS_ENABLED(CONFIG_HUSH_PARSER)) {
+		ut_asserteq(1, run_command("false", 0));
+		ut_asserteq(1, run_command_list("false", -1, 0));
+		run_command("setenv foo 'setenv black 1\nsetenv adder 2'", 0);
+		run_command("run foo", 0);
+		ut_assertnonnull(env_get("black"));
+		ut_asserteq(0, strcmp("1", env_get("black")));
+		ut_assertnonnull(env_get("adder"));
+		ut_asserteq(0, strcmp("2", env_get("adder")));
+		ut_assertok(run_command("", 0));
+		ut_assertok(run_command(" ", 0));
+	}
 
 	ut_asserteq(1, run_command("'", 0));
 
 	/* Variadic function test-cases */
+	if (IS_ENABLED(CONFIG_HUSH_PARSER)) {
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wformat-zero-length"
-	ut_assertok(run_commandf(""));
+		ut_assertok(run_commandf(""));
 #pragma GCC diagnostic pop
-	ut_assertok(run_commandf(" "));
+		ut_assertok(run_commandf(" "));
+	}
 	ut_asserteq(1, run_commandf("'"));
 
 	ut_assertok(run_commandf("env %s %s", "delete -f", "list"));