|
18 | 18 | import static io.github.ascopes.jct.assertions.JctAssertions.assertThatCompilation;
|
19 | 19 | import static io.github.ascopes.jct.assertions.JctAssertions.assertThatContainerGroup;
|
20 | 20 |
|
| 21 | +import io.github.ascopes.jct.compilers.JctCompilation; |
21 | 22 | import io.github.ascopes.jct.compilers.JctCompiler;
|
22 | 23 | import io.github.ascopes.jct.junit.EcjCompilerTest;
|
23 | 24 | import io.github.ascopes.jct.junit.JavacCompilerTest;
|
24 | 25 | import io.github.ascopes.jct.tests.integration.AbstractIntegrationTest;
|
| 26 | +import io.github.ascopes.jct.tests.integration.IntegrationTestConfigurer; |
25 | 27 | import io.github.ascopes.jct.workspaces.PathStrategy;
|
| 28 | +import io.github.ascopes.jct.workspaces.Workspace; |
26 | 29 | import io.github.ascopes.jct.workspaces.Workspaces;
|
27 | 30 | import org.junit.jupiter.api.DisplayName;
|
28 | 31 |
|
|
35 | 38 | class BasicModuleCompilationIntegrationTest extends AbstractIntegrationTest {
|
36 | 39 |
|
37 | 40 | @DisplayName("I can compile a 'Hello, World!' module program using a RAM disk on Javac")
|
38 |
| - @JavacCompilerTest(minVersion = 9) |
| 41 | + @JavacCompilerTest(minVersion = 9, configurers = IntegrationTestConfigurer.class) |
39 | 42 | void helloWorldRamDiskJavac(JctCompiler<?, ?> compiler) {
|
40 | 43 | try (var workspace = Workspaces.newWorkspace(PathStrategy.RAM_DIRECTORIES)) {
|
41 |
| - // Given |
42 |
| - workspace |
43 |
| - .createSourcePathPackage() |
44 |
| - .copyContentsFrom(resourcesDirectory()); |
45 |
| - |
46 |
| - // When |
47 |
| - var compilation = compiler.compile(workspace); |
48 |
| - |
49 |
| - // Then |
50 |
| - assertThatCompilation(compilation) |
51 |
| - .isSuccessfulWithoutWarnings(); |
52 |
| - |
53 |
| - assertThatCompilation(compilation) |
54 |
| - .classOutput() |
55 |
| - .packages() |
56 |
| - .fileExists("com", "example", "HelloWorld.class") |
57 |
| - .isNotEmptyFile(); |
58 |
| - |
59 |
| - assertThatCompilation(compilation) |
60 |
| - .classOutput() |
61 |
| - .packages() |
62 |
| - .fileExists("module-info.class") |
63 |
| - .isNotEmptyFile(); |
| 44 | + runHelloWorldTestExpectingPackages(compiler, workspace); |
64 | 45 | }
|
65 | 46 | }
|
66 | 47 |
|
67 | 48 | @DisplayName("I can compile a 'Hello, World!' module program using a temp directory on Javac")
|
68 |
| - @JavacCompilerTest(minVersion = 9) |
| 49 | + @JavacCompilerTest(minVersion = 9, configurers = IntegrationTestConfigurer.class) |
69 | 50 | void helloWorldUsingTempDirectoryJavac(JctCompiler<?, ?> compiler) {
|
70 | 51 | try (var workspace = Workspaces.newWorkspace(PathStrategy.TEMP_DIRECTORIES)) {
|
71 |
| - // Given |
72 |
| - workspace |
73 |
| - .createSourcePathPackage() |
74 |
| - .copyContentsFrom(resourcesDirectory()); |
75 |
| - |
76 |
| - // When |
77 |
| - var compilation = compiler.compile(workspace); |
78 |
| - |
79 |
| - // Then |
80 |
| - assertThatCompilation(compilation) |
81 |
| - .isSuccessfulWithoutWarnings(); |
82 |
| - |
83 |
| - assertThatCompilation(compilation) |
84 |
| - .classOutput() |
85 |
| - .packages() |
86 |
| - .fileExists("com", "example", "HelloWorld.class") |
87 |
| - .isNotEmptyFile(); |
88 |
| - |
89 |
| - assertThatCompilation(compilation) |
90 |
| - .classOutput() |
91 |
| - .packages() |
92 |
| - .fileExists("module-info.class") |
93 |
| - .isNotEmptyFile(); |
| 52 | + runHelloWorldTestExpectingPackages(compiler, workspace); |
94 | 53 | }
|
95 | 54 | }
|
96 | 55 |
|
97 | 56 | @DisplayName("I can compile a 'Hello, World!' module program using a temp directory on ECJ")
|
98 |
| - @EcjCompilerTest(minVersion = 9) |
| 57 | + @EcjCompilerTest(minVersion = 9, configurers = IntegrationTestConfigurer.class) |
99 | 58 | void helloWorldUsingTempDirectoryEcj(JctCompiler<?, ?> compiler) {
|
100 | 59 | try (var workspace = Workspaces.newWorkspace(PathStrategy.TEMP_DIRECTORIES)) {
|
101 |
| - // Given |
102 |
| - workspace |
103 |
| - .createSourcePathPackage() |
104 |
| - .copyContentsFrom(resourcesDirectory()); |
| 60 | + runHelloWorldTestExpectingModules(compiler, workspace); |
| 61 | + } |
| 62 | + } |
105 | 63 |
|
106 |
| - // When |
107 |
| - var compilation = compiler.compile(workspace); |
| 64 | + private void runHelloWorldTestExpectingPackages(JctCompiler<?, ?> compiler, Workspace workspace) { |
| 65 | + var compilation = runHelloWorldTestStart(compiler, workspace); |
108 | 66 |
|
109 |
| - // Then |
110 |
| - assertThatCompilation(compilation) |
111 |
| - .isSuccessfulWithoutWarnings(); |
| 67 | + assertThatCompilation(compilation) |
| 68 | + .classOutput() |
| 69 | + .packages() |
| 70 | + .fileExists("com", "example", "HelloWorld.class") |
| 71 | + .isNotEmptyFile(); |
112 | 72 |
|
113 |
| - assertThatCompilation(compilation) |
114 |
| - .classOutput() |
115 |
| - .modules() |
116 |
| - .moduleExists("hello.world") |
117 |
| - .satisfies( |
118 |
| - module -> assertThatContainerGroup(module) |
119 |
| - .fileExists("com", "example", "HelloWorld.class") |
120 |
| - .isNotEmptyFile(), |
121 |
| - module -> assertThatContainerGroup(module) |
122 |
| - .fileExists("module-info.class") |
123 |
| - .isNotEmptyFile() |
124 |
| - ); |
125 |
| - } |
| 73 | + assertThatCompilation(compilation) |
| 74 | + .classOutput() |
| 75 | + .packages() |
| 76 | + .fileExists("module-info.class") |
| 77 | + .isNotEmptyFile(); |
| 78 | + } |
| 79 | + |
| 80 | + private void runHelloWorldTestExpectingModules(JctCompiler<?, ?> compiler, Workspace workspace) { |
| 81 | + var compilation = runHelloWorldTestStart(compiler, workspace); |
| 82 | + |
| 83 | + assertThatCompilation(compilation) |
| 84 | + .classOutput() |
| 85 | + .modules() |
| 86 | + .moduleExists("hello.world") |
| 87 | + .satisfies( |
| 88 | + module -> assertThatContainerGroup(module) |
| 89 | + .fileExists("com", "example", "HelloWorld.class") |
| 90 | + .isNotEmptyFile(), |
| 91 | + module -> assertThatContainerGroup(module) |
| 92 | + .fileExists("module-info.class") |
| 93 | + .isNotEmptyFile() |
| 94 | + ); |
| 95 | + } |
| 96 | + |
| 97 | + private JctCompilation runHelloWorldTestStart(JctCompiler<?, ?> compiler, Workspace workspace) { |
| 98 | + // Given |
| 99 | + workspace |
| 100 | + .createSourcePathPackage() |
| 101 | + .copyContentsFrom(resourcesDirectory()); |
| 102 | + |
| 103 | + // When |
| 104 | + var compilation = compiler.compile(workspace); |
| 105 | + |
| 106 | + // Then |
| 107 | + assertThatCompilation(compilation) |
| 108 | + .isSuccessfulWithoutWarnings(); |
| 109 | + |
| 110 | + return compilation; |
126 | 111 | }
|
127 | 112 | }
|
0 commit comments