osht icon indicating copy to clipboard operation
osht copied to clipboard

Allow variable expansion in RUNS

Open jaredallard opened this issue 6 years ago • 1 comments

Currently if I try to dynamically run tests the variables aren't expanded which makes debugging a bit of a nightmare. i.e

RUNS helm link "$chart"

... becomes

ok 14 -     RUNS helm lint "$chart" -f "../environments/${ENV}.yaml"

jaredallard avatar Mar 28 '18 06:03 jaredallard

I saw the code that prints this last week by sheer coincidence. It is printing the line in the file, using shell's "stack trace" primitive (call). That has the advantage of printing comments, and sometimes you don't want to see an expansion, because the variable name is part of the test's description.

I've wished from time to time that I could see variable expansion too. It can be done with verbose, but using it as a flag for the whole test suite is almost worse. At my last job, I actually made a change to OSHT so that it would do verbose output on failure, given a flag configuration. I intended to submit that back but, well, I'm no longer there. :)

Anyway, as a temporary fix, this helps:

OSHT_VERBOSE=1 RUNS helm link "$chart"

So, if a test fails, just prepend that individual test with verbose.

On a wider scale, I suggest you generate a temporary file with the tests, if you need more context. Even something as simple as this could do it:

cat > /tmp/test.sh <<<EOF
RUNS helm link "$chart"
EOF
source /tmp/test.sh

You could have a whole test suite cat'ed at once, as long as you pay attention to not include code that do variable assignments. For example, this wouldn't work:

cat > /tmp/test.sh <<<EOF
X=1
OK $X -eq 1
EOF
source /tmp/test.sh

but this would:

X=1
cat > /tmp/test.sh <<<EOF
OK $X -eq 1
EOF
source /tmp/test.sh

dcsobral avatar Jul 01 '19 17:07 dcsobral