Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Included script with a relative path are not covered #327

Open
beatussum opened this issue Jul 24, 2024 · 2 comments · May be fixed by #330
Open

Included script with a relative path are not covered #327

beatussum opened this issue Jul 24, 2024 · 2 comments · May be fixed by #330

Comments

@beatussum
Copy link
Contributor

beatussum commented Jul 24, 2024

Description

If a specfile include (Include) a file foo with a relative path and the directory from where shellspec is called differs from the one specified by --execdir, foo is not covered with --kcov.

In details

Consider the following lines:

  (
    "$SHELLSPEC_KCOV_PATH" \
    $SHELLSPEC_KCOV_COMMON_OPTS \
    $SHELLSPEC_KCOV_OPTS \
    --bash-method=DEBUG \
    --bash-parser="$SHELLSPEC_SHELL" \
    --bash-parse-files-in-dir=. \
    --configure=command-name="shellspec $*" \
    "$SHELLSPEC_COVERAGEDIR" "$SHELLSPEC_KCOV_IN_FILE"
  ) 8>&1

kcov is executed inside "${PWD}" and relative paths are computed from ${PWD}; however, relative paths specified with Include are relative to "${SHELLSPEC_EXECDIR}".

In this way,

  1. when kcov get the filename from the different traps loaded from here, the second field ${BASH_SOURCE[0]:-} has a relative path computed from "${SHELLSPEC_EXECDIR}",
  2. kcov tries to get the associated absolute path (here),
  3. realpath() (called here) returns null and filename is the relative path as it was before,
  4. it fails here.

Solution?

I don't have a good overall view of the project and it's very likely that I'm talking nonsense. I apologize in advance if this is the case.

Hardcoded the right cd in the subshell for a small example was successful, therefore I think that a shellspec_execdir "${SHELLSPEC_EXECDIR}" should be called here or before this subshell.

beatussum added a commit to beatussum/shellspec that referenced this issue Aug 5, 2024
Before this commit, if a specfile includes (`Include`) a file foo with a
relative path and the directory from where `shellspec` is called differs from
the one specified by `--execdir`, foo is not covered with `--kcov`.

Closes: shellspec#327
See-also: shellspec#327
Signed-off-by: Mattéo Rossillol‑‑Laruelle <[email protected]>
@beatussum beatussum linked a pull request Aug 5, 2024 that will close this issue
@Y-Rookie
Copy link

Hello, how about the progress of this issue? I might be experiencing the same problem: the coverage report shows that the instrumented lines are not empty, but the executed lines are zero. I included the relative path of the test script aa through Include ../scripts/test.sh in the spec, and then called a function from script test.sh using when call. The spec file and the script test.sh being tested are not in the same directory.

@beatussum
Copy link
Contributor Author

You can see the referenced pull request and the @ko1nksm's answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants