Search in sources :

Example 31 with ProjectInspector

use of fr.inria.spirals.repairnator.process.inspectors.ProjectInspector in project repairnator by Spirals-Team.

the class TestNopolRepair method testNopolRepair.

@Test
public void testNopolRepair() throws IOException {
    // surli/failingProject build
    int buildId = 207890790;
    Build build = BuildHelper.getBuildFromId(buildId, null);
    assertThat(build, notNullValue());
    assertThat(buildId, is(build.getId()));
    Path tmpDirPath = Files.createTempDirectory("test_nopolrepair");
    File tmpDir = tmpDirPath.toFile();
    tmpDir.deleteOnExit();
    System.out.println("Dirpath : " + tmpDirPath);
    BuildToBeInspected toBeInspected = new BuildToBeInspected(build, null, ScannedBuildStatus.ONLY_FAIL, "");
    ProjectInspector inspector = new ProjectInspector(toBeInspected, tmpDir.getAbsolutePath(), null, null);
    CloneRepository cloneStep = new CloneRepository(inspector);
    NopolRepair nopolRepair = new NopolRepair(inspector);
    NopolRepair.TOTAL_MAX_TIME = 2;
    cloneStep.setNextStep(new CheckoutBuggyBuild(inspector)).setNextStep(new TestProject(inspector)).setNextStep(new GatherTestInformation(inspector, new BuildShouldFail(), false)).setNextStep(new ComputeClasspath(inspector)).setNextStep(new ComputeSourceDir(inspector, false)).setNextStep(nopolRepair);
    cloneStep.execute();
    assertThat(nopolRepair.shouldStop, is(false));
    assertThat(nopolRepair.getPipelineState(), is(PipelineState.NOPOL_PATCHED));
    assertThat(nopolRepair.getNopolInformations().size(), is(11));
// The following assertion is working when the test is launched in the current module
// however it does not work properly when launched from the root module,
// so it breaks the CI. The nopol logs should be treaten differently inside Nopol
// File nopolLog = new File(inspector.getRepoLocalPath(), "repairnator.nopol.log");
// assertTrue(nopolLog.exists());
}
Also used : Path(java.nio.file.Path) CheckoutBuggyBuild(fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild) BuildShouldFail(fr.inria.spirals.repairnator.process.step.gatherinfo.BuildShouldFail) ProjectInspector(fr.inria.spirals.repairnator.process.inspectors.ProjectInspector) BuildToBeInspected(fr.inria.spirals.repairnator.BuildToBeInspected) 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)

Example 32 with ProjectInspector

use of fr.inria.spirals.repairnator.process.inspectors.ProjectInspector in project repairnator by Spirals-Team.

the class TestNPERepair method testNPERepair.

@Test
public void testNPERepair() throws IOException {
    // surli/failingProject build
    int buildId = 252712792;
    Build build = BuildHelper.getBuildFromId(buildId, null);
    assertThat(build, notNullValue());
    assertThat(buildId, is(build.getId()));
    Path tmpDirPath = Files.createTempDirectory("test_nperepair");
    File tmpDir = tmpDirPath.toFile();
    tmpDir.deleteOnExit();
    System.out.println("Dirpath : " + tmpDirPath);
    BuildToBeInspected toBeInspected = new BuildToBeInspected(build, null, ScannedBuildStatus.ONLY_FAIL, "");
    ProjectInspector inspector = new ProjectInspector(toBeInspected, tmpDir.getAbsolutePath(), null, null);
    CloneRepository cloneStep = new CloneRepository(inspector);
    NPERepair npeRepair = new NPERepair(inspector);
    cloneStep.setNextStep(new CheckoutBuggyBuild(inspector)).setNextStep(new TestProject(inspector)).setNextStep(new GatherTestInformation(inspector, new BuildShouldFail(), false)).setNextStep(npeRepair);
    cloneStep.execute();
    assertThat(npeRepair.shouldStop, is(false));
    assertThat(npeRepair.getPipelineState(), is(PipelineState.NPEFIX_PATCHED));
    assertThat(inspector.getJobStatus().getNpeFixPatches().size(), is(6));
}
Also used : Path(java.nio.file.Path) CheckoutBuggyBuild(fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild) GatherTestInformation(fr.inria.spirals.repairnator.process.step.gatherinfo.GatherTestInformation) Build(fr.inria.jtravis.entities.Build) CheckoutBuggyBuild(fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild) BuildShouldFail(fr.inria.spirals.repairnator.process.step.gatherinfo.BuildShouldFail) ProjectInspector(fr.inria.spirals.repairnator.process.inspectors.ProjectInspector) File(java.io.File) BuildToBeInspected(fr.inria.spirals.repairnator.BuildToBeInspected) Test(org.junit.Test)

Example 33 with ProjectInspector

use of fr.inria.spirals.repairnator.process.inspectors.ProjectInspector in project repairnator by Spirals-Team.

the class TestTestProject method testTestProjectWhenNotFailing.

@Test
public void testTestProjectWhenNotFailing() throws IOException {
    // surli/failingProject build
    int buildId = 201176013;
    Build build = BuildHelper.getBuildFromId(buildId, null);
    assertThat(build, notNullValue());
    assertThat(buildId, is(build.getId()));
    Path tmpDirPath = Files.createTempDirectory("test_clone");
    File tmpDir = tmpDirPath.toFile();
    tmpDir.deleteOnExit();
    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);
    TestProject testProject = new TestProject(inspector);
    cloneStep.setNextStep(new CheckoutBuggyBuild(inspector)).setNextStep(testProject);
    cloneStep.execute();
    assertThat(testProject.shouldStop, is(false));
    assertThat(testProject.getPipelineState(), is(PipelineState.NOTFAILING));
    assertThat(jobStatus.getPipelineState(), is(PipelineState.NOTFAILING));
}
Also used : Path(java.nio.file.Path) JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) CheckoutBuggyBuild(fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild) Build(fr.inria.jtravis.entities.Build) CheckoutBuggyBuild(fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild) GitHelper(fr.inria.spirals.repairnator.process.git.GitHelper) ProjectInspector(fr.inria.spirals.repairnator.process.inspectors.ProjectInspector) File(java.io.File) BuildToBeInspected(fr.inria.spirals.repairnator.BuildToBeInspected) Test(org.junit.Test)

Example 34 with ProjectInspector

use of fr.inria.spirals.repairnator.process.inspectors.ProjectInspector in project repairnator by Spirals-Team.

the class TestTestProject method testTestProjectWhenErroring.

@Test
public void testTestProjectWhenErroring() throws IOException {
    // surli/failingProject build
    int buildId = 208240908;
    Build build = BuildHelper.getBuildFromId(buildId, null);
    assertThat(build, notNullValue());
    assertThat(buildId, is(build.getId()));
    Path tmpDirPath = Files.createTempDirectory("test_clone");
    File tmpDir = tmpDirPath.toFile();
    tmpDir.deleteOnExit();
    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);
    TestProject testProject = new TestProject(inspector);
    cloneStep.setNextStep(new CheckoutBuggyBuild(inspector)).setNextStep(testProject);
    cloneStep.execute();
    assertThat(testProject.shouldStop, is(false));
    assertThat(testProject.getPipelineState(), is(PipelineState.TESTABLE));
    assertThat(jobStatus.getPipelineState(), is(PipelineState.TESTABLE));
}
Also used : Path(java.nio.file.Path) JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) CheckoutBuggyBuild(fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild) Build(fr.inria.jtravis.entities.Build) CheckoutBuggyBuild(fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild) GitHelper(fr.inria.spirals.repairnator.process.git.GitHelper) ProjectInspector(fr.inria.spirals.repairnator.process.inspectors.ProjectInspector) File(java.io.File) BuildToBeInspected(fr.inria.spirals.repairnator.BuildToBeInspected) Test(org.junit.Test)

Example 35 with ProjectInspector

use of fr.inria.spirals.repairnator.process.inspectors.ProjectInspector in project repairnator by Spirals-Team.

the class TestCheckoutBuggyBuildSourceCode method testCheckoutPreviousBuildSourceCodeNoPR2.

@Test
public void testCheckoutPreviousBuildSourceCodeNoPR2() throws IOException, GitAPIException, RepairnatorConfigException {
    // alibaba/fastjson
    int buildId = 222020421;
    int previousBuildId = 222016611;
    ScannedBuildStatus status = ScannedBuildStatus.PASSING_AND_PASSING_WITH_TEST_CHANGES;
    Build build = BuildHelper.getBuildFromId(buildId, null);
    assertThat(build, notNullValue());
    assertThat(buildId, is(build.getId()));
    assertThat(build.isPullRequest(), is(false));
    Build previousBuild = BuildHelper.getBuildFromId(previousBuildId, null);
    assertThat(previousBuild, notNullValue());
    assertThat(previousBuild.getId(), is(previousBuildId));
    assertThat(previousBuild.isPullRequest(), is(false));
    Path tmpDirPath = Files.createTempDirectory("test_checkoutprevious");
    File tmpDir = tmpDirPath.toFile();
    tmpDir.deleteOnExit();
    BuildToBeInspected toBeInspected = new BuildToBeInspected(build, previousBuild, status, "");
    ProjectInspector inspector = mock(ProjectInspector.class);
    when(inspector.getWorkspace()).thenReturn(tmpDir.getAbsolutePath());
    when(inspector.getRepoLocalPath()).thenReturn(tmpDir.getAbsolutePath() + "/repo");
    when(inspector.getRepoToPushLocalPath()).thenReturn(tmpDir.getAbsolutePath() + "/repotopush");
    when(inspector.getBuildToBeInspected()).thenReturn(toBeInspected);
    when(inspector.getPatchedBuild()).thenReturn(build);
    when(inspector.getBuggyBuild()).thenReturn(previousBuild);
    when(inspector.getGitHelper()).thenReturn(new GitHelper());
    JobStatus jobStatus = new JobStatus(tmpDir.getAbsolutePath() + "/repo");
    when(inspector.getJobStatus()).thenReturn(jobStatus);
    CloneRepository cloneStep = new CloneRepository(inspector);
    CheckoutBuggyBuildSourceCode checkoutBuild = new CheckoutBuggyBuildSourceCode(inspector);
    cloneStep.setNextStep(checkoutBuild);
    cloneStep.execute();
    assertThat(checkoutBuild.getPipelineState(), is(PipelineState.PREVIOUSBUILDCODECHECKEDOUT));
    assertThat(jobStatus.getPipelineState(), is(PipelineState.PREVIOUSBUILDCODECHECKEDOUT));
    assertThat(checkoutBuild.isShouldStop(), is(false));
    Git gitDir = Git.open(new File(tmpDir, "repo"));
    Iterable<RevCommit> logs = gitDir.log().call();
    Iterator<RevCommit> iterator = logs.iterator();
    boolean foundRightCommitAfterRepairCommits = false;
    boolean foundUndoSourceCodeCommit = false;
    boolean stopSearch = false;
    while (iterator.hasNext() && !stopSearch) {
        RevCommit revCommit = iterator.next();
        if (revCommit.getShortMessage().equals("Undo changes on source code")) {
            foundUndoSourceCodeCommit = true;
            CanonicalTreeParser oldTreeIter = new CanonicalTreeParser();
            CanonicalTreeParser newTreeIter = new CanonicalTreeParser();
            ObjectReader reader = gitDir.getRepository().newObjectReader();
            RevCommit prevCommit = iterator.next();
            oldTreeIter.reset(reader, prevCommit.getTree());
            newTreeIter.reset(reader, revCommit.getTree());
            List<DiffEntry> diff = gitDir.diff().setOldTree(oldTreeIter).setNewTree(newTreeIter).call();
            for (DiffEntry entry : diff) {
                assertThat(entry.getOldPath(), startsWith("src/main/java/"));
            }
            revCommit = prevCommit;
        }
        if (revCommit.getName().equals(build.getCommit().getSha())) {
            foundRightCommitAfterRepairCommits = true;
        }
        if (!revCommit.getShortMessage().contains("repairnator")) {
            stopSearch = true;
        }
        if (foundRightCommitAfterRepairCommits && foundUndoSourceCodeCommit) {
            stopSearch = true;
        }
    }
    assertThat(foundRightCommitAfterRepairCommits, is(true));
    assertThat(foundUndoSourceCodeCommit, is(true));
}
Also used : Path(java.nio.file.Path) GitHelper(fr.inria.spirals.repairnator.process.git.GitHelper) ProjectInspector(fr.inria.spirals.repairnator.process.inspectors.ProjectInspector) BuildToBeInspected(fr.inria.spirals.repairnator.BuildToBeInspected) CanonicalTreeParser(org.eclipse.jgit.treewalk.CanonicalTreeParser) JobStatus(fr.inria.spirals.repairnator.process.inspectors.JobStatus) CloneRepository(fr.inria.spirals.repairnator.process.step.CloneRepository) Git(org.eclipse.jgit.api.Git) ScannedBuildStatus(fr.inria.spirals.repairnator.states.ScannedBuildStatus) Build(fr.inria.jtravis.entities.Build) ObjectReader(org.eclipse.jgit.lib.ObjectReader) File(java.io.File) RevCommit(org.eclipse.jgit.revwalk.RevCommit) DiffEntry(org.eclipse.jgit.diff.DiffEntry) Test(org.junit.Test)

Aggregations

ProjectInspector (fr.inria.spirals.repairnator.process.inspectors.ProjectInspector)43 Test (org.junit.Test)40 JobStatus (fr.inria.spirals.repairnator.process.inspectors.JobStatus)39 File (java.io.File)35 Path (java.nio.file.Path)35 Build (fr.inria.jtravis.entities.Build)33 BuildToBeInspected (fr.inria.spirals.repairnator.BuildToBeInspected)33 GitHelper (fr.inria.spirals.repairnator.process.git.GitHelper)30 CheckoutBuggyBuild (fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutBuggyBuild)24 CloneRepository (fr.inria.spirals.repairnator.process.step.CloneRepository)10 CheckoutPatchedBuild (fr.inria.spirals.repairnator.process.step.checkoutrepository.CheckoutPatchedBuild)8 GatherTestInformation (fr.inria.spirals.repairnator.process.step.gatherinfo.GatherTestInformation)7 Git (org.eclipse.jgit.api.Git)7 BuildShouldFail (fr.inria.spirals.repairnator.process.step.gatherinfo.BuildShouldFail)6 RevCommit (org.eclipse.jgit.revwalk.RevCommit)6 RepairnatorConfig (fr.inria.spirals.repairnator.config.RepairnatorConfig)4 ScannedBuildStatus (fr.inria.spirals.repairnator.states.ScannedBuildStatus)3 DiffEntry (org.eclipse.jgit.diff.DiffEntry)3 ObjectReader (org.eclipse.jgit.lib.ObjectReader)3 CanonicalTreeParser (org.eclipse.jgit.treewalk.CanonicalTreeParser)3