aboutsummaryrefslogtreecommitdiff
path: root/src/functionalTest/java/ch/fhnw/thga/gradleplugins/CompileFregeTaskFunctionalTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/functionalTest/java/ch/fhnw/thga/gradleplugins/CompileFregeTaskFunctionalTest.java')
-rw-r--r--src/functionalTest/java/ch/fhnw/thga/gradleplugins/CompileFregeTaskFunctionalTest.java344
1 files changed, 298 insertions, 46 deletions
diff --git a/src/functionalTest/java/ch/fhnw/thga/gradleplugins/CompileFregeTaskFunctionalTest.java b/src/functionalTest/java/ch/fhnw/thga/gradleplugins/CompileFregeTaskFunctionalTest.java
index a0512c0..42a3de2 100644
--- a/src/functionalTest/java/ch/fhnw/thga/gradleplugins/CompileFregeTaskFunctionalTest.java
+++ b/src/functionalTest/java/ch/fhnw/thga/gradleplugins/CompileFregeTaskFunctionalTest.java
@@ -1,9 +1,14 @@
package ch.fhnw.thga.gradleplugins;
+import static ch.fhnw.thga.gradleplugins.FregeExtension.DEFAULT_RELATIVE_SOURCE_DIR;
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 org.gradle.testkit.runner.TaskOutcome.FAILED;
+import static org.gradle.testkit.runner.TaskOutcome.FROM_CACHE;
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS;
+import static org.gradle.testkit.runner.TaskOutcome.UP_TO_DATE;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -15,19 +20,19 @@ 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.Tag;
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;
-import ch.fhnw.thga.gradleplugins.fregeproject.ProjectRoot;
public class CompileFregeTaskFunctionalTest
{
private static final String NEW_LINE = System.lineSeparator();
private static final FregeSourceFile COMPLETION_FR = new FregeSourceFile(
- "src/main/frege/ch/fhnw/thga/Completion.fr",
+ String.format("%s/%s",
+ DEFAULT_RELATIVE_SOURCE_DIR,
+ "ch/fhnw/thga/Completion.fr"),
String.join
(
NEW_LINE,
@@ -40,6 +45,25 @@ public class CompileFregeTaskFunctionalTest
NEW_LINE
)
);
+ private static final String MINIMAL_BUILD_FILE_CONFIG = createFregeSection(
+ FregeDTOBuilder
+ .builder()
+ .version("'3.25.84'")
+ .release("'3.25alpha'")
+ .build()
+ );
+
+ private static final boolean assertFileExists(
+ File testProjectDir,
+ String relativeFilePath)
+ {
+ return testProjectDir
+ .toPath()
+ .resolve(relativeFilePath)
+ .toFile()
+ .exists();
+ }
+
@Nested
@IndicativeSentencesGeneration(
separator = " -> ",
@@ -52,18 +76,10 @@ public class CompileFregeTaskFunctionalTest
@TempDir File testProjectDir)
throws Exception
{
- String minimalBuildFileConfig = createFregeSection(
- FregeDTOBuilder
- .builder()
- .version("'3.25.84'")
- .release("'3.25alpha'")
- .build()
- );
-
Project project = FregeProjectBuilder
.builder()
.projectRoot(testProjectDir)
- .buildFile(minimalBuildFileConfig)
+ .buildFile(MINIMAL_BUILD_FILE_CONFIG)
.fregeSourceFiles(() -> Stream.of(COMPLETION_FR))
.build();
@@ -79,16 +95,14 @@ public class CompileFregeTaskFunctionalTest
SUCCESS,
result.task(":" + COMPILE_FREGE_TASK_NAME).getOutcome()
);
- assertTrue(testProjectDir
- .toPath()
- .resolve("build/classes/main/frege/ch/fhnw/thga/Completion.java")
- .toFile()
- .exists());
- assertTrue(testProjectDir
- .toPath()
- .resolve("build/classes/main/frege/ch/fhnw/thga/Completion.class")
- .toFile()
- .exists());
+ assertFileExists(
+ testProjectDir,
+ "build/classes/main/frege/ch/fhnw/thga/Completion.java"
+ );
+ assertFileExists(
+ testProjectDir,
+ "build/classes/main/frege/ch/fhnw/thga/Completion.class"
+ );
}
@Test
void given_frege_code_and_many_compiler_flags(
@@ -122,23 +136,18 @@ public class CompileFregeTaskFunctionalTest
SUCCESS,
result.task(":" + COMPILE_FREGE_TASK_NAME).getOutcome()
);
- assertTrue(testProjectDir
- .toPath()
- .resolve("build/classes/main/frege/ch/fhnw/thga/Completion.java")
- .toFile()
- .exists()
+ assertFileExists(
+ testProjectDir,
+ "build/classes/main/frege/ch/fhnw/thga/Completion.java"
);
- assertTrue(testProjectDir
- .toPath()
- .resolve("build/classes/main/frege/ch/fhnw/thga/Completion.class")
- .toFile()
- .exists()
+ assertFileExists(
+ testProjectDir,
+ "build/classes/main/frege/ch/fhnw/thga/Completion.class"
);
}
@Test
void given_frege_code_in_custom_source_and_output_dir_and_minimal_build_file_config(
- @TempDir File testProjectDir
- )
+ @TempDir File testProjectDir)
throws Exception
{
String customSourceAndOutputBuildFileConfig = createFregeSection(
@@ -160,7 +169,6 @@ public class CompileFregeTaskFunctionalTest
.build();
BuildResult result = runGradleTask(testProjectDir, COMPILE_FREGE_TASK_NAME);
- System.out.println(result.getOutput());
assertTrue(
project
.getTasks()
@@ -171,18 +179,262 @@ public class CompileFregeTaskFunctionalTest
SUCCESS,
result.task(":" + COMPILE_FREGE_TASK_NAME).getOutcome()
);
- assertTrue(testProjectDir
- .toPath()
- .resolve("build/frege/ch/fhnw/thga/Completion.java")
- .toFile()
- .exists()
+ assertFileExists(
+ testProjectDir,
+ "build/classes/main/frege/ch/fhnw/thga/Completion.java"
+ );
+ assertFileExists(
+ testProjectDir,
+ "build/classes/main/frege/ch/fhnw/thga/Completion.class"
+ );
+ }
+ @Test
+ void and_is_up_to_date_given_no_code_changes(
+ @TempDir File testProjectDir)
+ throws Exception
+ {
+ FregeProjectBuilder
+ .builder()
+ .projectRoot(testProjectDir)
+ .buildFile(MINIMAL_BUILD_FILE_CONFIG)
+ .fregeSourceFiles(() -> Stream.of(COMPLETION_FR))
+ .build();
+
+ BuildResult first = runGradleTask(testProjectDir, COMPILE_FREGE_TASK_NAME);
+
+ assertEquals(
+ SUCCESS,
+ first.task(":" + COMPILE_FREGE_TASK_NAME).getOutcome());
+
+ BuildResult second = runGradleTask(testProjectDir, COMPILE_FREGE_TASK_NAME);
+
+ assertEquals(
+ UP_TO_DATE,
+ second.task(":" + COMPILE_FREGE_TASK_NAME).getOutcome());
+ }
+ @Test
+ void and_is_cached_given_cache_hit(
+ @TempDir File testProjectDir)
+ throws Exception
+ {
+ FregeProjectBuilder
+ .builder()
+ .projectRoot(testProjectDir)
+ .buildFile(MINIMAL_BUILD_FILE_CONFIG)
+ .fregeSourceFiles(() -> Stream.of(COMPLETION_FR))
+ .build();
+
+ BuildResult first = runGradleTask(
+ testProjectDir,
+ COMPILE_FREGE_TASK_NAME,
+ "--build-cache"
);
- assertTrue(testProjectDir
- .toPath()
- .resolve("build/frege/ch/fhnw/thga/Completion.class")
- .toFile()
- .exists()
+
+ assertEquals(
+ SUCCESS,
+ first.task(":" + COMPILE_FREGE_TASK_NAME).getOutcome()
+ );
+
+ String codeChange = String.join(
+ NEW_LINE,
+ "module ch.fhnw.thga.Completion where",
+ NEW_LINE,
+ NEW_LINE,
+ " frob :: Int -> (Int, String)",
+ NEW_LINE,
+ " frob i = (i, \"Frege rocks\")",
+ NEW_LINE
+ );
+ FregeProjectBuilder
+ .builder()
+ .projectRoot(testProjectDir)
+ .buildFile(MINIMAL_BUILD_FILE_CONFIG)
+ .fregeSourceFiles(() -> Stream.of(new FregeSourceFile(
+ COMPLETION_FR.getFregeModulePath(),
+ codeChange)))
+ .build();
+
+ BuildResult second = runGradleTask(
+ testProjectDir,
+ COMPILE_FREGE_TASK_NAME,
+ "--build-cache"
+ );
+
+ assertEquals(
+ SUCCESS,
+ second.task(":" + COMPILE_FREGE_TASK_NAME).getOutcome()
+ );
+
+ FregeProjectBuilder
+ .builder()
+ .projectRoot(testProjectDir)
+ .buildFile(MINIMAL_BUILD_FILE_CONFIG)
+ .fregeSourceFiles(() -> Stream.of(COMPLETION_FR))
+ .build();
+ BuildResult third = runGradleTask(
+ testProjectDir,
+ COMPILE_FREGE_TASK_NAME,
+ "--build-cache"
+ );
+
+ assertEquals(
+ FROM_CACHE,
+ third.task(":" + COMPILE_FREGE_TASK_NAME).getOutcome());
+ }
+ @Test
+ void given_two_dependent_frege_files_in_default_source_dir_and_minimal_build_file_config(
+ @TempDir File testProjectDir)
+ throws Exception
+ {
+ String frobCode = String.join(
+ NEW_LINE,
+ "module ch.fhnw.thga.Frob where",
+ NEW_LINE,
+ NEW_LINE,
+ "import ch.fhnw.thga.Completion (complete)",
+ NEW_LINE,
+ "frob i = complete $ i + i",
+ NEW_LINE
+ );
+ Project project = FregeProjectBuilder
+ .builder()
+ .projectRoot(testProjectDir)
+ .buildFile(MINIMAL_BUILD_FILE_CONFIG)
+ .fregeSourceFiles(() -> Stream.of(COMPLETION_FR, new FregeSourceFile(
+ String.format(
+ "%s/%s",
+ DEFAULT_RELATIVE_SOURCE_DIR,
+ "ch/fhnw/thga/Frob.fr"
+ ),
+ frobCode)))
+ .build();
+
+ BuildResult result = runGradleTask(
+ testProjectDir,
+ COMPILE_FREGE_TASK_NAME,
+ "--compileItem=ch.fhnw.thga.Frob"
+ );
+
+ assertTrue(
+ project
+ .getTasks()
+ .getByName(COMPILE_FREGE_TASK_NAME)
+ instanceof CompileFregeTask
+ );
+ assertEquals(
+ SUCCESS,
+ result.task(":" + COMPILE_FREGE_TASK_NAME).getOutcome()
+ );
+ assertFileExists(
+ testProjectDir,
+ "build/classes/main/frege/ch/fhnw/thga/Completion.java"
+ );
+ assertFileExists(
+ testProjectDir,
+ "build/classes/main/frege/ch/fhnw/thga/Completion.class"
+ );
+ assertFileExists(
+ testProjectDir,
+ "build/classes/main/frege/ch/fhnw/thga/Frob.java"
+ );
+ assertFileExists(
+ testProjectDir,
+ "build/classes/main/frege/ch/fhnw/thga/Frob.class"
+ );
+ }
+ }
+ @Nested
+ @IndicativeSentencesGeneration(
+ separator = " -> ",
+ generator = DisplayNameGenerator.ReplaceUnderscores.class
+ )
+ class Compile_frege_task_fails
+ {
+ @Test
+ void given_frege_code_and_illegal_compiler_flags(
+ @TempDir File testProjectDir)
+ throws Exception
+ {
+ String buildConfigWithIllegalCompilerFlags = createFregeSection(
+ FregeDTOBuilder
+ .builder()
+ .version("'3.25.84'")
+ .release("'3.25alpha'")
+ .compilerFlags("['-make', '-bla']")
+ .build()
+ );
+ Project project = FregeProjectBuilder
+ .builder()
+ .projectRoot(testProjectDir)
+ .buildFile(buildConfigWithIllegalCompilerFlags)
+ .fregeSourceFiles(() -> Stream.of(COMPLETION_FR))
+ .build();
+
+ BuildResult result = runAndFailGradleTask(testProjectDir, COMPILE_FREGE_TASK_NAME);
+
+ assertTrue(
+ project
+ .getTasks()
+ .getByName(COMPILE_FREGE_TASK_NAME)
+ instanceof CompileFregeTask
+ );
+ assertEquals(
+ FAILED,
+ result.task(":" + COMPILE_FREGE_TASK_NAME).getOutcome()
+ );
+ }
+ @Test
+ void given_two_dependent_frege_files_in_default_source_dir_and_without_make_compiler_flag(
+ @TempDir File testProjectDir)
+ throws Exception
+ {
+ String frobCode = String.join(
+ NEW_LINE,
+ "module ch.fhnw.thga.Frob where",
+ NEW_LINE,
+ NEW_LINE,
+ "import ch.fhnw.thga.Completion (complete)",
+ NEW_LINE,
+ "frob i = complete $ i + i",
+ NEW_LINE
+ );
+ String minimalBuildFileConfigWithoutMake = createFregeSection(
+ FregeDTOBuilder
+ .builder()
+ .version("'3.25.84'")
+ .release("'3.25alpha'")
+ .compilerFlags("['-v']")
+ .build()
+ );
+ Project project = FregeProjectBuilder
+ .builder()
+ .projectRoot(testProjectDir)
+ .buildFile(minimalBuildFileConfigWithoutMake)
+ .fregeSourceFiles(() -> Stream.of(COMPLETION_FR, new FregeSourceFile(
+ String.format(
+ "%s/%s",
+ DEFAULT_RELATIVE_SOURCE_DIR,
+ "ch/fhnw/thga/Frob.fr"
+ ),
+ frobCode)))
+ .build();
+
+ BuildResult result = runAndFailGradleTask(
+ testProjectDir,
+ COMPILE_FREGE_TASK_NAME,
+ "--compileItem=ch.fhnw.thga.Frob"
+ );
+
+ assertTrue(
+ project
+ .getTasks()
+ .getByName(COMPILE_FREGE_TASK_NAME)
+ instanceof CompileFregeTask
+ );
+ assertEquals(
+ FAILED,
+ result.task(":" + COMPILE_FREGE_TASK_NAME).getOutcome()
);
}
- }
+ }
}