Search in sources :

Example 1 with FailureType

use of fr.inria.spirals.repairnator.process.testinformation.FailureType in project repairnator by Spirals-Team.

the class GatherTestInformation method businessExecute.

@Override
protected void businessExecute() {
    this.getLogger().debug("Gathering test information...");
    File rootRepo = new File(this.inspector.getJobStatus().getPomDirPath());
    final List<File> surefireDirs = new ArrayList<File>();
    try {
        Files.walkFileTree(rootRepo.toPath(), new SimpleFileVisitor<Path>() {

            public FileVisitResult preVisitDirectory(Path file, BasicFileAttributes attrs) throws IOException {
                if (file.toString().endsWith(SUREFIREREPORT_PATH)) {
                    surefireDirs.add(file.toFile());
                    return FileVisitResult.SKIP_SUBTREE;
                } else {
                    return FileVisitResult.CONTINUE;
                }
            }
        });
    } catch (IOException e) {
        this.getLogger().warn("Error while traversing files to get surefire reports: " + e);
        this.addStepError(e.getMessage());
    }
    for (File surefireDir : surefireDirs) {
        SurefireReportParser parser = new SurefireReportParser(Arrays.asList(new File[] { surefireDir }), Locale.ENGLISH, null);
        try {
            List<ReportTestSuite> testSuites = parser.parseXMLReportFiles();
            for (ReportTestSuite testSuite : testSuites) {
                if (!skipSettingStatusInformation) {
                    this.nbTotalTests += testSuite.getNumberOfTests();
                    this.nbSkippingTests += testSuite.getNumberOfSkipped();
                    if (testSuite.getNumberOfFailures() > 0 || testSuite.getNumberOfErrors() > 0) {
                        File failingModule = surefireDir.getParentFile().getParentFile();
                        this.failingModulePath = failingModule.getCanonicalPath();
                        this.getInspector().getJobStatus().setFailingModulePath(this.failingModulePath);
                        this.writeProperty("failingModule", this.failingModulePath);
                        getLogger().info("Get the following failing module path: " + failingModulePath);
                        for (ReportTestCase testCase : testSuite.getTestCases()) {
                            if (testCase.hasFailure() || testCase.hasError()) {
                                // sometimes surefire reports a failureType on the form:
                                // "java.lang.NullPointerException:" we should avoid this case
                                String failureType = testCase.getFailureType();
                                if (failureType.endsWith(":")) {
                                    failureType = failureType.substring(0, failureType.length() - 1);
                                }
                                this.failureNames.add(failureType);
                                FailureType typeTof = new FailureType(testCase.getFailureType(), testCase.getFailureMessage(), testCase.hasError());
                                FailureLocation failureLocation = null;
                                for (FailureLocation location : this.failureLocations) {
                                    if (location.getClassName().equals(testCase.getFullClassName())) {
                                        failureLocation = location;
                                        break;
                                    }
                                }
                                if (failureLocation == null) {
                                    failureLocation = new FailureLocation(testCase.getFullClassName());
                                    this.failureLocations.add(failureLocation);
                                }
                                failureLocation.addFailure(typeTof);
                                if (testCase.hasError()) {
                                    failureLocation.addErroringMethod(testCase.getFullClassName() + "#" + testCase.getName());
                                } else {
                                    failureLocation.addFailingMethod(testCase.getFullClassName() + "#" + testCase.getName());
                                }
                            }
                        }
                    }
                }
                this.nbErroringTests += testSuite.getNumberOfErrors();
                this.nbFailingTests += testSuite.getNumberOfFailures();
            }
            if (this.nbFailingTests > 0) {
                this.setPipelineState(PipelineState.HASTESTFAILURE);
            } else if (this.nbErroringTests > 0) {
                this.setPipelineState(PipelineState.HASTESTERRORS);
            } else {
                this.setPipelineState(PipelineState.NOTFAILING);
            }
        } catch (MavenReportException e) {
            this.addStepError("Error while parsing files to get test information:", e);
        } catch (IOException e) {
            this.addStepError("Error while getting the failing module path: ", e);
        }
    }
    if (!this.skipSettingStatusInformation) {
        this.writeProperty("error-types", this.failureNames);
        this.writeProperty("failing-test-cases", this.failureLocations);
        this.writeProperty("totalNumberFailingTests", this.nbFailingTests);
        this.writeProperty("totalNumberErroringTests", this.nbErroringTests);
        this.writeProperty("totalNumberSkippingTests", this.nbSkippingTests);
        this.writeProperty("totalNumberRunningTests", this.nbTotalTests);
        this.inspector.getJobStatus().setFailureLocations(this.failureLocations);
        Metrics metrics = this.inspector.getJobStatus().getMetrics();
        metrics.setFailureNames(this.failureNames);
        metrics.setNbFailingTests(this.nbErroringTests + this.nbFailingTests);
        metrics.setNbRunningTests(this.nbTotalTests);
    }
    this.shouldStop = contract.shouldBeStopped(this);
}
Also used : Path(java.nio.file.Path) ReportTestSuite(org.apache.maven.plugins.surefire.report.ReportTestSuite) SurefireReportParser(org.apache.maven.plugins.surefire.report.SurefireReportParser) FailureType(fr.inria.spirals.repairnator.process.testinformation.FailureType) FailureLocation(fr.inria.spirals.repairnator.process.testinformation.FailureLocation) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) Metrics(fr.inria.spirals.repairnator.process.inspectors.Metrics) ReportTestCase(org.apache.maven.plugins.surefire.report.ReportTestCase) File(java.io.File) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 2 with FailureType

use of fr.inria.spirals.repairnator.process.testinformation.FailureType in project repairnator by Spirals-Team.

the class TestGatherTestInformation method testGatherTestInformationOnlyOneErroring.

@Test
public void testGatherTestInformationOnlyOneErroring() throws IOException {
    // surli/failingProject build
    int buildId = 208897371;
    Build build = BuildHelper.getBuildFromId(buildId, null);
    assertThat(build, notNullValue());
    assertThat(buildId, is(build.getId()));
    Path tmpDirPath = Files.createTempDirectory("test_gathertest");
    File tmpDir = tmpDirPath.toFile();
    tmpDir.deleteOnExit();
    System.out.println("Dirpath : " + tmpDirPath);
    File repoDir = new File(tmpDir, "repo");
    BuildToBeInspected toBeInspected = new BuildToBeInspected(build, null, ScannedBuildStatus.ONLY_FAIL, "");
    ProjectInspector inspector = mock(ProjectInspector.class);
    when(inspector.getWorkspace()).thenReturn(tmpDir.getAbsolutePath());
    when(inspector.getRepoLocalPath()).thenReturn(tmpDir.getAbsolutePath() + "/repo");
    when(inspector.getBuildToBeInspected()).thenReturn(toBeInspected);
    when(inspector.getBuggyBuild()).thenReturn(build);
    when(inspector.getM2LocalPath()).thenReturn(tmpDir.getAbsolutePath() + "/.m2");
    when(inspector.getGitHelper()).thenReturn(new GitHelper());
    JobStatus jobStatus = new JobStatus(tmpDir.getAbsolutePath() + "/repo");
    when(inspector.getJobStatus()).thenReturn(jobStatus);
    CloneRepository cloneStep = new CloneRepository(inspector);
    GatherTestInformation gatherTestInformation = new GatherTestInformation(inspector, new BuildShouldFail(), false);
    cloneStep.setNextStep(new CheckoutBuggyBuild(inspector)).setNextStep(new TestProject(inspector)).setNextStep(gatherTestInformation);
    cloneStep.execute();
    assertThat(gatherTestInformation.shouldStop, is(false));
    assertThat(gatherTestInformation.getPipelineState(), is(PipelineState.HASTESTERRORS));
    assertThat(jobStatus.getPipelineState(), is(PipelineState.HASTESTERRORS));
    assertThat(jobStatus.getFailingModulePath(), is(repoDir.getCanonicalPath()));
    assertThat(gatherTestInformation.getNbTotalTests(), is(8));
    assertThat(gatherTestInformation.getNbFailingTests(), is(0));
    assertThat(gatherTestInformation.getNbErroringTests(), is(1));
    assertThat(gatherTestInformation.getNbSkippingTests(), is(0));
    Set<String> failureNames = jobStatus.getMetrics().getFailureNames();
    assertThat("failure names" + StringUtils.join(failureNames.toArray()), failureNames.contains("java.lang.StringIndexOutOfBoundsException"), is(true));
    assertThat(failureNames.size(), is(1));
    assertThat(jobStatus.getFailureLocations().size(), is(1));
    FailureLocation expectedFailureLocation = new FailureLocation("nopol_examples.nopol_example_1.NopolExampleTest");
    FailureType failureType = new FailureType("java.lang.StringIndexOutOfBoundsException", "String index out of range: -5", true);
    expectedFailureLocation.addFailure(failureType);
    expectedFailureLocation.addErroringMethod("nopol_examples.nopol_example_1.NopolExampleTest#test5");
    FailureLocation actualLocation = jobStatus.getFailureLocations().iterator().next();
    assertThat(actualLocation, is(expectedFailureLocation));
}
Also used : Path(java.nio.file.Path) CheckoutBuggyBuild(fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild) FailureType(fr.inria.spirals.repairnator.process.testinformation.FailureType) FailureLocation(fr.inria.spirals.repairnator.process.testinformation.FailureLocation) BuildShouldFail(fr.inria.spirals.repairnator.process.step.gatherinfo.BuildShouldFail) GitHelper(fr.inria.spirals.repairnator.process.git.GitHelper) ProjectInspector(fr.inria.spirals.repairnator.process.inspectors.ProjectInspector) BuildToBeInspected(fr.inria.spirals.repairnator.BuildToBeInspected) JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) GatherTestInformation(fr.inria.spirals.repairnator.process.step.gatherinfo.GatherTestInformation) Build(fr.inria.jtravis.entities.Build) CheckoutBuggyBuild(fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild) File(java.io.File) Test(org.junit.Test)

Aggregations

FailureLocation (fr.inria.spirals.repairnator.process.testinformation.FailureLocation)2 FailureType (fr.inria.spirals.repairnator.process.testinformation.FailureType)2 File (java.io.File)2 Path (java.nio.file.Path)2 Build (fr.inria.jtravis.entities.Build)1 BuildToBeInspected (fr.inria.spirals.repairnator.BuildToBeInspected)1 GitHelper (fr.inria.spirals.repairnator.process.git.GitHelper)1 JobStatus (fr.inria.spirals.repairnator.process.inspectors.JobStatus)1 Metrics (fr.inria.spirals.repairnator.process.inspectors.Metrics)1 ProjectInspector (fr.inria.spirals.repairnator.process.inspectors.ProjectInspector)1 CheckoutBuggyBuild (fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild)1 BuildShouldFail (fr.inria.spirals.repairnator.process.step.gatherinfo.BuildShouldFail)1 GatherTestInformation (fr.inria.spirals.repairnator.process.step.gatherinfo.GatherTestInformation)1 IOException (java.io.IOException)1 FileVisitResult (java.nio.file.FileVisitResult)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 ReportTestCase (org.apache.maven.plugins.surefire.report.ReportTestCase)1 ReportTestSuite (org.apache.maven.plugins.surefire.report.ReportTestSuite)1 SurefireReportParser (org.apache.maven.plugins.surefire.report.SurefireReportParser)1 MavenReportException (org.apache.maven.reporting.MavenReportException)1