blob: 6964bfa9e1ece15b077260c9b78cafa38ac7a2d2 [file] [log] [blame]
Simon Glass4c0bf972023-10-01 19:13:06 -06001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Tests for history command
4 *
5 * Copyright 2023 Google LLC
6 * Written by Simon Glass <sjg@chromium.org>
7 */
8
Simon Glass4c0bf972023-10-01 19:13:06 -06009#include <cli.h>
10#include <command.h>
11#include <test/lib.h>
12#include <test/test.h>
13#include <test/ut.h>
14
15static int lib_test_history(struct unit_test_state *uts)
16{
17 static const char cmd1[] = "setenv fred hello";
18 static const char cmd2[] = "print fred";
19
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();
25
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);
31
32 console_in_puts(cmd2);
33 console_in_puts("\n");
34 ut_asserteq(strlen(cmd2), cli_readline(""));
35 ut_assert_nextline(cmd2);
36
37 ut_assertok(run_command("print fred", 0));
38 ut_assert_nextline("fred=hello");
39 ut_assert_console_end();
40
41 ut_assertok(run_command("history", 0));
42 ut_assert_nextline(cmd1);
43 ut_assert_nextline(cmd2);
44 ut_assert_console_end();
45
46 return 0;
47}
48LIB_TEST(lib_test_history, UT_TESTF_CONSOLE_REC);