Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Joe Hershberger | 26e038f | 2015-05-20 14:27:36 -0500 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2015 |
| 4 | * Joe Hershberger, National Instruments, joe.hershberger@ni.com |
Joe Hershberger | 26e038f | 2015-05-20 14:27:36 -0500 | [diff] [blame] | 5 | */ |
| 6 | |
Joe Hershberger | 26e038f | 2015-05-20 14:27:36 -0500 | [diff] [blame] | 7 | #include <command.h> |
| 8 | #include <test/env.h> |
| 9 | #include <test/suites.h> |
| 10 | #include <test/ut.h> |
| 11 | |
Ravi Minnikanti | cb803d7 | 2024-08-11 11:44:15 -0700 | [diff] [blame] | 12 | static int env_test_env_cmd(struct unit_test_state *uts) |
| 13 | { |
| 14 | ut_assertok(run_command("setenv non_default_var1 1", 0)); |
| 15 | ut_assert_console_end(); |
| 16 | |
| 17 | ut_assertok(run_command("setenv non_default_var2 1", 0)); |
| 18 | ut_assert_console_end(); |
| 19 | |
| 20 | ut_assertok(run_command("env print non_default_var1", 0)); |
| 21 | ut_assert_nextline("non_default_var1=1"); |
| 22 | ut_assert_console_end(); |
| 23 | |
| 24 | ut_assertok(run_command("env default non_default_var1 non_default_var2", 0)); |
| 25 | ut_assert_nextline("WARNING: 'non_default_var1' not in imported env, deleting it!"); |
| 26 | ut_assert_nextline("WARNING: 'non_default_var2' not in imported env, deleting it!"); |
| 27 | ut_assert_console_end(); |
| 28 | |
| 29 | ut_asserteq(1, run_command("env exists non_default_var1", 0)); |
| 30 | ut_assert_console_end(); |
| 31 | |
| 32 | ut_asserteq(1, run_command("env exists non_default_var2", 0)); |
| 33 | ut_assert_console_end(); |
| 34 | |
| 35 | return 0; |
| 36 | } |
Simon Glass | 11fcfa3 | 2024-08-22 07:57:50 -0600 | [diff] [blame] | 37 | ENV_TEST(env_test_env_cmd, UTF_CONSOLE); |
Ravi Minnikanti | cb803d7 | 2024-08-11 11:44:15 -0700 | [diff] [blame] | 38 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 39 | int do_ut_env(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Joe Hershberger | 26e038f | 2015-05-20 14:27:36 -0500 | [diff] [blame] | 40 | { |
Simon Glass | b50211f | 2021-03-07 17:35:10 -0700 | [diff] [blame] | 41 | struct unit_test *tests = UNIT_TEST_SUITE_START(env_test); |
| 42 | const int n_ents = UNIT_TEST_SUITE_COUNT(env_test); |
Joe Hershberger | 26e038f | 2015-05-20 14:27:36 -0500 | [diff] [blame] | 43 | |
Philippe Reynes | 1f99f84 | 2019-12-17 19:07:04 +0100 | [diff] [blame] | 44 | return cmd_ut_category("environment", "env_test_", |
| 45 | tests, n_ents, argc, argv); |
Joe Hershberger | 26e038f | 2015-05-20 14:27:36 -0500 | [diff] [blame] | 46 | } |