[PATCH v2 2/2] test: env: deep resolve value testing

Artem Lapkin email2tema at gmail.com
Fri Nov 19 05:36:47 CET 2021


Add new tests for `setenv -r` options (setup env variable with additional
resolving vars inside value).

test.py -k test_env

Signed-off-by: Artem Lapkin <art at khadas.com>
---
 test/py/tests/test_env.py | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/test/py/tests/test_env.py b/test/py/tests/test_env.py
index 9bed2f48d7..a2f02f6f67 100644
--- a/test/py/tests/test_env.py
+++ b/test/py/tests/test_env.py
@@ -201,6 +201,30 @@ def test_env_unset_non_existent(state_test_env):
     unset_var(state_test_env, var)
     validate_empty(state_test_env, var)
 
+def test_env_resovle(state_test_env):
+    """Test deep resolve variable."""
+    c = state_test_env.u_boot_console
+    c.run_command("setenv a hello; setenv b world; setenv c '${a} ${b}'")
+    assert c.run_command('printenv a') == 'a=hello'
+    assert c.run_command('printenv b') == 'b=world'
+    assert c.run_command('printenv c') == 'c=${a} ${b}'
+    c.run_command("setenv d '${c}'")
+    assert c.run_command('printenv d') == 'd=${c}'
+    c.run_command("setenv -r e '${a} ${b} ${c}'")
+    assert c.run_command('printenv e') == 'e=hello world hello world'
+    c.run_command("setenv not_exist; setenv -r e '${not_exist}OK'")
+    assert c.run_command('printenv e') == 'e=OK'
+    c.run_command("setenv a 'A${b}'; setenv b 'B${a}'")
+    assert c.run_command('printenv a') == 'a=A${b}'
+    c.run_command("setenv e ''")
+    assert c.run_command('printenv e') == 'e='
+    c.run_command("setenv -r e '${b}'")
+    #assert c.run_command('printenv e') == 'e=BABABABABABABABABABABABABABABABAB${a}'
+    assert c.run_command('printenv e') != 'e='
+    c.run_command("setenv -r e")
+    with c.disable_check('error_notification'):
+        assert c.run_command('printenv e') == '## Error: "e" not defined'
+
 def test_env_set_non_existent(state_test_env):
     """Test set a non-existant variable."""
 
-- 
2.25.1



More information about the U-Boot mailing list