osht
osht copied to clipboard
Allow variable expansion in RUNS
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"
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