mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fix incorrect loading of jacoco coverage data (end line number for a method is inclusive)
This commit is contained in:
@@ -90,12 +90,13 @@ public class JaCoCoCoverageRunner extends JavaCoverageRunner {
|
||||
className = className.replace('\\', '.').replace('/', '.');
|
||||
final ClassData classData = data.getOrCreateClassData(className);
|
||||
final Collection<IMethodCoverage> methods = classCoverage.getMethods();
|
||||
LineData[] lines = new LineData[classCoverage.getLastLine()];
|
||||
LineData[] lines = new LineData[classCoverage.getLastLine() + 1];
|
||||
for (IMethodCoverage method : methods) {
|
||||
final String desc = method.getName() + method.getDesc();
|
||||
// Line numbers are 1-based here.
|
||||
final int firstLine = method.getFirstLine();
|
||||
final int lastLine = method.getLastLine();
|
||||
for (int i = firstLine; i < lastLine; i++) {
|
||||
for (int i = firstLine; i <= lastLine; i++) {
|
||||
final ILine methodLine = method.getLine(i);
|
||||
final int methodLineStatus = methodLine.getStatus();
|
||||
final LineData lineData = new LineData(i , desc) {
|
||||
|
||||
Binary file not shown.
+20
-7
@@ -21,6 +21,8 @@ import com.intellij.openapi.project.ex.ProjectManagerEx;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiPackage;
|
||||
import com.intellij.rt.coverage.data.ClassData;
|
||||
import com.intellij.rt.coverage.data.LineCoverage;
|
||||
import com.intellij.testFramework.ModuleTestCase;
|
||||
import com.intellij.util.containers.hash.HashMap;
|
||||
|
||||
@@ -30,7 +32,7 @@ import java.util.Map;
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class PackageAnnotatorTest extends ModuleTestCase {
|
||||
public class CoverageIntegrationTest extends ModuleTestCase {
|
||||
private static String getTestDataPath() {
|
||||
return PluginPathManager.getPluginHomePath("coverage") + "/testData/simple";
|
||||
}
|
||||
@@ -44,12 +46,7 @@ public class PackageAnnotatorTest extends ModuleTestCase {
|
||||
}
|
||||
|
||||
public void testSimple() {
|
||||
File coverageFile = new File(getTestDataPath(), "simple$foo_in_simple.coverage");
|
||||
IDEACoverageRunner runner = CoverageRunner.getInstance(IDEACoverageRunner.class);
|
||||
CoverageFileProvider fileProvider = new DefaultCoverageFileProvider(coverageFile);
|
||||
CoverageSuite suite =
|
||||
JavaCoverageEngine.getInstance().createCoverageSuite(runner, "Simple", fileProvider, null, -1, null, false, false, false);
|
||||
CoverageSuitesBundle bundle = new CoverageSuitesBundle(suite);
|
||||
CoverageSuitesBundle bundle = loadCoverageSuite(IDEACoverageRunner.class, "simple$foo_in_simple.coverage");
|
||||
PsiPackage psiPackage = JavaPsiFacade.getInstance(myProject).findPackage("foo");
|
||||
PackageAnnotator annotator = new PackageAnnotator(psiPackage);
|
||||
PackageAnnotationConsumer consumer = new PackageAnnotationConsumer();
|
||||
@@ -58,6 +55,22 @@ public class PackageAnnotatorTest extends ModuleTestCase {
|
||||
assertNotNull(fooClassCoverage);
|
||||
}
|
||||
|
||||
public void testJaCoCo() {
|
||||
CoverageSuitesBundle bundle = loadCoverageSuite(JaCoCoCoverageRunner.class, "simple$foo_in_simple.jacoco.coverage");
|
||||
ClassData classData = bundle.getCoverageData().getClassData("foo.FooClass");
|
||||
// getStatus() never returns full coverage; it can only distinguish between none and partial
|
||||
assertEquals(LineCoverage.PARTIAL, classData.getStatus("method1()I").intValue());
|
||||
}
|
||||
|
||||
private CoverageSuitesBundle loadCoverageSuite(Class<? extends CoverageRunner> coverageRunnerClass, String coverageDataPath) {
|
||||
File coverageFile = new File(getTestDataPath(), coverageDataPath);
|
||||
CoverageRunner runner = CoverageRunner.getInstance(coverageRunnerClass);
|
||||
CoverageFileProvider fileProvider = new DefaultCoverageFileProvider(coverageFile);
|
||||
CoverageSuite suite =
|
||||
JavaCoverageEngine.getInstance().createCoverageSuite(runner, "Simple", fileProvider, null, -1, null, false, false, false, myProject);
|
||||
return new CoverageSuitesBundle(suite);
|
||||
}
|
||||
|
||||
private static class PackageAnnotationConsumer implements PackageAnnotator.Annotator {
|
||||
private final Map<VirtualFile, PackageAnnotator.PackageCoverageInfo> myDirectoryCoverage =
|
||||
new HashMap<VirtualFile, PackageAnnotator.PackageCoverageInfo>();
|
||||
Reference in New Issue
Block a user