Message ID | 20200307030734.237401-9-sjg@chromium.org |
---|---|
State | New |
Headers | show |
Series | gitlab: Simplify the test script | expand |
On Fri, Mar 06, 2020 at 08:07:27PM -0700, 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> > --- > > .gitlab-ci.yml | 6 +----- > 1 file changed, 1 insertion(+), 5 deletions(-) > > diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml > index bbd05aa872..05f56c6d19 100644 > --- a/.gitlab-ci.yml > +++ b/.gitlab-ci.yml > @@ -36,17 +36,13 @@ stages: > if [[ $ret -ne 0 && $ret -ne 129 ]]; then > 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 > - 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 Please change the comment to note that other less-than-obvious bash feature being used here, thanks!
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bbd05aa872..05f56c6d19 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -36,17 +36,13 @@ stages: if [[ $ret -ne 0 && $ret -ne 129 ]]; then 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 - 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
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> --- .gitlab-ci.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)