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

Fail coverage if any file contains an unmatched coveralls-ignore-start #197

Closed
tonyvanriet opened this issue Sep 30, 2019 · 5 comments · Fixed by #325
Closed

Fail coverage if any file contains an unmatched coveralls-ignore-start #197

tonyvanriet opened this issue Sep 30, 2019 · 5 comments · Fixed by #325

Comments

@tonyvanriet
Copy link

We get a lot of mileage out of #183 when we want to be more precise about the lines we're ignoring. Thanks @mruoss.

Nonetheless, we just noticed that if we don't properly terminate a # coveralls-ignore-start, excoveralls will proceed to ignore the remainder of the file, which could hide a coverage problem below the point where we intended to stop the ignore.

In our case, we had some cases where we erroneously used coveralls-ignore-end instead of stop, and it has taken us quite a while to notice the mistake.

I don't know if/when I'll be able to make time to try to PR this, but I wanted to at least come here first to see if there was anything missing from my understanding, or if there was already discussion along these lines.

Thanks

@RKushnir
Copy link
Contributor

I think it's a great observation. And I would be happy to make a PR if I first get a decision on #301, because it's changing the same code.

@mruoss
Copy link
Contributor

mruoss commented Feb 19, 2023

That's neat! I also like what credo does: # credo:disable-for-lines:<count>. Could be adapted as well.

@RKushnir
Copy link
Contributor

RKushnir commented Mar 6, 2023

@tonyvanriet What would be the desired behavior?

  1. I think we should print a warning message.
  2. Should the exit code be 0 (success) or 1 (failure)?
  3. Should the remainder of the file be ignored or not?

Additionally, I think we could print a warning in case there is an unrecognized comment with prefix coveralls- or coveralls-ignore-. That would catch a mistake like coveralls-ignore-end.

@tonyvanriet
Copy link
Author

Thanks for picking this up @RKushnir.

I think a failure exit code would make sense and a message to indicate "unmatched ignore tag". If the parser can't find a valid being and end to the ignore block, I don't think it should ignore anything for the rest of the file. I think it makes sense to err on the side being conservative for a coverage tool like this.

@RKushnir
Copy link
Contributor

RKushnir commented Mar 5, 2024

So it's been exactly a year since I showed up here 😅 But recently I actually started working on this and I think I'm about half-way done coding. Before I proceed, I'd like to get some authoritative approval/feedback first, to avoid wasting time.

My solution is going to noticeably complicate the Ignore module, so I want to know if we find it worthwhile. The general idea is to use Stream.transform to process the coverage lines. When we see a line with # ..ignore-start, we start buffering the following lines into a temporary list. If we then see an # .. ignore-stop (happy path), we "flush" the buffer to the output with ignored coverage, mimicking the current behavior. If we reach the end of the file (or we see a new # .. ignore-start) before there is a closing # .. ignore-stop, we flush the buffer without ignoring. In other words, a start without a stop is discarded, and there is a warning log message.

The invalid cases which I'm handling and showing warnings:

  1. ignore-start but no ignore-stop until the end of file
  2. ignore-start then again ignore-start without ignore-stop in-between.
  3. ignore-stop without a corresponding ignore-start before it
  4. redundant ignore-next-line inside of a start/stop block
  5. ignore-start that is in the next line after ignore-next-line
  6. double ignore-next-line
  7. ignore-next-line as the last line of code

The first 2 cases are important, the others are just an easy bonus and can be skipped if needed for simplicity.

Please, guide me @parroty . I can also create a separate issue to discuss the implementation or publish my half-baked PR already.

RKushnir added a commit to RKushnir/excoveralls that referenced this issue Mar 27, 2024
tonyrud added a commit to Vetspire/excoveralls that referenced this issue Sep 27, 2024
* Cobertura now handles defprotocol and defimpl definitions (parroty#306)

* Cobertura now handles defprotocol and defimpl definitions

* Cobertura, catch all if module type is unknown

* Bump version and update CHANGELOG

* Add Cobertura docs to README.md (parroty#312)

* Update Elixir requirement to 1.11+ (parroty#316)

* Update Elixir requirement to 1.11+

* Update deps

* Replace hackney with httpc (parroty#311)

* Replace hackney with httpc

* SSL options

* FIXUP

* Cache fixed

* Aaaah, caching again

* FIXUP

* Add missing apps to :extra_applications

* Add better check for :public_key

* Bump version and update CHANGELOG

* Fix lcov 2.0 source file handling (parroty#315)

Prior to 2.0 being released, `genhtml` was much better about handling
source files from the following paths:

* `test/support/some_helper.ex`
* `lib/foo/bar.ex`

But after 2.0 was released, when rendering with `genhtml` the paths
would be mangled and look like the following:

* `test/support/test/support/some_helper.ex`
* `lib/foo/lib/foo/bar.ex`

I have tried in vain with many permutations of `--prefix` when running
`genhtml` but the ultimate fix that made all of this go away was using
the absolute path for the source file (`SF`).

* Update CHANGELOG

* Remove erroneous line in ExCoveralls.poster (parroty#318)

* Import `.coverdata` after test run and improve documentation (parroty#309)

* Import `.coverdata` after test run and improve docs

* Update README table of contents

* Update README based on review suggestion

Co-authored-by: Alberto Sartori <[email protected]>

---------

Co-authored-by: Alberto Sartori <[email protected]>

* Update CHANGELOG

* Accept custom http options (parroty#319)

* Accept custom http options

* Add HTTP options docs to README

* Bump version and update CHANGELOG

* Always floor coverage instead of rounding (parroty#310)

* Always floor coverage instead of rounding

We do not want to report a 100% coverage when there are lines
that are not covered.

* Add option to restore previous ceil coverage behaviour

* Bump version and update CHANGELOG

* Update README examples (parroty#320)

* Use explicit steps to remove 1.16 deprecation warning (parroty#322)

* Update CHANGELOG and bump version

* Detect and warn about incorrectly used ignore-comments (parroty#325)

* Detect and warn about incorrectly used ignore-comments

Resolves parroty#197.

* Keep existing ignoring behavior

* Improve formatting

* Test more ignore-related warnings

* Remove warning in the case of ignore-next-line at the EOF

* Test the warning output

* Add a changelog entry

* Adjust test descriptions

---------

Co-authored-by: Roman <[email protected]>

* Fix Elixir 1.17 single-quoted string warning (parroty#327)

* Bump version and update CHANGELOG

* add missing step for Cobertura's range (parroty#329)

Without this change, the output is full of warnings such as
```
warning: negative steps are not supported in String.slice/2, pass 44..-1//1 instead
```

* Update CHANGELOG and version

* Revert "add missing step for Cobertura's range (parroty#329)" (parroty#330)

This reverts commit 00a96c4.

* Revert version change

* Update Range to use function syntax (parroty#332)

* add missing step for Cobertura's range

* Update Range to use function syntax

* run tests in elixir 1.17

* fix test with relative path

---------

Co-authored-by: parroty <[email protected]>

* Update CHANGELOG and version

---------

Co-authored-by: Rodrigue Villetard <[email protected]>
Co-authored-by: parroty <[email protected]>
Co-authored-by: Artem Solomatin <[email protected]>
Co-authored-by: Andrea Leopardi <[email protected]>
Co-authored-by: Matthew Johnston <[email protected]>
Co-authored-by: Zach Allaun <[email protected]>
Co-authored-by: Alberto Sartori <[email protected]>
Co-authored-by: Victor Rodrigues <[email protected]>
Co-authored-by: gitneko <[email protected]>
Co-authored-by: Roman <[email protected]>
Co-authored-by: Roman <[email protected]>
Co-authored-by: Hans Krutzer <[email protected]>
Co-authored-by: Juan Peri <[email protected]>
Co-authored-by: Kenta Nakase <[email protected]>
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.

3 participants