use of fr.inria.spirals.repairnator.BuildToBeInspected 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));
}
use of fr.inria.spirals.repairnator.BuildToBeInspected in project repairnator by Spirals-Team.
the class TestCheckoutBuggyBuildSourceCode method testCheckoutPreviousBuildSourceCodeNoPR.
@Test
public void testCheckoutPreviousBuildSourceCodeNoPR() throws IOException, GitAPIException, RepairnatorConfigException {
// INRIA/spoon
int buildId = 221992429;
int previousBuildId = 218213030;
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(previousBuild, build, 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));
}
use of fr.inria.spirals.repairnator.BuildToBeInspected in project repairnator by Spirals-Team.
the class TestCheckoutBuild method testCheckoutBuildFromPRWithMerge.
@Test
public void testCheckoutBuildFromPRWithMerge() throws IOException, GitAPIException {
// surli/failingProject build
int buildId = 199923736;
Build build = BuildHelper.getBuildFromId(buildId, null);
assertThat(build, notNullValue());
assertThat(buildId, is(build.getId()));
Path tmpDirPath = Files.createTempDirectory("test_checkout");
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.getGitHelper()).thenReturn(new GitHelper());
JobStatus jobStatus = new JobStatus(tmpDir.getAbsolutePath() + "/repo");
when(inspector.getJobStatus()).thenReturn(jobStatus);
CloneRepository cloneStep = new CloneRepository(inspector);
CheckoutBuggyBuild checkoutBuggyBuild = new CheckoutBuggyBuild(inspector);
cloneStep.setNextStep(checkoutBuggyBuild);
cloneStep.execute();
assertThat(checkoutBuggyBuild.getPipelineState(), is(PipelineState.BUILDCHECKEDOUT));
assertThat(jobStatus.getPipelineState(), is(PipelineState.BUILDCHECKEDOUT));
assertThat(checkoutBuggyBuild.isShouldStop(), is(false));
}
use of fr.inria.spirals.repairnator.BuildToBeInspected in project repairnator by Spirals-Team.
the class TestCheckoutBuild method testCheckoutBuggyBuild.
@Test
public void testCheckoutBuggyBuild() throws IOException, GitAPIException, RepairnatorConfigException {
// surli/failingProject build
int buildId = 207924136;
RepairnatorConfig repairnatorConfig = RepairnatorConfig.getInstance();
repairnatorConfig.setClean(false);
Build build = BuildHelper.getBuildFromId(buildId, null);
assertThat(build, notNullValue());
assertThat(buildId, is(build.getId()));
Path tmpDirPath = Files.createTempDirectory("test_checkout");
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.getGitHelper()).thenReturn(new GitHelper());
JobStatus jobStatus = new JobStatus(tmpDir.getAbsolutePath() + "/repo");
when(inspector.getJobStatus()).thenReturn(jobStatus);
CloneRepository cloneStep = new CloneRepository(inspector);
CheckoutBuggyBuild checkoutBuggyBuild = new CheckoutBuggyBuild(inspector);
cloneStep.setNextStep(checkoutBuggyBuild);
cloneStep.execute();
assertThat(checkoutBuggyBuild.getPipelineState(), is(PipelineState.BUILDCHECKEDOUT));
assertThat(jobStatus.getPipelineState(), is(PipelineState.BUILDCHECKEDOUT));
assertThat(checkoutBuggyBuild.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 stopSearch = false;
while (iterator.hasNext() && !stopSearch) {
RevCommit revCommit = iterator.next();
if (revCommit.getName().equals(build.getCommit().getSha())) {
foundRightCommitAfterRepairCommits = true;
stopSearch = true;
} else if (!revCommit.getShortMessage().contains("repairnator")) {
stopSearch = true;
}
}
assertThat(foundRightCommitAfterRepairCommits, is(true));
}
use of fr.inria.spirals.repairnator.BuildToBeInspected in project repairnator by Spirals-Team.
the class TestProjectInspector method testSpoonException.
@Test
public void testSpoonException() throws IOException, GitAPIException {
// surli/failingProject only-one-failing
int buildId = 355743087;
Path tmpDirPath = Files.createTempDirectory("test_spoonexception");
File tmpDir = tmpDirPath.toFile();
tmpDir.deleteOnExit();
Build failingBuild = BuildHelper.getBuildFromId(buildId, null);
BuildToBeInspected buildToBeInspected = new BuildToBeInspected(failingBuild, null, ScannedBuildStatus.ONLY_FAIL, "test");
List<AbstractDataSerializer> serializers = new ArrayList<>();
List<AbstractNotifier> notifiers = new ArrayList<>();
List<SerializerEngine> serializerEngines = new ArrayList<>();
SerializerEngine serializerEngine = mock(SerializerEngine.class);
serializerEngines.add(serializerEngine);
serializers.add(new InspectorSerializer(serializerEngines));
serializers.add(new NopolSerializer(serializerEngines));
RepairnatorConfig config = RepairnatorConfig.getInstance();
config.setLauncherMode(LauncherMode.REPAIR);
ProjectInspector inspector = new ProjectInspector(buildToBeInspected, tmpDir.getAbsolutePath(), serializers, notifiers);
inspector.run();
JobStatus jobStatus = inspector.getJobStatus();
assertThat(jobStatus.getPipelineState(), is(PipelineState.NOPOL_NOTPATCHED));
assertThat(jobStatus.getNopolInformations().get(0).getStatus(), is(NopolStatus.EXCEPTION));
verify(serializerEngine, times(1)).serialize(anyListOf(SerializedData.class), eq(SerializerType.INSPECTOR));
}
Aggregations