Search in sources :

Example 86 with DefaultInputFile

use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.

the class ProjectCoverageExclusionsTest method shouldNotExcludeFileDuplicationBasedOnPattern.

@Test
public void shouldNotExcludeFileDuplicationBasedOnPattern() {
    DefaultInputFile file = TestInputFileBuilder.create("foo", new File(baseDir, "moduleA"), new File(baseDir, "moduleA/src/org/polop/File.php")).setProjectBaseDir(baseDir.toPath()).build();
    underTest = new ProjectCoverageAndDuplicationExclusions(mockConfig("", "moduleA/src/org/other/*"));
    assertThat(underTest.isExcludedForCoverage(file)).isFalse();
    assertThat(underTest.isExcludedForDuplication(file)).isFalse();
}
Also used : DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) ProjectCoverageAndDuplicationExclusions(org.sonar.scanner.scan.filesystem.ProjectCoverageAndDuplicationExclusions) Test(org.junit.Test)

Example 87 with DefaultInputFile

use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.

the class ProjectCoverageExclusionsTest method shouldNotExcludeFileCoverageBasedOnPattern.

@Test
public void shouldNotExcludeFileCoverageBasedOnPattern() {
    DefaultInputFile file = TestInputFileBuilder.create("foo", new File(baseDir, "moduleA"), new File(baseDir, "moduleA/src/org/polop/File.php")).setProjectBaseDir(baseDir.toPath()).build();
    underTest = new ProjectCoverageAndDuplicationExclusions(mockConfig("moduleA/src/org/other/*", ""));
    assertThat(underTest.isExcludedForCoverage(file)).isFalse();
    assertThat(underTest.isExcludedForDuplication(file)).isFalse();
}
Also used : DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) ProjectCoverageAndDuplicationExclusions(org.sonar.scanner.scan.filesystem.ProjectCoverageAndDuplicationExclusions) Test(org.junit.Test)

Example 88 with DefaultInputFile

use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.

the class ProjectCoverageExclusionsTest method shouldExcludeFileCoverageBasedOnPattern.

@Test
public void shouldExcludeFileCoverageBasedOnPattern() {
    DefaultInputFile file = TestInputFileBuilder.create("foo", new File(baseDir, "moduleA"), new File(baseDir, "moduleA/src/org/polop/File.php")).setProjectBaseDir(baseDir.toPath()).build();
    underTest = new ProjectCoverageAndDuplicationExclusions(mockConfig("moduleA/src/org/polop/*", ""));
    assertThat(underTest.isExcludedForCoverage(file)).isTrue();
    assertThat(underTest.isExcludedForDuplication(file)).isFalse();
}
Also used : DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) ProjectCoverageAndDuplicationExclusions(org.sonar.scanner.scan.filesystem.ProjectCoverageAndDuplicationExclusions) Test(org.junit.Test)

Example 89 with DefaultInputFile

use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.

the class BranchMediumTest method shouldNotSkipSensorForUnchangedFilesOnBranch.

@Test
public void shouldNotSkipSensorForUnchangedFilesOnBranch() throws Exception {
    AnalysisResult result = getResult(tester.setBranchName("myBranch").setBranchTarget("master").setBranchType(BranchType.BRANCH));
    final DefaultInputFile file = (DefaultInputFile) result.inputFile(FILE_PATH);
    List<ScannerReport.Issue> issues = result.issuesFor(file);
    assertThat(issues).isNotEmpty();
    assertThat(logTester.logs()).doesNotContain(ONE_ISSUE_PER_LINE_IS_RESTRICTED_TO_CHANGED_FILES_ONLY);
}
Also used : DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) AnalysisResult(org.sonar.scanner.mediumtest.AnalysisResult) Test(org.junit.Test)

Example 90 with DefaultInputFile

use of org.sonar.api.batch.fs.internal.DefaultInputFile in project sonarqube by SonarSource.

the class BranchMediumTest method should_not_skip_report_for_unchanged_files_in_pr.

@Test
public void should_not_skip_report_for_unchanged_files_in_pr() {
    // sanity check, normally report gets generated
    AnalysisResult result = getResult(tester);
    final DefaultInputFile file = (DefaultInputFile) result.inputFile(FILE_PATH);
    assertThat(getResult(tester).getReportComponent(file)).isNotNull();
    int fileId = file.scannerId();
    assertThat(result.getReportReader().readChangesets(fileId)).isNotNull();
    assertThat(result.getReportReader().hasCoverage(fileId)).isTrue();
    assertThat(result.getReportReader().readFileSource(fileId)).isNotNull();
    // file is not skipped for pull requests (need coverage, duplications coming soon)
    AnalysisResult result2 = getResult(tester.setBranchType(BranchType.PULL_REQUEST));
    final DefaultInputFile fileInPr = (DefaultInputFile) result2.inputFile(FILE_PATH);
    assertThat(result2.getReportComponent(fileInPr)).isNotNull();
    fileId = fileInPr.scannerId();
    assertThat(result2.getReportReader().readChangesets(fileId)).isNull();
    assertThat(result2.getReportReader().hasCoverage(fileId)).isTrue();
    assertThat(result2.getReportReader().readFileSource(fileId)).isNull();
}
Also used : DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) AnalysisResult(org.sonar.scanner.mediumtest.AnalysisResult) Test(org.junit.Test)

Aggregations

DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)173 Test (org.junit.Test)117 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)75 File (java.io.File)63 InputFile (org.sonar.api.batch.fs.InputFile)46 Path (java.nio.file.Path)25 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)18 SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)17 BlameOutput (org.sonar.api.batch.scm.BlameCommand.BlameOutput)16 FileMetadata (org.sonar.api.batch.fs.internal.FileMetadata)14 IOException (java.io.IOException)13 DefaultIndexedFile (org.sonar.api.batch.fs.internal.DefaultIndexedFile)11 Metadata (org.sonar.api.batch.fs.internal.Metadata)11 Before (org.junit.Before)10 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)10 BlameLine (org.sonar.api.batch.scm.BlameLine)9 List (java.util.List)8 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)8 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)7 TextRange (org.sonar.api.batch.fs.TextRange)7