This repository has been archived by the owner on Jul 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #48 - Angular CLI-generated LCOV files fail to map to source Type…
- Loading branch information
1 parent
0daa50c
commit 7722e7a
Showing
10 changed files
with
191 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
src/test/java/com/pablissimo/sonar/LCOVParserImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
package com.pablissimo.sonar; | ||
|
||
import static org.junit.Assert.*; | ||
import java.io.File; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.util.Map; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.sonar.api.batch.fs.InputFile; | ||
import org.sonar.api.batch.fs.internal.DefaultInputFile; | ||
import org.sonar.api.batch.sensor.coverage.NewCoverage; | ||
import org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage; | ||
import org.sonar.api.batch.sensor.internal.SensorContextTester; | ||
|
||
public class LCOVParserImplTest { | ||
LOCSensor sensor; | ||
|
||
SensorContextTester sensorContext; | ||
DefaultInputFile inputFile; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
this.sensorContext = SensorContextTester.create(new File("")); | ||
|
||
this.inputFile = | ||
new DefaultInputFile("", "path/to/file.ts") | ||
.setLanguage(TypeScriptLanguage.LANGUAGE_KEY) | ||
.setLines(3); | ||
|
||
this.sensorContext.fileSystem().add(this.inputFile); | ||
} | ||
|
||
@Test | ||
public void parsesBasicLcovFiles() { | ||
Map<InputFile, NewCoverage> coverage = executeForTestCase("basic"); | ||
DefaultCoverage c = (DefaultCoverage) coverage.get(this.inputFile); | ||
|
||
assertEquals((Integer) 3, c.hitsByLine().get(1)); | ||
assertEquals((Integer) 0, c.hitsByLine().get(2)); | ||
assertEquals((Integer) 1, c.hitsByLine().get(3)); | ||
|
||
assertEquals(3, c.linesToCover()); | ||
} | ||
|
||
@Test | ||
public void parsesAngularTemplateLoaderOutput() { | ||
Map<InputFile, NewCoverage> coverage = executeForTestCase("angular"); | ||
DefaultCoverage c = (DefaultCoverage) coverage.get(this.inputFile); | ||
|
||
assertEquals((Integer) 3, c.hitsByLine().get(1)); | ||
assertEquals((Integer) 0, c.hitsByLine().get(2)); | ||
assertEquals((Integer) 1, c.hitsByLine().get(3)); | ||
|
||
assertEquals(3, c.linesToCover()); | ||
} | ||
|
||
@Test | ||
public void handlesNoContent() { | ||
Map<InputFile, NewCoverage> coverage = executeForTestCase("blank"); | ||
|
||
assertNotNull(coverage); | ||
assertEquals(0, coverage.size()); | ||
} | ||
|
||
@Test | ||
public void handlesNoLineHitsForASingleFile() { | ||
Map<InputFile, NewCoverage> coverage = executeForTestCase("nolinehits"); | ||
DefaultCoverage c = (DefaultCoverage) coverage.get(this.inputFile); | ||
|
||
assertEquals(1, coverage.size()); | ||
|
||
assertNotNull(c); | ||
assertNull(c.hitsByLine().get(1)); | ||
assertNull(c.hitsByLine().get(2)); | ||
assertNull(c.hitsByLine().get(3)); | ||
} | ||
|
||
@Test | ||
public void ignoresFilesNotPartOfAnalysisSet() { | ||
Map<InputFile, NewCoverage> coverage = executeForTestCase("existingandnot"); | ||
DefaultCoverage c = (DefaultCoverage) coverage.get(this.inputFile); | ||
|
||
assertNotNull(c); | ||
assertEquals(1, coverage.size()); | ||
} | ||
|
||
@Test | ||
public void handlesFilesEndingWithExclamationMarkIfNotPartOfSet() { | ||
Map<InputFile, NewCoverage> coverage = executeForTestCase("angularendswithbang"); | ||
|
||
assertNotNull(coverage); | ||
assertEquals(0, coverage.size()); | ||
} | ||
|
||
@Test | ||
public void handlesOutOfRangeLineNumbers() { | ||
Map<InputFile, NewCoverage> coverage = executeForTestCase("outofrangelines"); | ||
DefaultCoverage c = (DefaultCoverage) coverage.get(this.inputFile); | ||
|
||
assertNotNull(c); | ||
assertEquals(1, coverage.size()); | ||
|
||
assertEquals((Integer) 3, c.hitsByLine().get(1)); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void createThrowsWhenFileDoesNotExist() { | ||
File nonExistent = new File("whatever"); | ||
LCOVParserImpl.create(this.sensorContext, nonExistent); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void parseFileThrowsWhenFileDoesNotExist() { | ||
File nonExistent = new File("whatever"); | ||
LCOVParser parser = getParser(resource("basic")); | ||
|
||
parser.parseFile(nonExistent); | ||
} | ||
|
||
private Map<InputFile, NewCoverage> executeForTestCase(String testName) { | ||
File lcovFile = resource(testName); | ||
LCOVParser parser = getParser(lcovFile); | ||
|
||
return parser.parseFile(lcovFile); | ||
} | ||
|
||
private LCOVParser getParser(File lcovFile) { | ||
return LCOVParserImpl.create(this.sensorContext, lcovFile); | ||
} | ||
|
||
private File resource(String testName) { | ||
URL lcovUrl = LCOVParserImplTest.class.getClassLoader().getResource("./lcov/" + testName + ".lcov"); | ||
|
||
try { | ||
File lcovFile = new File(lcovUrl.toURI()); | ||
return lcovFile; | ||
} | ||
catch (URISyntaxException e) { | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
SF:path/to/template/loader.js!path/to/file.ts | ||
DA:1,3 | ||
DA:2,0 | ||
DA:3,1 | ||
end_of_record |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
SF:path/to/template/loader.js! | ||
DA:1,3 | ||
end_of_record |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
SF:path/to/file.ts | ||
DA:1,3 | ||
DA:2,0 | ||
DA:3,1 | ||
end_of_record |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
SF:path/to/file.ts | ||
DA:1,3 | ||
DA:2,0 | ||
DA:3,1 | ||
end_of_record | ||
SF:path/to/nonexistent/file.ts | ||
DA:1,1 | ||
end_of_record |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SF:path/to/file.ts | ||
end_of_record |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
SF:path/to/file.ts | ||
DA:0,3 | ||
DA:1,3 | ||
DA:4,3 | ||
end_of_record |