]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11641 Add tests
authorJulien HENRY <julien.henry@sonarsource.com>
Tue, 5 Mar 2019 17:10:07 +0000 (18:10 +0100)
committerSonarTech <sonartech@sonarsource.com>
Fri, 8 Mar 2019 19:20:55 +0000 (20:20 +0100)
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/CoverageMediumTest.java

index c51d03d37858e4cf5b39daddbf1da2be9ec2f20a..4730fa8eadbf7fb288e318788ea2195a4fed154b 100644 (file)
@@ -282,6 +282,36 @@ public class CoverageMediumTest {
     assertThat(result.coverageFor(file, 4)).isNull();
   }
 
+  // SONAR-11641
+  @Test
+  public void dontFallbackOnExecutableLinesIfNoCoverageSaved() throws IOException {
+
+    File baseDir = temp.getRoot();
+    File srcDir = new File(baseDir, "src");
+    srcDir.mkdir();
+
+    File xooFile = new File(srcDir, "sample.xoo");
+    File measuresFile = new File(srcDir, "sample.xoo.measures");
+    File coverageFile = new File(srcDir, "sample.xoo.coverage");
+    FileUtils.write(xooFile, "function foo() {\n  if (a && b) {\nalert('hello');\n}\n}", StandardCharsets.UTF_8);
+    FileUtils.write(measuresFile, "# The code analyzer disagree with the coverage tool and consider some lines to be executable\nexecutable_lines_data:2=1;3=1;4=0", StandardCharsets.UTF_8);
+    FileUtils.write(coverageFile, "# No lines to cover in this file according to the coverage tool", StandardCharsets.UTF_8);
+
+    AnalysisResult result = tester.newAnalysis()
+      .properties(ImmutableMap.<String, String>builder()
+        .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
+        .put("sonar.projectKey", "com.foo.project")
+        .put("sonar.sources", "src")
+        .build())
+      .execute();
+
+    InputFile file = result.inputFile("src/sample.xoo");
+    assertThat(result.coverageFor(file, 1)).isNull();
+    assertThat(result.coverageFor(file, 2)).isNull();
+    assertThat(result.coverageFor(file, 3)).isNull();
+    assertThat(result.coverageFor(file, 4)).isNull();
+  }
+
   // SONAR-9557
   @Test
   public void exclusionsAndForceToZeroOnModules() throws IOException {