bashcov icon indicating copy to clipboard operation
bashcov copied to clipboard

Using PS4 in tested script breaks coverage results

Open LaurentMarchelli opened this issue 5 years ago • 0 comments

Hi,

My current script starts like this:

declare -x PS4='+ ${FUNCNAME[0]:+${FUNCNAME[0]}() }'
PS4+='${FUNCNAME[0]:-(${BASH_SOURCE[0]}:${BASH_LINENO[0]}) }'

So bashcov seems a bit confused ... By injecting the bashcov version variable in the tested environment this issue can be avoided.

if [[ -z "${__bashcov_version__}" ]]; then
  declare -x PS4='+ ${FUNCNAME[0]:+${FUNCNAME[0]}() }'
  PS4+='${FUNCNAME[0]:-(${BASH_SOURCE[0]}:${BASH_LINENO[0]}) }'
fi

I did it in my script before calling bashcov and it works, however maybe your code is a better place. ;-)

declare -x __bashcov_version__
__bashcov_version__="$(bashcov --version)"
bashcov -- "./tools/bash_unit" "${test_files_lst[@]}" || retval=${?}

Thank's for your amazing work. Best regards,

LaurentMarchelli avatar Feb 02 '20 00:02 LaurentMarchelli