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
Add filter for assert statement #613
Conversation
On second thought, rather than removing all |
@bjkail First of all thanks a lot for your contribution and helping us with the filters! In the first round for the built-in filters we're focusing on synthetic compiler artifacts which have no direct correspondence to the source code. For Java assertions I would see the following artifacts as synthetic:
The assertion code itself is present in source code and should therefore be treated like regular code to be executed and tested. From my point of view also for both cases (pass and fail). |
Ok, I'll see if I can rework along those lines, thanks. It's a little unfortunate to leave the failed assertion code in place, since |
@bjkail I agree. In general Java assertions are questionable and probably not widely used in practice. As far as I remember we received only a single question about it. In our filter candidates there is a section "Test Execution is Questionable or Impossible by Design". |
@marchof I guess you can consider this to be a second question about them :). I see that we implemented "Private empty constructors", so would it be ok for this PR to also ignore the 'throw new AssertionError' + "message" portion of |
f6e483c
to
2c80983
Compare
Rebased to master, and updated to only filter compiler-generated code not present in the source code (initialization and load+jump for |
org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/AssertFilter.java
Outdated
Show resolved
Hide resolved
@bjkail Regarding ignore AssertionError path: As I personally don't like the usage of Java assertions at all I'm ok with ignoring the throws AssertionError(...) path. So we will only see whether the assertion was executed (only the case if run with -ea) and there will be no branches visible. |
@marchof Thanks for the feedback. I found it's non-trivial to accurately find the boundary between the |
@bjkail ok! Let's do baby steps. This his how we try to come to a first 0.8.0 release. |
@Godin Did my latest commit address your concerns? |
Would be helpful if this got merged - we are probably one of the few teams actually liking asserts, and we sprinkle them through our code where preconditions should be met. Our coverage numbers are now artificially low because of that, and it's harder to keep a baseline. |
@MarkSinke Have you actually tested this PR with your code base? Does it provide the expected results for you? |
Sorry no - I'm not sure how I would test a change that is not released yet?
Mark.
On Mon, Sep 24, 2018 at 3:59 PM Marc R. Hoffmann ***@***.***> wrote:
@MarkSinke <https://github.com/MarkSinke> Have you actually tested this
PR with your code base? Does it provide the expected results for you?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#613 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AFi1D0n4l8ojsZ3Y72xj-RwYYDPU9XJZks5ueOVQgaJpZM4P5odh>
.
--
*Mark Sinke*
CTO
+31 646 255 635 +31 30 699 1930
mark.sinke@forcare.com
www.forcare.com
|
@MarkSinke I just rebased this PR on master. In case you want to it with Ant or the CLI you can download a build of this PR here: https://ci.appveyor.com/project/JaCoCo/jacoco/build/1.0.2195/artifacts |
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bjkail I started working on getting this done - wanted to mention your contribution in our changelog and realized that you didn't wrote name in headers. So wondering if this was on purpose or just was forgotten? is there any IP/legal issues?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't recall, I probably copied from somewhere, cleared it out, and then just didn't bother to fill in my name :-). There are no IP/legal issues.
@Godin What's the state of this? Any chance of getting this merged and released soon? (My use-case being ignoring Lombok generated null check assertions that are possible since 1.18.8) |
@Godin any update on this? Is this going to be merged and released soon? |
I would appreciate to see this in the next jacoco release. |
I’ve just stumbled on this and would also like to see something fixing it merged. I managed to test 3 out of 4 branches (by specifically writing tests that trigger the assertions) and am fine with requiring that at first, but the fourth is virtually impossible (unload the class, then reload it with assertions disabled, with a custom classloader, ugh… no, thanks). So, could we please exclude the “untestable” branch (Edit: and the static initialiser, see #1063) first, get that into a release I can use with Maven, and perhaps consider ignoring assertions later/elsewhere? Thanks in advance! |
What’s holding this up? |
This pr getting merged will be much appreciated. |
#1196 was merged instead |
This bug is unfortunately still open with jacoco-maven-plugin 0.8.8 (I still get the partial coverage at the beginning of a class using assert and on the assert lines). |
• jacoco/jacoco#1063 (which jacoco/jacoco#613 and/or jacoco/jacoco#1196 were supposed to fix) is still open, so the code coverage is still off • projectlombok/lombok.patcher#10 latest lombok source not published • maven-release-plugin 3.0.0 still not available, need to bump the date manually or force oneself to not care about reproducible builds • antrun plugin, which we don’t use, uses insecure versions of ant by default; unsure if continuously bumping it will be worth the hassle? does anyone use any even? • maven-release-plugin 2.5.3 also uses insecure jdom (3.x doesn’t but is still in early beta)
@mirabilos What exactly is "still open" for you? Note that in #1196 we added a filter to hide the internal initialization code for asserts. But still each assert gives two branches: Good case and failure -- which is how assert works. |
Marc R. Hoffmann dixit:
***@***.*** What exactly is "still open" for you? Note that in #1196 we
***@***.*** a filter to hide the internal initialization code for asserts.
***@***.*** still each assert gives two branches: Good case and failure --
***@***.*** is how assert works.
I still get the partial branch coverage at the beginning of the class
and partial branch coverage for the asserts. At least Sonar says so…
Asserts *cannot* have two (or more) cases for the domain of coverage
because they’re literally a statement that the other condition cannot
happen at that point in control/data flow.
bye,
//mirabilos
--
I believe no one can invent an algorithm. One just happens to hit upon it
when God enlightens him. Or only God invents algorithms, we merely copy them.
If you don't believe in God, just consider God as Nature if you won't deny
existence. -- Coywolf Qi Hunt
|
@mirabilos This filter is implemented since our latest release 0.8.8. Here is the test case: Please open a new bug with an executable reproducer which demonstrates the problem - preferably a Git repository with simple Maven project. Thx! |
Testcase is still https://github.com/tarent/rfc822/ (git master this time). |
@mirabilos We cannot provide support for Sonarqube. If you think the problem is with JaCoCo please provide a executable build which includes a JaCoCo report goal and shows the problem. Otherwise please report the problem to Sponarqube. |
Add a filter for
assert
statements (JAVAC.ASSERT):$assertionsDisabled
static field in the<clinit>
method.assert
by looking for theGETSTATIC
+IFNE
of$assertionsDisabled
.