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

Generated filename attribute is invalid when project root is machine root #13

Closed
Mange opened this issue Sep 18, 2020 · 3 comments · Fixed by #14
Closed

Generated filename attribute is invalid when project root is machine root #13

Mange opened this issue Sep 18, 2020 · 3 comments · Fixed by #14

Comments

@Mange
Copy link
Contributor

Mange commented Sep 18, 2020

Assuming SimpleCov.root is /, which could happen in some forms of container builds, then the generated filename attributes are cut off incorrectly.

Example:

Full path Expected result Actual result
/foo/bar.rb foo/bar.rb oo/bar.rb

This happens because the code that tries to strip away the project root assumes that it must be at least 1 character before the path separator, which is not true with a path like "/".

filename = file.filename

# Here is the problem; the +1 assumes that SimpleCov.root.length is just before
# the path separator, while for the case of "/" it is actually *on* the path
# separator.
path = filename[SimpleCov.root.length+1..-1]

class_.attributes['name'] = File.basename(filename, '.*')
class_.attributes['filename'] = path

The real reason I get this

I'm trying to set up code coverage reporting on GitLab, which does not support the <source> element and instead requires the filename to be the full path to the file from the repo root.

However, this repo contains several projects and so the actual project root is not at the repo root. This would not have been a problem, as I could just adjust the SimpleCov.root, but the tests run inside a container where the app is just one directory below the root (/myapp). So I have to set the root to / to get it to include the myapp/ part in the filename so Gitlab can resolve the file from <repo root>/myapp/foo/bar.rb.

You could say this is a perfect storm of edge cases, and I would agree.

@jessebs
Copy link
Contributor

jessebs commented Sep 18, 2020

Thanks for the ticket and PR. I'll review the PR the first chance I get in the next couple of days.

@jessebs
Copy link
Contributor

jessebs commented Sep 28, 2020

Resolved in 1.4.1 which has been released to rubygems.org

@Mange
Copy link
Contributor Author

Mange commented Sep 29, 2020

Thank you! ❤️

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