DiegoEliasCosta / spotjmhbugs

A SpotBugs plugin that detects bad practices on JMH microbenchmarks.
MIT License
11 stars 1 forks source link

Reduce the verbosity of unit tests #4

Open DiegoEliasCosta opened 5 years ago

DiegoEliasCosta commented 5 years ago

After migrating to SpotBugs 3.1.12 unit-tests now print the method byte-code. This should be configured to be printed only when running in DEBUG mode with build systems.

Example of

de.heidelberg.pvs.diego.jmh.JMHSample_08_DeadCode.<init> : ()V
  0 aload_0         []::[< Lde/heidelberg/pvs/diego/jmh/JMHSample_08_DeadCode;, IP, r0 >]
  1 invokespecial   [< Lde/heidelberg/pvs/diego/jmh/JMHSample_08_DeadCode;, IP, r0 >]::[< Lde/heidelberg/pvs/diego/jmh/JMHSample_08_DeadCode;, IP, r0 >]
  4 aload_0         []::[< Lde/heidelberg/pvs/diego/jmh/JMHSample_08_DeadCode;, IP, r0 >]
  5 ldc2_w          [< Lde/heidelberg/pvs/diego/jmh/JMHSample_08_DeadCode;, IP, r0 >]::[< Lde/heidelberg/pvs/diego/jmh/JMHSample_08_DeadCode;, IP, r0 >]
  8 putfield        [< Lde/heidelberg/pvs/diego/jmh/JMHSample_08_DeadCode;, IP, r0 >, < D, 3.141592653589793 >]::[< Lde/heidelberg/pvs/diego/jmh/JMHSample_08_DeadCode;, IP, r0 >]
 11 return          []::[< Lde/heidelberg/pvs/diego/jmh/JMHSample_08_DeadCode;, IP, r0 >]
isopov commented 5 years ago

This verbosity comes with bumping spotbugs version from 3.1.1 to 3.1.2

isopov commented 5 years ago

https://github.com/spotbugs/spotbugs/compare/3.1.1...spotbugs:3.1.2 - link to compare of these two versions (24 commits in 3.1.2)

isopov commented 5 years ago

I suspect the following commit - https://github.com/spotbugs/spotbugs/commit/88fb657b2055d062d09b3952310f58356304619e

DiegoEliasCosta commented 5 years ago

Yeah... that puzzles me a bit. The problem is that apparently SpotBugsRule is the only available entry-point for unit-tests in SpotBugs and there is no way to customize the detectors that are running in the tests.

I found some detectors that have unguarded print statements that will be printed every time we run some unit tests.

The easiest solution would be to send a PR to SpotBugs guarding the print statements with a DEBUG variable, which is how most detectors are implemented. Another option would be to implement better control over the detectors that are running, but that can take quite some time.

I will send them a PR tomorrow.