1 // SPDX-License-Identifier: GPL-2.0+
3 * Tests for history command
5 * Copyright 2023 Google LLC
12 #include <test/test.h>
15 static int lib_test_history(struct unit_test_state *uts)
17 static const char cmd1[] = "setenv fred hello";
18 static const char cmd2[] = "print fred";
20 /* running commands directly does not add to history */
21 ut_assertok(run_command(cmd1, 0));
22 ut_assert_console_end();
23 ut_assertok(run_command("history", 0));
24 ut_assert_console_end();
26 /* enter commands via the console */
27 console_in_puts(cmd1);
28 console_in_puts("\n");
29 ut_asserteq(strlen(cmd1), cli_readline(""));
30 ut_assert_nextline(cmd1);
32 console_in_puts(cmd2);
33 console_in_puts("\n");
34 ut_asserteq(strlen(cmd2), cli_readline(""));
35 ut_assert_nextline(cmd2);
37 ut_assertok(run_command("print fred", 0));
38 ut_assert_nextline("fred=hello");
39 ut_assert_console_end();
41 ut_assertok(run_command("history", 0));
42 ut_assert_nextline(cmd1);
43 ut_assert_nextline(cmd2);
44 ut_assert_console_end();
48 LIB_TEST(lib_test_history, UTF_CONSOLE_REC);