This unit test verifies negation in modern hush shell. To test on
sandbox, run the following commands with CONFIG_HUSH_MODERN_PARSER
enabled.

  => cli set modern
  => ut hush
  Test: negation: modern.c

Signed-off-by: Anshul Dalal <[email protected]>
---
 test/hush/Makefile |  3 +++
 test/hush/modern.c | 30 ++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/test/hush/Makefile b/test/hush/Makefile
index febdc82e8aae..b4ab03f510c0 100644
--- a/test/hush/Makefile
+++ b/test/hush/Makefile
@@ -9,3 +9,6 @@ obj-y += dollar.o
 endif
 obj-y += list.o
 obj-y += loop.o
+ifdef CONFIG_HUSH_MODERN_PARSER
+obj-y += modern.o
+endif
diff --git a/test/hush/modern.c b/test/hush/modern.c
new file mode 100644
index 000000000000..6f5da9e457b4
--- /dev/null
+++ b/test/hush/modern.c
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2026 Texas Instruments Incorporated - https://www.ti.com/
+ *     Anshul Dalal <[email protected]>
+ *
+ */
+
+ #include <command.h>
+ #include <test/ut.h>
+ #include <test/hush.h>
+
+#include <asm/global_data.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static int hush_test_negation(struct unit_test_state *uts)
+{
+       if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
+               ut_fail(uts, __FILE__, __LINE__, __func__,
+                       "Negation '!' is only available in modern parser");
+               return CMD_RET_FAILURE;
+       }
+
+       ut_asserteq(0, run_command("! false", 0));
+       ut_asserteq(1, run_command("! true", 0));
+
+       return 0;
+}
+
+HUSH_TEST(hush_test_negation, 0);

-- 
2.55.0

Reply via email to