diff options
Diffstat (limited to 'src/functionalTest/java')
4 files changed, 319 insertions, 346 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() ); } - } + } } 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 diff --git a/src/functionalTest/java/ch/fhnw/thga/gradleplugins/SharedFunctionalTestLogic.java b/src/functionalTest/java/ch/fhnw/thga/gradleplugins/SharedFunctionalTestLogic.java index a0d46a4..3b4ee49 100644 --- a/src/functionalTest/java/ch/fhnw/thga/gradleplugins/SharedFunctionalTestLogic.java +++ b/src/functionalTest/java/ch/fhnw/thga/gradleplugins/SharedFunctionalTestLogic.java @@ -53,15 +53,25 @@ public class SharedFunctionalTestLogic return destination; } - static BuildResult runGradleTask(File testProjectDir, String... taskName) + static BuildResult runGradleTask(File testProjectDir, String... args) { return GradleRunner .create() .withProjectDir(testProjectDir) .withPluginClasspath() - .withArguments(taskName) + .withArguments(args) .build(); } + + static BuildResult runAndFailGradleTask(File testProjectDir, String... args) + { + return GradleRunner + .create() + .withProjectDir(testProjectDir) + .withPluginClasspath() + .withArguments(args) + .buildAndFail(); + } static File createSettingsFile(File testProjectDir) throws IOException { diff --git a/src/functionalTest/java/ch/fhnw/thga/gradleplugins/fregeproject/FregeProjectBuilder.java b/src/functionalTest/java/ch/fhnw/thga/gradleplugins/fregeproject/FregeProjectBuilder.java index bb87cdc..d2c6aeb 100644 --- a/src/functionalTest/java/ch/fhnw/thga/gradleplugins/fregeproject/FregeProjectBuilder.java +++ b/src/functionalTest/java/ch/fhnw/thga/gradleplugins/fregeproject/FregeProjectBuilder.java @@ -4,9 +4,11 @@ import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.nio.file.CopyOption; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; import java.util.List; import java.util.function.Supplier; import java.util.stream.Stream; @@ -98,8 +100,9 @@ public final class FregeProjectBuilder implements ProjectRoot, BuildFile, Build projectRoot .toPath() .resolve(DEFAULT_RELATIVE_COMPILER_DOWNLOAD_DIR) - .resolve(LOCAL_COMPILER_PATH.getFileName()) - ).toFile(); + .resolve(LOCAL_COMPILER_PATH.getFileName()), + StandardCopyOption.REPLACE_EXISTING) + .toFile(); } private FregeProjectBuilder() {} @@ -162,7 +165,7 @@ public final class FregeProjectBuilder implements ProjectRoot, BuildFile, Build createGradleFile("settings.gradle", settingsFile); createGradleFile("build.gradle", buildFile); if (useLocalFregeCompiler) setupLocalFregeCompilerInDefaultPath(); - fregeSourceFiles.get().map(this::writeToFile).findFirst(); + fregeSourceFiles.get().map(this::writeToFile).toArray(); Project project = ProjectBuilder .builder() .withProjectDir(projectRoot) |