Skip to content

slather shows no coverage if working directory has symbolic link #578

@middagj

Description

@middagj

We have a CI pipeline running via tart that by default checks out the repo at /var/tmp/builds/.... /var is in macOS just a symbolic link to /private/var. When the sources files are fetches via llvm-cov export it uses the exact path as used in the test run. In lib/slather/project.rb#L144 this is made absolute and undone of any symbolic links via realpath:

        coverage_json["data"].reduce([]) do |result, chunk|
          result.concat(chunk["files"].map do |file|
            filename = file["filename"]
            path = Pathname(filename)
            # Don't crash if the file doesn't exist on disk.
            # This may happen for autogenerated files that have been deleted.
            filename = path.exist? ? path.realpath : filename
            {"filename" => filename, "segments" => file["segments"]}
          end)
        end

However, llvm-cov show requires the path as returned in llvm-cov export to filter correctly. This fixes it:

diff --git a/lib/slather/project.rb b/lib/slather/project.rb
index 8266192..ebf0ac7 100755
--- a/lib/slather/project.rb
+++ b/lib/slather/project.rb
@@ -141,7 +141,7 @@ module Slather
             path = Pathname(filename)
             # Don't crash if the file doesn't exist on disk.
             # This may happen for autogenerated files that have been deleted.
-            filename = path.exist? ? path.realpath : filename
+            filename = path.exist? ? path : filename
             {"filename" => filename, "segments" => file["segments"]}
           end)
         end

but I am unsure about the implications in the rest of the library as realpath is used more. Perhaps this also explains #562.

Reproduce:

  • clone slather in /var/tmp and chdir into repo dir
  • run bundle install
  • run bundle exec rspec spec/slather/coverage_service/llvm_cov_spec.rb:32

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions