Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into report-viewer/comp…
Browse files Browse the repository at this point in the history
…arison-table-test

# Conflicts:
#	report-viewer/package-lock.json
  • Loading branch information
Kr0nox committed Sep 1, 2024
2 parents d4f1735 + 04905d0 commit 850e65b
Show file tree
Hide file tree
Showing 75 changed files with 998 additions and 873 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/complete-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
node-version: "18"

- name: Build Assembly
run: mvn -Pwith-report-viewer -DskipTests clean package assembly:single
run: mvn -DskipTests clean package assembly:single

- name: Rename Jar
run: mv cli/target/jplag-*-jar-with-dependencies.jar cli/target/jplag.jar
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
- "**/pom.xml"
- "**.java"
- "**.g4"
- "report-viewer/**"
pull_request:
types: [opened, synchronize, reopened]
paths:
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ jobs:
with:
node-version: "18"

- name: Set version of Report Viewer
shell: bash
run: |
VERSION=$(grep "<revision>" pom.xml | grep -oPm1 "(?<=<revision>)[^-|<]+")
MAJOR=$(echo $VERSION | cut -d '.' -f 1)
MINOR=$(echo $VERSION | cut -d '.' -f 2)
PATCH=$(echo $VERSION | cut -d '.' -f 3)
json=$(cat report-viewer/src/version.json)
json=$(echo "$json" | jq --arg MAJOR "$MAJOR" --arg MINOR "$MINOR" --arg PATCH "$PATCH" '.report_viewer_version |= { "major": $MAJOR | tonumber, "minor": $MINOR | tonumber, "patch": $PATCH | tonumber }')
echo "$json" > report-viewer/src/version.json
echo "Version of Report Viewer:"
cat report-viewer/src/version.json
- name: Build JPlag
run: mvn -Pwith-report-viewer -U -B clean package assembly:single

Expand Down
43 changes: 0 additions & 43 deletions .github/workflows/report-viewer.yml

This file was deleted.

2 changes: 1 addition & 1 deletion cli/src/main/java/de/jplag/cli/options/CliOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class CliOptions implements Runnable {
public String resultFile = "results";

@Option(names = {"-M", "--mode"}, description = "The mode of JPlag. One of: ${COMPLETION-CANDIDATES} (default: ${DEFAULT_VALUE})")
public JPlagMode mode = JPlagMode.RUN;
public JPlagMode mode = JPlagMode.RUN_AND_VIEW;

@Option(names = {"--normalize"}, description = "Activate the normalization of tokens. Supported for languages: Java, C++.")
public boolean normalize = false;
Expand Down
27 changes: 27 additions & 0 deletions cli/src/test/java/de/jplag/cli/DebugTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package de.jplag.cli;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;

import org.junit.jupiter.api.Test;

import de.jplag.cli.test.CliArgument;
import de.jplag.cli.test.CliTest;
import de.jplag.exceptions.ExitException;
import de.jplag.options.JPlagOptions;

class DebugTest extends CliTest {
@Test
void testDefaultDebug() throws IOException, ExitException {
JPlagOptions options = runCliForOptions();
assertFalse(options.debugParser());
}

@Test
void testSetDebug() throws IOException, ExitException {
JPlagOptions options = runCliForOptions(args -> args.with(CliArgument.DEBUG, true));
assertTrue(options.debugParser());
}
}
29 changes: 29 additions & 0 deletions cli/src/test/java/de/jplag/cli/ExcludeFileTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package de.jplag.cli;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.io.IOException;

import org.junit.jupiter.api.Test;

import de.jplag.cli.test.CliArgument;
import de.jplag.cli.test.CliTest;
import de.jplag.exceptions.ExitException;
import de.jplag.options.JPlagOptions;

class ExcludeFileTest extends CliTest {
private static final String EXCLUDE_FILE_NAME = "exclusions";

@Test
void testNoDefaultExcludeFile() throws IOException, ExitException {
JPlagOptions options = runCliForOptions();
assertNull(options.exclusionFileName());
}

@Test
void testSetExcludeFile() throws IOException, ExitException {
JPlagOptions options = runCliForOptions(args -> args.with(CliArgument.EXCLUDE_FILES, EXCLUDE_FILE_NAME));
assertEquals(EXCLUDE_FILE_NAME, options.exclusionFileName());
}
}
28 changes: 28 additions & 0 deletions cli/src/test/java/de/jplag/cli/LogLevelTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package de.jplag.cli;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.IOException;

import org.junit.jupiter.api.Test;
import org.slf4j.event.Level;

import de.jplag.cli.test.CliArgument;
import de.jplag.cli.test.CliTest;
import de.jplag.exceptions.ExitException;

class LogLevelTest extends CliTest {
private static final Level DEFAULT_LOG_LEVEL = Level.INFO;

@Test
void testDefaultLogLevel() throws IOException, ExitException {
Level level = runCliForLogLevel();
assertEquals(DEFAULT_LOG_LEVEL, level);
}

@Test
void testSetLogLevel() throws IOException, ExitException {
Level level = runCliForLogLevel(args -> args.with(CliArgument.LOG_LEVEL, Level.ERROR.name()));
assertEquals(Level.ERROR, level);
}
}
68 changes: 68 additions & 0 deletions cli/src/test/java/de/jplag/cli/ResultFileTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package de.jplag.cli;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

import org.junit.jupiter.api.Test;

import de.jplag.cli.test.CliArgument;
import de.jplag.cli.test.CliTest;
import de.jplag.exceptions.ExitException;

class ResultFileTest extends CliTest {
private static final String DEFAULT_RESULT_FILE = "results.zip";
private static final String TEST_RESULT_FILE = "customResults.zip";
private static final String TEST_RESULT_FILE_WITH_AVOIDANCE = "customResults(1).zip";
private static final String TEST_RESULT_FILE_WITHOUT_ZIP = "customResults";

@Test
void testDefaultResultFolder() throws IOException, ExitException {
String targetPath = runCliForTargetPath();
assertEquals(DEFAULT_RESULT_FILE, targetPath);
}

@Test
void testSetResultFolder() throws IOException, ExitException {
String targetPath = runCliForTargetPath(args -> args.with(CliArgument.RESULT_FILE, TEST_RESULT_FILE));
assertEquals(TEST_RESULT_FILE, targetPath);
}

@Test
void testSetResultFolderWithoutZip() throws IOException, ExitException {
String targetPath = runCliForTargetPath(args -> args.with(CliArgument.RESULT_FILE, TEST_RESULT_FILE_WITHOUT_ZIP));
assertEquals(TEST_RESULT_FILE, targetPath);
}

@Test
void testResultFileOverrideAvoidance() throws IOException, ExitException {
File testDir = Files.createTempDirectory("JPlagResultFileTest").toFile();
File targetFile = new File(testDir, TEST_RESULT_FILE);
File expectedTargetFile = new File(testDir, TEST_RESULT_FILE_WITH_AVOIDANCE);
targetFile.createNewFile();

String actualTargetPath = runCliForTargetPath(args -> args.with(CliArgument.RESULT_FILE, targetFile.getAbsolutePath()));

targetFile.delete();
testDir.delete();

assertEquals(expectedTargetFile.getAbsolutePath(), actualTargetPath);
}

@Test
void testResultFileOverwrite() throws IOException, ExitException {
File testDir = Files.createTempDirectory("JPlagResultFileTest").toFile();
File targetFile = new File(testDir, TEST_RESULT_FILE);
targetFile.createNewFile();

String actualTargetPath = runCliForTargetPath(
args -> args.with(CliArgument.RESULT_FILE, targetFile.getAbsolutePath()).with(CliArgument.OVERWRITE_RESULT_FILE, true));

targetFile.delete();
testDir.delete();

assertEquals(targetFile.getAbsolutePath(), actualTargetPath);
}
}
29 changes: 29 additions & 0 deletions cli/src/test/java/de/jplag/cli/SubdirectoryTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package de.jplag.cli;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.io.IOException;

import org.junit.jupiter.api.Test;

import de.jplag.cli.test.CliArgument;
import de.jplag.cli.test.CliTest;
import de.jplag.exceptions.ExitException;
import de.jplag.options.JPlagOptions;

class SubdirectoryTest extends CliTest {
private static final String TEST_SUBDIRECTORY = "dir";

@Test
void testDefaultSubdirectory() throws IOException, ExitException {
JPlagOptions options = runCliForOptions();
assertNull(options.subdirectoryName());
}

@Test
void testSetSubdirectory() throws IOException, ExitException {
JPlagOptions options = runCliForOptions(args -> args.with(CliArgument.SUBDIRECTORY, TEST_SUBDIRECTORY));
assertEquals(TEST_SUBDIRECTORY, options.subdirectoryName());
}
}
30 changes: 30 additions & 0 deletions cli/src/test/java/de/jplag/cli/SuffixesTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package de.jplag.cli;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.IOException;
import java.util.List;

import org.junit.jupiter.api.Test;

import de.jplag.cli.test.CliArgument;
import de.jplag.cli.test.CliTest;
import de.jplag.exceptions.ExitException;
import de.jplag.options.JPlagOptions;

class SuffixesTest extends CliTest {
private static final List<String> JAVA_SUFFIXES = List.of(".java", ".JAVA");
private static final List<String> CUSTOM_SUFFIXES = List.of(".j", ".jva");

@Test
void testDefaultSuffixes() throws IOException, ExitException {
JPlagOptions options = runCliForOptions();
assertEquals(JAVA_SUFFIXES, options.fileSuffixes());
}

@Test
void testSetSuffixes() throws IOException, ExitException {
JPlagOptions options = runCliForOptions(args -> args.with(CliArgument.SUFFIXES, CUSTOM_SUFFIXES.toArray(new String[0])));
assertEquals(CUSTOM_SUFFIXES, options.fileSuffixes());
}
}
6 changes: 6 additions & 0 deletions cli/src/test/java/de/jplag/cli/test/CliArgument.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ public record CliArgument<T>(String name, boolean isPositional) {

public static CliArgument<String> RESULT_FILE = new CliArgument<>("r", false);
public static CliArgument<Boolean> OVERWRITE_RESULT_FILE = new CliArgument<>("overwrite", false);

public static CliArgument<String> LOG_LEVEL = new CliArgument<>("log-level", false);
public static CliArgument<Boolean> DEBUG = new CliArgument<>("d", false);

public static CliArgument<String> SUBDIRECTORY = new CliArgument<>("subdirectory", false);
public static CliArgument<String> EXCLUDE_FILES = new CliArgument<>("x", false);
}
4 changes: 3 additions & 1 deletion cli/src/test/java/de/jplag/cli/test/CliResult.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package de.jplag.cli.test;

import org.slf4j.event.Level;

import de.jplag.options.JPlagOptions;

public record CliResult(JPlagOptions jPlagOptions, String targetPath) {
public record CliResult(JPlagOptions jPlagOptions, String targetPath, Level logLevel) {
}
27 changes: 26 additions & 1 deletion cli/src/test/java/de/jplag/cli/test/CliTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
import org.junit.jupiter.api.BeforeEach;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.slf4j.event.Level;

import de.jplag.JPlagResult;
import de.jplag.cli.*;
import de.jplag.cli.logger.CollectedLogger;
import de.jplag.cli.picocli.CliInputHandler;
import de.jplag.exceptions.ExitException;
import de.jplag.options.JPlagOptions;
Expand Down Expand Up @@ -105,6 +107,29 @@ protected String runCliForTargetPath(Consumer<CliArgumentBuilder> additionalOpti
return runCli(additionalOptionsBuilder).targetPath();
}

/**
* Runs the cli
* @return The log level set by the cli
* @throws ExitException If JPlag throws an exception
* @throws IOException If JPlag throws an exception
* @see #runCli()
*/
protected Level runCliForLogLevel() throws IOException, ExitException {
return runCli().logLevel();
}

/**
* Runs the cli using custom options
* @param additionalOptionsBuilder May modify the {@link CliArgumentBuilder} object to set custom options for this run.
* @return The log level set by the cli
* @throws ExitException If JPlag throws an exception
* @throws IOException If JPlag throws an exception
* @see #runCli()
*/
protected Level runCliForLogLevel(Consumer<CliArgumentBuilder> additionalOptionsBuilder) throws IOException, ExitException {
return runCli(additionalOptionsBuilder).logLevel();
}

/**
* Runs the cli
* @return The options returned by the cli
Expand All @@ -129,7 +154,7 @@ protected CliResult runCli(Consumer<CliArgumentBuilder> additionalOptionsBuilder

String targetPath = (String) getWritableFileMethod.invoke(cli);

return new CliResult(optionsBuilder.buildOptions(), targetPath);
return new CliResult(optionsBuilder.buildOptions(), targetPath, CollectedLogger.getLogLevel());
} catch (IllegalAccessException | InvocationTargetException e) {
Assumptions.abort("Could not access private field in CLI for test.");
return null; // will not be executed
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.8.0</version>
<version>3.10.0</version>
<configuration>
<sourcepath>src/main/java;target/generated-sources/annotations</sourcepath>
</configuration>
Expand Down
Loading

0 comments on commit 850e65b

Please sign in to comment.