aboutsummaryrefslogtreecommitdiff
path: root/src/functionalTest/java/ch/fhnw/thga/gradleplugins/InitFregeTaskFunctionalTest.java
blob: cd1f4abe28279b969662f04877d778e68df6a44a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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.FregePlugin.INIT_FREGE_TASK_NAME;
import static ch.fhnw.thga.gradleplugins.SharedFunctionalTestLogic.MINIMAL_BUILD_FILE_CONFIG;
import static ch.fhnw.thga.gradleplugins.SharedFunctionalTestLogic.assertFileExists;
import static ch.fhnw.thga.gradleplugins.SharedFunctionalTestLogic.runGradleTask;
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 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.ProjectRoot;

public class InitFregeTaskFunctionalTest
{
    private static ProjectRoot FREGE_PROJECT_BUILDER = FregeProjectBuilder.builder();

    @Nested
    @IndicativeSentencesGeneration(
        separator = " -> ",
        generator = DisplayNameGenerator.ReplaceUnderscores.class)
    class Init_frege_task_works {
        @Test
        void given_minimal_build_file_config(
            @TempDir File testProjectDir)
            throws Exception
        {
            Project project = FREGE_PROJECT_BUILDER
                .projectRoot(testProjectDir)
                .buildFile(MINIMAL_BUILD_FILE_CONFIG)
                .build();

            BuildResult result = runGradleTask(testProjectDir, INIT_FREGE_TASK_NAME);
    
            assertTrue(
                project
                .getTasks()
                .getByName(INIT_FREGE_TASK_NAME) instanceof InitFregeTask
            );
            assertEquals(
                SUCCESS,
                result.task(":" + INIT_FREGE_TASK_NAME).getOutcome()
            );
            assertFileExists(
                testProjectDir.toPath().resolve(DEFAULT_RELATIVE_SOURCE_DIR).toFile(),
                "examples/HelloFrege.fr"
            );

            BuildResult compileHelloFrege = runGradleTask(testProjectDir, COMPILE_FREGE_TASK_NAME);
            assertEquals(SUCCESS, compileHelloFrege.task(":" + COMPILE_FREGE_TASK_NAME).getOutcome());
        }

        @Test
        void given_custom_module_name_on_command_line(
            @TempDir File testProjectDir)
            throws Exception
        {
            Project project = FREGE_PROJECT_BUILDER
                .projectRoot(testProjectDir)
                .buildFile(MINIMAL_BUILD_FILE_CONFIG)
                .build();

            BuildResult result = runGradleTask(
                testProjectDir,
                INIT_FREGE_TASK_NAME,
                "--moduleName=ch.fhnw.thga.HelloFrege"
            );
    
            assertTrue(
                project
                .getTasks()
                .getByName(INIT_FREGE_TASK_NAME) instanceof InitFregeTask
            );
            assertEquals(
                SUCCESS,
                result.task(":" + INIT_FREGE_TASK_NAME).getOutcome()
            );
            assertFileExists(
                testProjectDir.toPath().resolve(DEFAULT_RELATIVE_SOURCE_DIR).toFile(),
                "ch/fhnw/thga/HelloFrege.fr"
            );
        }
    }
}