diff mbox series

[v2,18/23] travis/gitlab/azure: Use bash to avoid a_test_which_does_not_exist

Message ID 20200315234303.18598-15-sjg@chromium.org
State Superseded
Headers show
Series gitlab: Simplify the test script | expand

Commit Message

Simon Glass March 15, 2020, 11:42 p.m. UTC
Bash allows for variables to expand only if non-empty:

	$ var=test
	$ echo ${var:+"$var"}
	test
	$ echo ${var:+"-k $var"}
	-k test
	$ var=
	$ echo ${var:+"-k $var"}

Use this feature to avoid the workaround.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

Changes in v2:
- Add a comment about the obscure bash feature
- Update travis, azure also

 .azure-pipelines.yml | 3 ++-
 .gitlab-ci.yml       | 7 ++-----
 .travis.yml          | 7 ++-----
 3 files changed, 6 insertions(+), 11 deletions(-)

Comments

Tom Rini March 16, 2020, 9:24 p.m. UTC | #1
On Sun, Mar 15, 2020 at 05:42:58PM -0600, Simon Glass wrote:

> Bash allows for variables to expand only if non-empty:
> 
> 	$ var=test
> 	$ echo ${var:+"$var"}
> 	test
> 	$ echo ${var:+"-k $var"}
> 	-k test
> 	$ var=
> 	$ echo ${var:+"-k $var"}
> 
> Use this feature to avoid the workaround.
> 
> Signed-off-by: Simon Glass <sjg at chromium.org>

Reviewed-by: Tom Rini <trini at konsulko.com>
diff mbox series

Patch

diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml
index b7222db97f..50d00fa899 100644
--- a/.azure-pipelines.yml
+++ b/.azure-pipelines.yml
@@ -257,7 +257,8 @@  jobs:
           pip install -r test/py/requirements.txt
           export PATH=/opt/qemu/bin:/tmp/uboot-test-hooks/bin:${PATH};
           export PYTHONPATH=/tmp/uboot-test-hooks/py/travis-ci;
-          ./test/py/test.py --bd ${TEST_PY_BD} ${TEST_PY_ID} -k "${TEST_PY_TEST_SPEC:-not a_test_which_does_not_exist}" --build-dir "$UBOOT_TRAVIS_BUILD_DIR";
+          # "${var:+"-k $var"}" expands to "" if $var is empty, "-k $var" if not
+          ./test/py/test.py --bd ${TEST_PY_BD} ${TEST_PY_ID} ${TEST_PY_TEST_SPEC:+"-k ${TEST_PY_TEST_SPEC}"} --build-dir "$UBOOT_TRAVIS_BUILD_DIR";
           ret=$?;
           if [[ $ret -ne 0 ]]; then
               exit $ret;
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 38f2cba69f..48b90b2ba3 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -38,17 +38,14 @@  stages:
            --board ${TEST_PY_BD};
         exit $ret;
       fi
-    # "not a_test_which_does_not_exist" is a dummy -k parameter which will
-    # never prevent any test from running. That way, we can always pass
-    # "-k something" even when $TEST_PY_TEST_SPEC doesnt need a custom
-    # value.
     - virtualenv -p /usr/bin/python3 /tmp/venv
     - . /tmp/venv/bin/activate
     - pip install -r test/py/requirements.txt
+    # "${var:+"-k $var"}" expands to "" if $var is empty, "-k $var" if not
     - export PATH=/opt/qemu/bin:/tmp/uboot-test-hooks/bin:${PATH};
       export PYTHONPATH=/tmp/uboot-test-hooks/py/travis-ci;
       ./test/py/test.py --bd ${TEST_PY_BD} ${TEST_PY_ID}
-        -k "${TEST_PY_TEST_SPEC:-not a_test_which_does_not_exist}"
+        ${TEST_PY_TEST_SPEC:+"-k ${TEST_PY_TEST_SPEC}"}
         --build-dir "$UBOOT_TRAVIS_BUILD_DIR";
       ret=$?;
       if [[ $ret -ne 0 ]]; then
diff --git a/.travis.yml b/.travis.yml
index d7c16326ff..887654ca96 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -127,11 +127,8 @@  script:
        exit $ret;
      fi;
    fi
- # "not a_test_which_does_not_exist" is a dummy -k parameter which will
- # never prevent any test from running. That way, we can always pass
- # "-k something" even when $TEST_PY_TEST_SPEC doesnt need a custom
- # value.
  # Build just the one board needed for testing, if TEST_PY_BD is non-empty
+ # Note: "${var:+"-k $var"}" expands to "" if $var is empty, "-k $var" if not
  - if [[ "${TEST_PY_BD}" != "" ]]; then
      export UBOOT_TRAVIS_BUILD_DIR=`cd .. && pwd`/${TEST_PY_BD};
      cp ~/grub_x86.efi $UBOOT_TRAVIS_BUILD_DIR/;
@@ -150,7 +147,7 @@  script:
      . /tmp/venv/bin/activate;
      pip install -r test/py/requirements.txt;
      ./test/py/test.py --bd ${TEST_PY_BD} ${TEST_PY_ID}
-       -k "${TEST_PY_TEST_SPEC:-not a_test_which_does_not_exist}"
+       ${TEST_PY_TEST_SPEC:+"-k ${TEST_PY_TEST_SPEC}"}
        --build-dir "$UBOOT_TRAVIS_BUILD_DIR";
      ret=$?;
      if [[ $ret -ne 0 ]]; then