diff mbox series

[v2,7/7] test: env: add test for env info sub-command

Message ID 20200210170129.8405-6-patrick.delaunay@st.com
State Superseded
Headers show
Series cmd: env: add option for quiet output on env info | expand

Commit Message

Patrick Delaunay Feb. 10, 2020, 5:01 p.m. UTC
Add a pytest for testing the env info sub-command:

test_env_info: test command with several option

test_env_info_test: test the result of the sub-commandi with quiet option,
'-q' as used for support in shell test; for example:
  if env info -p -d -q; then env save; fi

Signed-off-by: Patrick Delaunay <patrick.delaunay at st.com>
---

Changes in v2:
- add pytest test_env_info and test_env_info_test (new)

 test/py/tests/test_env.py | 44 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

Comments

Stephen Warren Feb. 10, 2020, 8:25 p.m. UTC | #1
On 2/10/20 10:01 AM, Patrick Delaunay wrote:
> Add a pytest for testing the env info sub-command:
> 
> test_env_info: test command with several option
> 
> test_env_info_test: test the result of the sub-commandi with quiet option,

Nit: Remove "i" from the end of "sub-commandi".

> diff --git a/test/py/tests/test_env.py b/test/py/tests/test_env.py

> + at pytest.mark.boardspec('sandbox')

I assume that's just so things like "environment can't be persisted" can 
be guaranteed, since other boards will be different to sandbox here?

> + at pytest.mark.buildconfigspec('cmd_nvedit_info')
> + at pytest.mark.buildconfigspec('cmd_echo')
> +def test_env_info_test(state_test_env):
> +
> +    """Test 'env info' quiet command result with several options for test.
> +    """

Nit: It took me a while to realized what the "for test" and "_test" 
function name suffix meant. Perhaps _retcode might be a better function 
name suffix?

Acked-by: Stephen Warren <swarren at nvidia.com>
Patrick Delaunay Feb. 11, 2020, 9:20 a.m. UTC | #2
Hi Stephen

> From: Stephen Warren <swarren at wwwdotorg.org>
> Sent: lundi 10 février 2020 21:25
> 
> On 2/10/20 10:01 AM, Patrick Delaunay wrote:
> > Add a pytest for testing the env info sub-command:
> >
> > test_env_info: test command with several option
> >
> > test_env_info_test: test the result of the sub-commandi with quiet
> > option,
> 
> Nit: Remove "i" from the end of "sub-commandi".

yes
 
> > diff --git a/test/py/tests/test_env.py b/test/py/tests/test_env.py
> 
> > + at pytest.mark.boardspec('sandbox')
> 
> I assume that's just so things like "environment can't be persisted" can be
> guaranteed, since other boards will be different to sandbox here?

Yes.

And also  the test is based on command "env_loc" (select the env backend used) which is sandbox specific.
So this test will failed on real platform.

 
> > + at pytest.mark.buildconfigspec('cmd_nvedit_info')
> > + at pytest.mark.buildconfigspec('cmd_echo')
> > +def test_env_info_test(state_test_env):
> > +
> > +    """Test 'env info' quiet command result with several options for test.
> > +    """
> 
> Nit: It took me a while to realized what the "for test" and "_test"
> function name suffix meant. Perhaps _retcode might be a better function name
> suffix?

ok

 
> Acked-by: Stephen Warren <swarren at nvidia.com>
diff mbox series

Patch

diff --git a/test/py/tests/test_env.py b/test/py/tests/test_env.py
index 6ff38f1020..7b78ec4e40 100644
--- a/test/py/tests/test_env.py
+++ b/test/py/tests/test_env.py
@@ -336,3 +336,47 @@  def test_env_import_whitelist_delete(state_test_env):
     unset_var(state_test_env, 'foo2')
     unset_var(state_test_env, 'foo3')
     unset_var(state_test_env, 'foo4')
+
+ at pytest.mark.boardspec('sandbox')
+ at pytest.mark.buildconfigspec('cmd_nvedit_info')
+def test_env_info(state_test_env):
+
+    """Test 'env info' command with several options.
+    """
+    c = state_test_env.u_boot_console
+
+    response = c.run_command('env info')
+    assert 'env_valid = invalid' in response
+    assert 'env_ready = true' in response
+    assert 'env_use_default = true' in response
+
+    response = c.run_command('env info -p -d')
+    assert 'Default environment is used' in response
+    assert 'Environment cannot be persisted' in response
+
+    response = c.run_command('env info -p -d -q')
+    assert response == ""
+
+ at pytest.mark.boardspec('sandbox')
+ at pytest.mark.buildconfigspec('cmd_nvedit_info')
+ at pytest.mark.buildconfigspec('cmd_echo')
+def test_env_info_test(state_test_env):
+
+    """Test 'env info' quiet command result with several options for test.
+    """
+    c = state_test_env.u_boot_console
+
+    response = c.run_command('env info -d -q')
+    assert response == ""
+    response = c.run_command('echo $?')
+    assert response == "0"
+
+    response = c.run_command('env info -p -q')
+    assert response == ""
+    response = c.run_command('echo $?')
+    assert response == "1"
+
+    response = c.run_command('env info -d -p -q')
+    assert response == ""
+    response = c.run_command('echo $?')
+    assert response == "1"