-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ASTDiff: Test for Problematic cases based on the previous snapshot
- Loading branch information
1 parent
28aeb68
commit fac0757
Showing
256 changed files
with
7,175,144 additions
and
4 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
src/test/java/org/refactoringminer/astDiff/tests/Defects4JProblematicCasesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.refactoringminer.astDiff.tests; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import net.joshka.junit.json.params.JsonFileSource; | ||
import org.apache.commons.io.FileUtils; | ||
import org.json.JSONException; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.converter.ConvertWith; | ||
import org.refactoringminer.astDiff.actions.ASTDiff; | ||
import org.refactoringminer.astDiff.utils.CaseInfo; | ||
import org.refactoringminer.astDiff.utils.MappingExportModel; | ||
import org.refactoringminer.rm1.GitHistoryRefactoringMinerImpl; | ||
import org.skyscreamer.jsonassert.JSONAssert; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
import static org.junit.jupiter.api.Assertions.fail; | ||
import static org.refactoringminer.astDiff.utils.UtilMethods.*; | ||
|
||
/** | ||
* @author Pourya Alikhani Fard [email protected] | ||
*/ | ||
public class Defects4JProblematicCasesTest { | ||
private static final String dir = getDefects4jMappingPath(); | ||
@ParameterizedTest(name= "{index}: {0}") | ||
@JsonFileSource(resources = "/astDiff/defects4j/cases-problematic.json") | ||
public void testSubTreeMappings(@ConvertWith(CaseInfo.CaseInfoConverter.class) CaseInfo info) throws JsonProcessingException, JSONException { | ||
File mappingsDirFile = new File(getFinalFolderPath(dir, info.getRepo(), info.getCommit())); | ||
String[] files = mappingsDirFile.list(); | ||
List<String> expectedFilesList = new ArrayList<>(List.of(Objects.requireNonNull(files))); | ||
String projectDir = info.getRepo(); | ||
String bugID = info.getCommit(); | ||
Set<ASTDiff> astDiffs = new GitHistoryRefactoringMinerImpl().diffAtDirectories( | ||
Path.of(getDefect4jBeforeDir(projectDir, bugID)), | ||
Path.of(getDefect4jAfterDir(projectDir, bugID))).getDiffSet(); | ||
|
||
for (ASTDiff astDiff : astDiffs) { | ||
String finalFilePath = getFinalFilePath(astDiff, dir, info.getRepo(), info.getCommit()); | ||
finalFilePath = getSnapShotPath(finalFilePath); | ||
//Because we store the previous snapshot of problematic cases in /astDiff/SNAPSHOT/ | ||
String calculated = MappingExportModel.exportString(astDiff.getAllMappings()); | ||
String msg = String.format("Failed for %s/commit/%s , srcFileName: %s",info.getRepo().replace(".git",""),info.getCommit(),astDiff.getSrcPath()); | ||
String expected = null; | ||
try { | ||
expected = FileUtils.readFileToString(new File(finalFilePath), "utf-8"); | ||
} catch (IOException e) { | ||
fail("File not found: " + finalFilePath + " for " + info.getRepo() + "/commit/" + info.getCommit() + " , srcFileName: " + astDiff.getSrcPath()); | ||
} | ||
JSONAssert.assertEquals(msg,expected, calculated, false); | ||
expectedFilesList.remove(getFileNameFromSrcDiff(astDiff.getSrcPath())); | ||
} | ||
for (String expectedButNotGeneratedFile : expectedFilesList) { | ||
String expectedDiffName = getSrcASTDiffFromFile(expectedButNotGeneratedFile); | ||
fail(expectedDiffName); | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/test/java/org/refactoringminer/astDiff/tests/RefactoringOracleProblematicCasesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.refactoringminer.astDiff.tests; | ||
|
||
import net.joshka.junit.json.params.JsonFileSource; | ||
import org.apache.commons.io.FileUtils; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.converter.ConvertWith; | ||
import org.refactoringminer.astDiff.actions.ASTDiff; | ||
import org.refactoringminer.astDiff.utils.CaseInfo; | ||
import org.refactoringminer.astDiff.utils.MappingExportModel; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
import static org.refactoringminer.astDiff.utils.UtilMethods.*; | ||
import static org.refactoringminer.astDiff.utils.UtilMethods.getSrcASTDiffFromFile; | ||
|
||
/* Created by pourya on 2024-02-17*/ | ||
public class RefactoringOracleProblematicCasesTest { | ||
private static final String dir = getCommitsMappingsPath(); | ||
@ParameterizedTest(name= "{index}: {0}") | ||
@JsonFileSource(resources = {"/astDiff/commits/cases-problematic.json"}) | ||
public void testSubTreeMappings(@ConvertWith(CaseInfo.CaseInfoConverter.class) CaseInfo info) throws Exception { | ||
File mappingsDirFile = new File(getFinalFolderPath(dir, info.getRepo(), info.getCommit())); | ||
String[] files = mappingsDirFile.list(); | ||
List<String> expectedFilesList = new ArrayList<>(List.of(Objects.requireNonNull(files))); | ||
boolean partial = info.getSrc_files() != null && !info.getSrc_files().isEmpty(); | ||
Set<ASTDiff> astDiffs = getProjectDiffLocally(info.makeURL()); | ||
boolean hit = false; | ||
for (ASTDiff astDiff : astDiffs) { | ||
String finalFilePath = getFinalFilePath(astDiff, dir, info.getRepo(), info.getCommit()); | ||
finalFilePath = getSnapShotPath(finalFilePath); | ||
//Because we store the previous snapshot of problematic cases in /astDiff/SNAPSHOT/ | ||
if (partial) | ||
if (!info.getSrc_files().contains(astDiff.getSrcPath())) | ||
continue; | ||
hit = true; | ||
String calculated = MappingExportModel.exportString(astDiff.getAllMappings()).replaceAll("\\r\\n", "\n").replaceAll("\\r", "\n"); | ||
String msg = String.format("Failed for %s/commit/%s , srcFileName: %s",info.getRepo().replace(".git",""),info.getCommit(),astDiff.getSrcPath()); | ||
String expected = null; | ||
try { | ||
expected = FileUtils.readFileToString(new File(finalFilePath), "utf-8"); | ||
assertEquals(expected.length(), calculated.length(), msg); | ||
} catch (IOException e) { | ||
fail("File not found: " + finalFilePath + " for " + info.getRepo() + "/commit/" + info.getCommit() + " , srcFileName: " + astDiff.getSrcPath()); | ||
} | ||
assertEquals(calculated, expected, msg); | ||
expectedFilesList.remove(getFileNameFromSrcDiff(astDiff.getSrcPath())); | ||
} | ||
for (String expectedButNotGeneratedFile : expectedFilesList) { | ||
String expectedDiffName = getSrcASTDiffFromFile(expectedButNotGeneratedFile); | ||
fail(expectedDiffName + " not generated for " + expectedDiffName); | ||
} | ||
if (!hit) | ||
fail("No diff checked for " + info.getRepo() + "/commit/" + info.getCommit()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.