diff options
author | Thibault Gagnaux <tgagnaux@gmail.com> | 2022-02-11 13:58:28 +0100 |
---|---|---|
committer | Thibault Gagnaux <tgagnaux@gmail.com> | 2022-02-11 13:58:28 +0100 |
commit | 7ef464ab2c2a6a2e0b9ee857d6979ab98f1ec930 (patch) | |
tree | 923b369a85f6c47f8ceee01ddebcd1b8606abb05 /src/functionalTest/java/ch/fhnw/thga/gradleplugins/FregePluginFunctionalTest.java | |
parent | 0aa4dd065ee78f9acc88b39625cc4a9b47f6c944 (diff) | |
download | frege-gradle-plugin-7ef464ab2c2a6a2e0b9ee857d6979ab98f1ec930.tar.gz frege-gradle-plugin-7ef464ab2c2a6a2e0b9ee857d6979ab98f1ec930.tar.bz2 frege-gradle-plugin-7ef464ab2c2a6a2e0b9ee857d6979ab98f1ec930.zip |
refactor: finishes the compileFregeTask refactoring
Diffstat (limited to 'src/functionalTest/java/ch/fhnw/thga/gradleplugins/FregePluginFunctionalTest.java')
-rw-r--r-- | src/functionalTest/java/ch/fhnw/thga/gradleplugins/FregePluginFunctionalTest.java | 298 |
1 files changed, 3 insertions, 295 deletions
diff --git a/src/functionalTest/java/ch/fhnw/thga/gradleplugins/FregePluginFunctionalTest.java b/src/functionalTest/java/ch/fhnw/thga/gradleplugins/FregePluginFunctionalTest.java index 9cd24c4..5159c92 100644 --- a/src/functionalTest/java/ch/fhnw/thga/gradleplugins/FregePluginFunctionalTest.java +++ b/src/functionalTest/java/ch/fhnw/thga/gradleplugins/FregePluginFunctionalTest.java @@ -43,299 +43,7 @@ import org.junit.jupiter.api.io.TempDir; public class FregePluginFunctionalTest { - private static final String NEW_LINE = System.lineSeparator(); - private static FregeDTOBuilder FREGE_BUILDER = FregeDTOBuilder.builder(); - private static final String FREGE_COMPLETION_MODULE_CODE = - String.join - ( - NEW_LINE, - "module ch.fhnw.thga.Completion where", - NEW_LINE, - NEW_LINE, - " complete :: Int -> (Int, String)", - NEW_LINE, - " complete i = (i, \"Frege rocks\")", - NEW_LINE - ); - - - - /*private BuildResult runAndFailGradleTask(String taskName, String... args) { - return GradleRunner.create().withProjectDir(testProjectDir).withPluginClasspath() - .withArguments(taskName) - .buildAndFail(); - }*/ - - static File createFregeSourceFile( - Path fregeFilePath, - String fregeSourceCode) - throws IOException - { - Files.createDirectories( - fregeFilePath - .getParent() - ); - File fregeFile = fregeFilePath.toFile(); - writeToFile(fregeFile, fregeSourceCode); - return fregeFile; - } - - static File setupLocalFregeCompiler(File testProjectDir) throws IOException - { - Path fregeCompiler = Paths.get("src/functionalTest/resources/frege3.25.84.jar"); - Files.createDirectories(testProjectDir.toPath().resolve("lib")); - return Files.copy( - fregeCompiler, - testProjectDir.toPath().resolve("lib/frege3.25.84.jar") - ).toFile(); - } - - @Nested - @IndicativeSentencesGeneration( - separator = " -> ", - generator = DisplayNameGenerator.ReplaceUnderscores.class - ) - class Compile_frege_task_works { - - /*@Test - void given_frege_code_in_default_source_dir_and_minimal_build_file_config( - @TempDir File testProjectDir) - throws Exception - { - String minimalBuildFileConfig = createFregeSection( - FREGE_BUILDER.version("'3.25.84'").release("'3.25alpha'").build() - ); - Project project = createFregeGradleProject( - testProjectDir, - minimalBuildFileConfig - ); - Path completionFr = - testProjectDir - .toPath() - .resolve(Paths.get(DEFAULT_RELATIVE_SOURCE_DIR, "ch/fhnw/thga/Completion.fr") - ); - createFregeSourceFile(completionFr, FREGE_COMPLETION_MODULE_CODE); - setupLocalFregeCompiler(testProjectDir); - - BuildResult result = runGradleTask(testProjectDir, COMPILE_FREGE_TASK_NAME); - - assertTrue( - project - .getTasks() - .getByName(COMPILE_FREGE_TASK_NAME) - instanceof CompileFregeTask - ); - assertEquals( - 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()); - } - - @Test - void given_frege_code_and_many_compiler_flags( - @TempDir File testProjectDir - ) throws Exception - { - String buildConfigWithCompilerFlags = createFregeSection( - FREGE_BUILDER - .version("'3.25.84'") - .release("'3.25alpha'") - .compilerFlags("['-v', '-make', '-O', '-hints']") - .build() - ); - Project project = createFregeGradleProject( - testProjectDir, - buildConfigWithCompilerFlags - ); - Path completionFr = - testProjectDir - .toPath() - .resolve(Paths.get(DEFAULT_RELATIVE_SOURCE_DIR, "ch/fhnw/thga/Completion.fr") - ); - createFregeSourceFile(completionFr, FREGE_COMPLETION_MODULE_CODE); - setupLocalFregeCompiler(testProjectDir); - - BuildResult result = runGradleTask(testProjectDir, COMPILE_FREGE_TASK_NAME); - - assertTrue( - project - .getTasks() - .getByName(COMPILE_FREGE_TASK_NAME) - instanceof CompileFregeTask - ); - assertEquals( - 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()); - } - - @Test - void given_frege_code_in_custom_source_dir_and_custom_output_dir_and_minimal_build_file_config() - throws Exception { - Path customMainSourceDir = testProjectDir.toPath().resolve(Paths.get("src", "frege")); - Files.createDirectories(customMainSourceDir); - File completionFr = customMainSourceDir.resolve("Completion.fr").toFile(); - writeToFile(completionFr, FREGE_COMPLETION_MODULE_CODE); - String minimalBuildFileConfig = createFregeSection( - FREGE_BUILDER.version("'3.25.84'").release("'3.25alpha'") - .mainSourceDir("layout.projectDirectory.dir('src/frege')") - .outputDir("layout.buildDirectory.dir('frege')").build()); - appendToFile(buildFile, minimalBuildFileConfig); - System.out.println(Files.readString(buildFile.toPath())); - - BuildResult result = runGradleTask(COMPILE_FREGE_TASK_NAME); - - assertTrue(project.getTasks().getByName(COMPILE_FREGE_TASK_NAME) instanceof CompileFregeTask); - assertEquals(SUCCESS, result.task(":" + COMPILE_FREGE_TASK_NAME).getOutcome()); - assertTrue( - new File(testProjectDir.getAbsolutePath() - + "/build/frege/ch/fhnw/thga/Completion.java").exists()); - assertTrue( - new File(testProjectDir.getAbsolutePath() - + "/build/frege/ch/fhnw/thga/Completion.class").exists()); - } - - @Test - void and_is_up_to_date_given_no_code_changes() throws Exception { - String completionFr = "Completion.fr"; - String minimalBuildFileConfig = createFregeSection( - FREGE_BUILDER.version("'3.25.84'").release("'3.25alpha'").build()); - setupDefaultFregeProjectStructure(FREGE_COMPLETION_MODULE_CODE, completionFr, minimalBuildFileConfig); - - System.out.println(Files.readString(buildFile.toPath())); - BuildResult first = runGradleTask(COMPILE_FREGE_TASK_NAME); - assertEquals(SUCCESS, first.task(":" + COMPILE_FREGE_TASK_NAME).getOutcome()); - - BuildResult second = runGradleTask(COMPILE_FREGE_TASK_NAME); - assertEquals(UP_TO_DATE, second.task(":" + COMPILE_FREGE_TASK_NAME).getOutcome()); - } - - @Test - void and_is_cached_given_cache_hit() throws Exception { - String completionFr = "Completion.fr"; - String minimalBuildFileConfig = createFregeSection( - FREGE_BUILDER.version("'3.25.84'").release("'3.25alpha'").build()); - setupDefaultFregeProjectStructure(FREGE_COMPLETION_MODULE_CODE, completionFr, minimalBuildFileConfig); - - BuildResult first = runGradleTask(COMPILE_FREGE_TASK_NAME, "--build-cache"); - 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); - setupDefaultFregeProjectStructure(codeChange, completionFr, ""); - - System.out.println(Files.readString(buildFile.toPath())); - BuildResult second = runGradleTask(COMPILE_FREGE_TASK_NAME, "--build-cache"); - assertEquals(SUCCESS, second.task(":" + COMPILE_FREGE_TASK_NAME).getOutcome()); - - setupDefaultFregeProjectStructure(FREGE_COMPLETION_MODULE_CODE, completionFr, ""); - BuildResult third = runGradleTask(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() - throws Exception { - String completionFr = "Completion.fr"; - String frobFr = "Frob.fr"; - 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 minimalBuildFileConfig = createFregeSection( - FREGE_BUILDER.version("'3.25.84'").release("'3.25alpha'").build()); - setupDefaultFregeProjectStructure(FREGE_COMPLETION_MODULE_CODE, completionFr, minimalBuildFileConfig); - setupDefaultFregeProjectStructure(frobCode, frobFr, ""); - - System.out.println(Files.readString(buildFile.toPath())); - BuildResult result = runGradleTask(COMPILE_FREGE_TASK_NAME); - - assertTrue(project.getTasks().getByName(COMPILE_FREGE_TASK_NAME) instanceof CompileFregeTask); - assertEquals(SUCCESS, result.task(":" + COMPILE_FREGE_TASK_NAME).getOutcome()); - assertTrue(new File( - testProjectDir.getAbsolutePath() - + "/build/classes/main/frege/ch/fhnw/thga/Completion.java") - .exists()); - assertTrue(new File( - testProjectDir.getAbsolutePath() - + "/build/classes/main/frege/ch/fhnw/thga/Completion.class") - .exists()); - assertTrue(new File(testProjectDir.getAbsolutePath() - + "/build/classes/main/frege/ch/fhnw/thga/Frob.java") - .exists()); - assertTrue(new File(testProjectDir.getAbsolutePath() - + "/build/classes/main/frege/ch/fhnw/thga/Frob.class") - .exists()); - } - } - - @Nested - @IndicativeSentencesGeneration(separator = " -> ", generator = DisplayNameGenerator.ReplaceUnderscores.class) - class Compile_frege_task_fails { - @Test - void given_frege_code_and_illegal_compiler_flags() throws Exception { - String completionFr = "Completion.fr"; - String buildConfigWithIllegalCompilerFlags = createFregeSection(FREGE_BUILDER - .version("'3.25.84'") - .release("'3.25alpha'").compilerFlags("['-make', '-bla']").build()); - setupDefaultFregeProjectStructure(FREGE_COMPLETION_MODULE_CODE, completionFr, - buildConfigWithIllegalCompilerFlags); - - BuildResult result = runAndFailGradleTask(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() - throws Exception { - String completionFr = "Completion.fr"; - String frobFr = "Frob.fr"; - 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( - FREGE_BUILDER.version("'3.25.84'").release("'3.25alpha'").compilerFlags("['-v']") - .build()); - setupDefaultFregeProjectStructure(FREGE_COMPLETION_MODULE_CODE, completionFr, - minimalBuildFileConfigWithoutMake); - setupDefaultFregeProjectStructure(frobCode, frobFr, ""); - - System.out.println("Build File: " + Files.readString(buildFile.toPath())); - - BuildResult result = runAndFailGradleTask(COMPILE_FREGE_TASK_NAME); - - - assertTrue(project.getTasks().getByName(COMPILE_FREGE_TASK_NAME) instanceof CompileFregeTask); - assertEquals(FAILED, result.task(":" + COMPILE_FREGE_TASK_NAME).getOutcome()); - } - } - - @Nested + /*@Nested @IndicativeSentencesGeneration(separator = " -> ", generator = DisplayNameGenerator.ReplaceUnderscores.class) class Run_frege_task_works { @Test @@ -444,6 +152,6 @@ public class FregePluginFunctionalTest project.getTasks().getByName(REPL_FREGE_TASK_NAME) instanceof ReplFregeTask); assertEquals(FAILED, result.task(":" + COMPILE_FREGE_TASK_NAME).getOutcome()); - }*/ - } + } + }*/ }
\ No newline at end of file |