Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robinmaisch committed Mar 18, 2024
1 parent 95fcb9e commit 640e1fa
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 44 deletions.
47 changes: 16 additions & 31 deletions languages/java-cpg/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.jplag</groupId>
Expand All @@ -17,13 +15,19 @@
<kotlin.version>1.9.0</kotlin.version>
</properties>


<dependencies>

<dependency>
<groupId>${cpg.groupId}</groupId>
<artifactId>cpg-core</artifactId>
<version>${cpg.version}</version>

<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>${cpg.groupId}</groupId>
Expand All @@ -35,11 +39,6 @@
<artifactId>cpg-analysis</artifactId>
<version>${cpg.version}</version>
</dependency>
<dependency>
<groupId>${cpg.groupId}</groupId>
<artifactId>cpg-neo4j</artifactId>
<version>${cpg.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
Expand All @@ -51,52 +50,38 @@
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.jplag</groupId>
<artifactId>jplag</artifactId>
<version>${revision}</version>
<scope>test</scope>
</dependency>
</dependencies>

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

<build>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<configuration>
<jvmTarget>1.8</jvmTarget>
<args>
<arg>-Xcontext-receivers</arg>
</args>
</configuration>
<executions>
<execution>
<id>compile</id>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>
<phase>process-sources</phase>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
<phase>test-compile</phase>
</execution>
</executions>
<configuration>
<jvmTarget>1.8</jvmTarget>
<args>
<arg>-Xcontext-receivers</arg>
</args>
</configuration>
</plugin>
</plugins>
</build>


</project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import de.jplag.ParsingException;
import de.jplag.java_cpg.transformation.matching.CpgIsomorphismDetector;
import de.jplag.java_cpg.transformation.matching.PatternRepository;
import de.jplag.java_cpg.transformation.matching.pattern.GraphPatternBuilder;
import de.jplag.java_cpg.transformation.matching.pattern.Match;
import de.jplag.java_cpg.transformation.matching.pattern.SimpleGraphPattern;

Expand All @@ -34,7 +33,7 @@ public static Stream<Arguments> providePairs() {

@ParameterizedTest
@MethodSource("providePairs")
public <T extends Node> void testMatch(String filename, Class<T> rootType, GraphPatternBuilder builder) {
public <T extends Node> void testMatch(String filename, Class<T> rootType, SimpleGraphPattern<T> pattern) {
File file = new File(baseDirectory, filename);
try {
CpgAdapter cpgAdapter = new CpgAdapter();
Expand All @@ -44,9 +43,8 @@ public <T extends Node> void testMatch(String filename, Class<T> rootType, Graph
detector.loadGraph(graph);
List<T> rootCandidates = detector.getNodesOfType(rootType);

SimpleGraphPattern<?> pattern1 = (SimpleGraphPattern<?>) builder.build();
Assertions.assertTrue(rootCandidates.stream().anyMatch(candidate -> {
List<Match> matches = pattern1.recursiveMatch(candidate);
List<Match> matches = pattern.recursiveMatch(candidate);
if (matches.isEmpty()) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.jplag.java_cpg.transform;

import static de.jplag.java_cpg.transformation.TransformationRepository.*;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -22,7 +24,6 @@
import de.jplag.Token;
import de.jplag.java_cpg.JavaCpgLanguage;
import de.jplag.java_cpg.transformation.GraphTransformation;
import de.jplag.java_cpg.transformation.TransformationRepository;

/**
* An integration test that checks whether pairs of submissions are accepted as equal after being subjected to different
Expand All @@ -41,14 +42,15 @@ public static void setUpOnce() {
}

private static Stream<Arguments> getArguments() {
return Stream.of(Arguments.of("singleUseVariable", new GraphTransformation[] {TransformationRepository.inlineSingleUseVariable}),
Arguments.of("constantClass", new GraphTransformation[] {TransformationRepository.moveConstantToOnlyUsingClass}),
Arguments.of("for2While", new GraphTransformation[] {TransformationRepository.forStatementToWhileStatement}),
Arguments.of("negatedIf", new GraphTransformation[] {TransformationRepository.ifWithNegatedConditionResolution}),
Arguments.of("unusedVariables",
new GraphTransformation[] {TransformationRepository.removeUnusedVariableDeclarationStatement,
TransformationRepository.removeUnusedVariableDeclaration, TransformationRepository.removeEmptyDeclarationStatement}),
Arguments.of("dfgLinearization", new GraphTransformation[] {}));
return Stream
.of(Arguments.of("singleUseVariable", new GraphTransformation[] {inlineSingleUseVariable}),
Arguments.of("constantClass",
new GraphTransformation[] {moveConstantToOnlyUsingClass, removeLibraryRecord, removeLibraryField}),
Arguments.of("for2While", new GraphTransformation[] {forStatementToWhileStatement}),
Arguments.of("negatedIf", new GraphTransformation[] {ifWithNegatedConditionResolution}),
Arguments.of("unusedVariables", new GraphTransformation[] {removeUnusedVariableDeclarationStatement,
removeUnusedVariableDeclaration, removeEmptyDeclarationStatement}),
Arguments.of("dfgLinearization", new GraphTransformation[] {}));
}

@ParameterizedTest
Expand Down

0 comments on commit 640e1fa

Please sign in to comment.