bashcov icon indicating copy to clipboard operation
bashcov copied to clipboard

expected integer for LINENO, got "\\${LINENO-}"

Open boskamp opened this issue 1 year ago • 4 comments

Description

Running bashcov as non-root with the following command line:

bashcov -- ./main/idmdoctor export -l admin -u http://idmui.vmware:50000 -d ~/tmp/export/

This results in the following error/stacktrace:

#<Thread:0x00005a56a42613a8 /var/lib/gems/3.0.0/gems/bashcov-3.1.3/lib/bashcov/runner.rb:63 run> terminated with exception (report_on_exception is true):
/var/lib/gems/3.0.0/gems/bashcov-3.1.3/lib/bashcov/xtrace.rb:126:in `parse_hit!': expected integer for LINENO, got "\\\\${LINENO-}" (Bashcov::XtraceError)
	from /var/lib/gems/3.0.0/gems/bashcov-3.1.3/lib/bashcov/xtrace.rb:96:in `block in read'
	from /var/lib/gems/3.0.0/gems/bashcov-3.1.3/lib/bashcov/xtrace.rb:93:in `loop'
	from /var/lib/gems/3.0.0/gems/bashcov-3.1.3/lib/bashcov/xtrace.rb:93:in `read'
	from /var/lib/gems/3.0.0/gems/bashcov-3.1.3/lib/bashcov/runner.rb:63:in `block (2 levels) in run'

The program under test continues to run and coverage reports are generated, but the resulting bashcov report content is evidently incorrect. From the program under test's MAIN function, coverage is only correct until after the first subfunction call (DO_LOAD_BOOTSTRAP). Everything following this function call is reported as uncovered, which is not plausible.

Here's a screenshot of the coverage report from MAIN: grafik

An interesting side note is that this bug seems to depend on the program under test. In exactly the same environment, when testing a different program, e.g.

bashcov -- ./main/smoke ~/tmp/export/

the exception does not occur and the coverage report looks absolutely plausible.

Environment

Ubuntu 22.04 ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux-gnu] bashcov 3.1.3 (via gem install bashcov) GNU bash, Version 5.1.16(1)-release (x86_64-pc-linux-gnu)

boskamp avatar Jan 12 '25 14:01 boskamp

Not sure if related but there is a similiar problem in kcov: https://github.com/SimonKagstrom/kcov/issues/478

jakub-bochenski avatar Jun 18 '25 13:06 jakub-bochenski

This is duplicate/related to #86 ?

jakub-bochenski avatar Jun 18 '25 13:06 jakub-bochenski

@boskamp Getting ${LINENO-} is normal behavior when the line is missed, however I don't understand why it's being escaped as \\${LINENO-} in your case. Can you share a bit more about what the DO_LOAD_BOOTSTRAP function does? Does it call the set command such as set -x or similar?

infertux avatar Jun 24 '25 02:06 infertux

@boskamp Getting ${LINENO-} is normal behavior when the line is missed, however I don't understand why it's being escaped as \\${LINENO-} in your case. Can you share a bit more about what the DO_LOAD_BOOTSTRAP function does? Does it call the set command such as set -x or similar?

DO_LOAD_BOOTSTRAP sources a bunch of other script files containing function and global variable definitions, but it doesn't contain any set command. Here's the full source code:

DO_LOAD_BOOTSTRAP() {
    local BOOTSTRAP_DIR="$ME_DIR/bootstrap"
    for f in "$BOOTSTRAP_DIR"/*; do
        source "$f"
    done
}

boskamp avatar Jun 24 '25 08:06 boskamp