I have the following .vimrc
:
let &makeprg="./run-tests"
The contents of run-tests
:
#!/bin/sh
error_file=$(mktemp)
coverage run --source "$PWD" --branch -m pytest tests/ >"$error_file" 2>&1
if test $?; then
coverage report --show-missing
else
cat "$error_file"
fi
If the tests pass, I want to only show the coverage information. If the tests fail, I only want to show the test information.
However, on both passing and failing tests, $?
is always 0, i.e. a success.
If I copy and paste the coverage run ...
command in the terminal and manually inspect echo $?
I do get 0 for success and 1 for failing tests.
It seems that the value of $?
is being altered by some other command that Vim is executing in the makeprg
pipeline.
How best to resolve this?
$?
within won't be influenced by whatever happens external to the script. Instead of runningcoverage run ...
directly/manually you should try running the script itself. Maybe save$?
in a variable immediately aftercoverage
(e.g.result=$?
) then, say,echo "Result is $result"
before doingif test $result; then ...
. Then at least you'll know for sure what it's value was in the script.if command …
. @BLayer is correct: vim cannot interfere with the execution of the script as you describe. Perhaps you misunderstood the test builtin? Does the script work outside of vim? I suspect this belongs somewhere more related to programming than here.