use of org.sonar.go.plugin.GoCoverageReport.CoverageStat in project sonar-go by SonarSource.
the class GoCoverageReportTest method coverage_stat.
@Test
void coverage_stat() {
CoverageStat coverage = new CoverageStat(2, "_/my-app/my-app.go:3.10,4.5 2 234");
assertThat(coverage.filePath).isEqualTo("_/my-app/my-app.go");
assertThat(coverage.startLine).isEqualTo(3);
assertThat(coverage.startCol).isEqualTo(10);
assertThat(coverage.endLine).isEqualTo(4);
assertThat(coverage.endCol).isEqualTo(5);
assertThat(coverage.numStmt).isEqualTo(2);
assertThat(coverage.count).isEqualTo(234);
assertThat(assertThrows(IllegalArgumentException.class, () -> new CoverageStat(42, "invalid")).getMessage()).isEqualTo("Invalid go coverage at line 42");
}
use of org.sonar.go.plugin.GoCoverageReport.CoverageStat in project sonar-go by SonarSource.
the class GoCoverageReportTest method line_coverage.
@Test
void line_coverage() {
LineCoverage line = new LineCoverage();
assertThat(line.hits).isEqualTo(0);
line.add(new CoverageStat(2, "main.go:2.2,2.5 1 0"));
assertThat(line.hits).isEqualTo(0);
line.add(new CoverageStat(2, "main.go:2.2,2.5 1 3"));
assertThat(line.hits).isEqualTo(3);
line.add(new CoverageStat(2, "main.go:2.2,2.5 1 2"));
assertThat(line.hits).isEqualTo(5);
line.add(new CoverageStat(2, "main.go:2.8,2.10 1 0"));
assertThat(line.hits).isEqualTo(5);
}
use of org.sonar.go.plugin.GoCoverageReport.CoverageStat in project sonar-go by SonarSource.
the class GoCoverageReportTest method coverage.
@Test
void coverage() {
GoContext linuxContext = new GoContext('/', "/home/paul/go");
Coverage coverage = new Coverage(linuxContext);
coverage.add(new CoverageStat(2, "main.go:2.2,2.5 1 1"));
coverage.add(new CoverageStat(3, "main.go:4.2,4.7 1 0"));
coverage.add(new CoverageStat(4, "other.go:3.2,4.12 1 1"));
assertThat(coverage.fileMap.keySet()).containsExactlyInAnyOrder("/home/paul/go/main.go", "/home/paul/go/other.go");
assertThat(coverage.fileMap.get("/home/paul/go/main.go").lineMap.keySet()).containsExactlyInAnyOrder(2, 4);
assertThat(coverage.fileMap.get("/home/paul/go/other.go").lineMap.keySet()).containsExactlyInAnyOrder(3, 4);
}
use of org.sonar.go.plugin.GoCoverageReport.CoverageStat in project sonar-go by SonarSource.
the class GoCoverageReportTest method coverage_stat_resolve_path.
@Test
void coverage_stat_resolve_path() {
CoverageStat coverage;
GoContext linuxContext = new GoContext('/', "/home/paul/go");
GoContext windowsContext = new GoContext('\\', "C:\\Users\\paul\\go");
coverage = new CoverageStat(2, "_/my-app/my-app.go:2.2,2.5 1 0");
assertThat(coverage.resolvePath(linuxContext)).isEqualTo("/my-app/my-app.go");
coverage = new CoverageStat(2, "my-app/my-app.go:2.2,2.5 1 0");
assertThat(coverage.resolvePath(linuxContext)).isEqualTo("/home/paul/go/my-app/my-app.go");
coverage = new CoverageStat(2, "_\\C_\\my-app\\my-app.go:2.2,2.5 1 0");
assertThat(coverage.resolvePath(windowsContext)).isEqualTo("C:\\my-app\\my-app.go");
coverage = new CoverageStat(2, "my-app\\my-app.go:2.2,2.5 1 0");
assertThat(coverage.resolvePath(windowsContext)).isEqualTo("C:\\Users\\paul\\go\\my-app\\my-app.go");
linuxContext = new GoContext('/', null);
coverage = new CoverageStat(2, "my-app/my-app.go:2.2,2.5 1 0");
assertThat(coverage.resolvePath(linuxContext)).isEqualTo("my-app/my-app.go");
}
use of org.sonar.go.plugin.GoCoverageReport.CoverageStat in project sonar-go by SonarSource.
the class GoCoverageReportTest method file_coverage.
@Test
void file_coverage() {
FileCoverage file = new FileCoverage(COVERAGE_DIR.resolve("cover.go").toString());
assertThat(file.lineMap.size()).isEqualTo(0);
file.add(new CoverageStat(2, "cover.go:4.11,6.3 1 3"));
file.add(new CoverageStat(3, "cover.go:6.3,8.3 1 0"));
assertThat(file.lineMap.keySet()).containsExactlyInAnyOrder(5, 6, 7);
assertThat(file.lineMap.get(4)).isNull();
assertThat(file.lineMap.get(5).hits).isEqualTo(3);
assertThat(file.lineMap.get(6).hits).isEqualTo(0);
assertThat(file.lineMap.get(7).hits).isEqualTo(0);
assertThat(file.lineMap.get(8)).isNull();
}
Aggregations