aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.gradle1
-rw-r--r--src/functionalTest/java/ch/fhnw/thga/gradleplugins/CompileFregeTaskFunctionalTest.java2
-rw-r--r--src/functionalTest/java/ch/fhnw/thga/gradleplugins/RunFregeTaskFunctionalTest.java185
-rw-r--r--src/functionalTest/java/ch/fhnw/thga/gradleplugins/SetupFregeTaskFunctionalTest.java2
-rw-r--r--src/functionalTest/java/ch/fhnw/thga/gradleplugins/SharedFunctionalTestLogic.java4
-rw-r--r--src/functionalTest/java/ch/fhnw/thga/gradleplugins/fregeproject/FregeSourceFile.java2
6 files changed, 191 insertions, 5 deletions
diff --git a/build.gradle b/build.gradle
index 9baa197..084e5f1 100644
--- a/build.gradle
+++ b/build.gradle
@@ -73,5 +73,6 @@ tasks.withType(Test).configureEach
{
includeEngines 'jqwik', 'junit-jupiter'
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
+ excludeTags 'network'
}
}
diff --git a/src/functionalTest/java/ch/fhnw/thga/gradleplugins/CompileFregeTaskFunctionalTest.java b/src/functionalTest/java/ch/fhnw/thga/gradleplugins/CompileFregeTaskFunctionalTest.java
index 42a3de2..af3225d 100644
--- a/src/functionalTest/java/ch/fhnw/thga/gradleplugins/CompileFregeTaskFunctionalTest.java
+++ b/src/functionalTest/java/ch/fhnw/thga/gradleplugins/CompileFregeTaskFunctionalTest.java
@@ -5,6 +5,7 @@ import static ch.fhnw.thga.gradleplugins.FregePlugin.COMPILE_FREGE_TASK_NAME;
import static ch.fhnw.thga.gradleplugins.SharedFunctionalTestLogic.createFregeSection;
import static ch.fhnw.thga.gradleplugins.SharedFunctionalTestLogic.runAndFailGradleTask;
import static ch.fhnw.thga.gradleplugins.SharedFunctionalTestLogic.runGradleTask;
+import static ch.fhnw.thga.gradleplugins.SharedFunctionalTestLogic.NEW_LINE;
import static org.gradle.testkit.runner.TaskOutcome.FAILED;
import static org.gradle.testkit.runner.TaskOutcome.FROM_CACHE;
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS;
@@ -28,7 +29,6 @@ import ch.fhnw.thga.gradleplugins.fregeproject.FregeSourceFile;
public class CompileFregeTaskFunctionalTest
{
- private static final String NEW_LINE = System.lineSeparator();
private static final FregeSourceFile COMPLETION_FR = new FregeSourceFile(
String.format("%s/%s",
DEFAULT_RELATIVE_SOURCE_DIR,
diff --git a/src/functionalTest/java/ch/fhnw/thga/gradleplugins/RunFregeTaskFunctionalTest.java b/src/functionalTest/java/ch/fhnw/thga/gradleplugins/RunFregeTaskFunctionalTest.java
new file mode 100644
index 0000000..c0c870a
--- /dev/null
+++ b/src/functionalTest/java/ch/fhnw/thga/gradleplugins/RunFregeTaskFunctionalTest.java
@@ -0,0 +1,185 @@
+package ch.fhnw.thga.gradleplugins;
+
+import static ch.fhnw.thga.gradleplugins.FregeExtension.DEFAULT_RELATIVE_SOURCE_DIR;
+import static ch.fhnw.thga.gradleplugins.FregePlugin.RUN_FREGE_TASK_NAME;
+import static ch.fhnw.thga.gradleplugins.SharedFunctionalTestLogic.NEW_LINE;
+import static ch.fhnw.thga.gradleplugins.SharedFunctionalTestLogic.createFregeSection;
+import static ch.fhnw.thga.gradleplugins.SharedFunctionalTestLogic.runAndFailGradleTask;
+import static ch.fhnw.thga.gradleplugins.SharedFunctionalTestLogic.runGradleTask;
+import static org.gradle.testkit.runner.TaskOutcome.FAILED;
+import static org.gradle.testkit.runner.TaskOutcome.SUCCESS;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.File;
+import java.util.stream.Stream;
+
+import org.gradle.api.Project;
+import org.gradle.testkit.runner.BuildResult;
+import org.junit.jupiter.api.DisplayNameGenerator;
+import org.junit.jupiter.api.IndicativeSentencesGeneration;
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import ch.fhnw.thga.gradleplugins.fregeproject.FregeProjectBuilder;
+import ch.fhnw.thga.gradleplugins.fregeproject.FregeSourceFile;
+
+public class RunFregeTaskFunctionalTest
+{
+ private static final FregeSourceFile MAIN_FR = new FregeSourceFile(
+ String.format(
+ "%s/%s",
+ DEFAULT_RELATIVE_SOURCE_DIR,
+ "ch/fhnw/thga/Main.fr"
+ ),
+ String.join(
+ NEW_LINE,
+ "module ch.fhnw.thga.Main where",
+ NEW_LINE,
+ NEW_LINE,
+ " main = do",
+ NEW_LINE,
+ " println \"Frege rocks\"",
+ NEW_LINE
+ )
+ );
+ @Nested
+ @IndicativeSentencesGeneration(
+ separator = " -> ",
+ generator = DisplayNameGenerator.ReplaceUnderscores.class
+ )
+ class Run_frege_task_works
+ {
+ @Test
+ void given_frege_file_with_main_function_and_main_module_config(
+ @TempDir File testProjectDir)
+ throws Exception
+ {
+ String mainBuildConfig = createFregeSection(
+ FregeDTOBuilder
+ .builder()
+ .version("'3.25.84'")
+ .release("'3.25alpha'")
+ .mainModule("'ch.fhnw.thga.Main'")
+ .build()
+ );
+ Project project = FregeProjectBuilder
+ .builder()
+ .projectRoot(testProjectDir)
+ .buildFile(mainBuildConfig)
+ .fregeSourceFiles(() -> Stream.of(MAIN_FR))
+ .build();
+
+ BuildResult result = runGradleTask(testProjectDir, RUN_FREGE_TASK_NAME);
+
+ assertTrue(
+ project
+ .getTasks()
+ .getByName(RUN_FREGE_TASK_NAME)
+ instanceof RunFregeTask
+ );
+ assertEquals(
+ SUCCESS,
+ result.task(":" + RUN_FREGE_TASK_NAME).getOutcome()
+ );
+ assertTrue(result.getOutput().contains("Frege rocks"));
+ }
+
+ @Test
+ void given_frege_file_with_main_function_and_main_module_command_line_option(
+ @TempDir File testProjectDir)
+ throws Exception
+ {
+ String mainBuildConfig = createFregeSection(
+ FregeDTOBuilder
+ .builder()
+ .version("'3.25.84'")
+ .release("'3.25alpha'")
+ .build()
+ );
+ Project project = FregeProjectBuilder
+ .builder()
+ .projectRoot(testProjectDir)
+ .buildFile(mainBuildConfig)
+ .fregeSourceFiles(() -> Stream.of(MAIN_FR))
+ .build();
+
+ BuildResult result = runGradleTask(
+ testProjectDir,
+ RUN_FREGE_TASK_NAME,
+ "--mainModule=ch.fhnw.thga.Main");
+
+ assertTrue(
+ project
+ .getTasks()
+ .getByName(RUN_FREGE_TASK_NAME)
+ instanceof RunFregeTask
+ );
+ assertEquals(
+ SUCCESS,
+ result.task(":" + RUN_FREGE_TASK_NAME).getOutcome()
+ );
+ assertTrue(result.getOutput().contains("Frege rocks"));
+ }
+ }
+ @Nested
+ @IndicativeSentencesGeneration(
+ separator = " -> ",
+ generator = DisplayNameGenerator.ReplaceUnderscores.class
+ )
+ class Run_frege_task_fails
+ {
+ @Test
+ void given_frege_file_without_main_function(
+ @TempDir File testProjectDir)
+ throws Exception
+ {
+ String mainBuildConfig = createFregeSection(
+ FregeDTOBuilder
+ .builder()
+ .version("'3.25.84'")
+ .release("'3.25alpha'")
+ .mainModule("'ch.fhnw.thga.Main'")
+ .build()
+ );
+ Project project = FregeProjectBuilder
+ .builder()
+ .projectRoot(testProjectDir)
+ .buildFile(mainBuildConfig)
+ .fregeSourceFiles(() -> Stream.of(new FregeSourceFile(
+ String.format(
+ "%s/%s",
+ DEFAULT_RELATIVE_SOURCE_DIR,
+ "ch/fhnw/thga/Main.fr"
+ ),
+ String.join(
+ NEW_LINE,
+ "module ch.fhnw.thga.Main where",
+ NEW_LINE,
+ NEW_LINE,
+ " add a b = a + b",
+ NEW_LINE
+ )
+ )))
+ .build();
+
+ BuildResult result = runAndFailGradleTask(
+ testProjectDir,
+ RUN_FREGE_TASK_NAME
+ );
+
+ assertTrue(
+ project
+ .getTasks()
+ .getByName(RUN_FREGE_TASK_NAME)
+ instanceof RunFregeTask
+ );
+ assertEquals(
+ FAILED,
+ result.task(":" + RUN_FREGE_TASK_NAME).getOutcome()
+ );
+ assertTrue(result.getOutput().contains("Main method not found"));
+ }
+ }
+}
diff --git a/src/functionalTest/java/ch/fhnw/thga/gradleplugins/SetupFregeTaskFunctionalTest.java b/src/functionalTest/java/ch/fhnw/thga/gradleplugins/SetupFregeTaskFunctionalTest.java
index 825c555..6781764 100644
--- a/src/functionalTest/java/ch/fhnw/thga/gradleplugins/SetupFregeTaskFunctionalTest.java
+++ b/src/functionalTest/java/ch/fhnw/thga/gradleplugins/SetupFregeTaskFunctionalTest.java
@@ -17,11 +17,13 @@ import org.junit.jupiter.api.DisplayNameGenerator;
import org.junit.jupiter.api.IndicativeSentencesGeneration;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.io.TempDir;
import ch.fhnw.thga.gradleplugins.fregeproject.FregeProjectBuilder;
import ch.fhnw.thga.gradleplugins.fregeproject.ProjectRoot;
+@Tag("network")
class SetupFregeTaskFunctionalTest
{
private static FregeDTOBuilder FREGE_BUILDER = FregeDTOBuilder.builder();
diff --git a/src/functionalTest/java/ch/fhnw/thga/gradleplugins/SharedFunctionalTestLogic.java b/src/functionalTest/java/ch/fhnw/thga/gradleplugins/SharedFunctionalTestLogic.java
index 3b4ee49..c98d7ac 100644
--- a/src/functionalTest/java/ch/fhnw/thga/gradleplugins/SharedFunctionalTestLogic.java
+++ b/src/functionalTest/java/ch/fhnw/thga/gradleplugins/SharedFunctionalTestLogic.java
@@ -17,8 +17,8 @@ import org.gradle.testkit.runner.GradleRunner;
public class SharedFunctionalTestLogic
{
-
- static String createFregeSection(FregeDTO fregeDTO)
+ public static final String NEW_LINE = System.lineSeparator();
+ static String createFregeSection(FregeDTO fregeDTO)
{
return String.format(
"%s {%s %s%s}",
diff --git a/src/functionalTest/java/ch/fhnw/thga/gradleplugins/fregeproject/FregeSourceFile.java b/src/functionalTest/java/ch/fhnw/thga/gradleplugins/fregeproject/FregeSourceFile.java
index d45e158..c161dbd 100644
--- a/src/functionalTest/java/ch/fhnw/thga/gradleplugins/fregeproject/FregeSourceFile.java
+++ b/src/functionalTest/java/ch/fhnw/thga/gradleplugins/fregeproject/FregeSourceFile.java
@@ -1,7 +1,5 @@
package ch.fhnw.thga.gradleplugins.fregeproject;
-import java.nio.file.Path;
-
public class FregeSourceFile
{
private final String modulePath;