Skip to content

Commit 7dc3570

Browse files
committed
Add integration test for multi-tiered compilation flows
1 parent 449ac14 commit 7dc3570

File tree

1 file changed

+135
-0
lines changed

1 file changed

+135
-0
lines changed
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*
2+
* Copyright (C) 2022 - 2023, the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.github.ascopes.jct.tests.integration;
17+
18+
import static io.github.ascopes.jct.assertions.JctAssertions.assertThatCompilation;
19+
20+
import io.github.ascopes.jct.compilers.JctCompiler;
21+
import io.github.ascopes.jct.junit.JavacCompilerTest;
22+
import io.github.ascopes.jct.workspaces.Workspaces;
23+
import org.junit.jupiter.api.DisplayName;
24+
25+
/**
26+
* Integration tests to test the mechanisms used to create JARs and inputs from one compilation and
27+
* feed them into a second compilation.
28+
*
29+
* @author Ashley Scopes
30+
*/
31+
@DisplayName("Multi-tiered compilation integration tests")
32+
class MultiTieredCompilationIntegrationTest {
33+
34+
@DisplayName(
35+
"I can compile sources to classes and provide them in the classpath to a second compilation"
36+
)
37+
@JavacCompilerTest
38+
void compileSourcesToClassesAndProvideThemInClassPathToSecondCompilation(
39+
JctCompiler<?, ?> compiler
40+
) {
41+
try (
42+
var firstWorkspace = Workspaces.newWorkspace();
43+
var secondWorkspace = Workspaces.newWorkspace()
44+
) {
45+
firstWorkspace
46+
.createSourcePathPackage()
47+
.createFile("org", "example", "first", "Adder.java")
48+
.withContents(
49+
"package org.example.first;",
50+
"",
51+
"public class Adder {",
52+
" public int add(int a, int b) {",
53+
" return a + b;",
54+
" }",
55+
"}"
56+
);
57+
58+
var firstCompilation = compiler.compile(firstWorkspace);
59+
assertThatCompilation(firstCompilation).isSuccessfulWithoutWarnings();
60+
61+
secondWorkspace.addClassPathPackage(firstWorkspace.getClassOutputPackages().get(0).getPath());
62+
secondWorkspace.createSourcePathPackage()
63+
.createFile("org", "example", "second", "Main.java")
64+
.withContents(
65+
"package org.example.second;",
66+
"",
67+
"import org.example.first.Adder;",
68+
"",
69+
"public class Main {",
70+
" public static int addTogether(int a, int b) {",
71+
" Adder adder = new Adder();",
72+
" return adder.add(a, b);",
73+
" }",
74+
"}"
75+
);
76+
77+
var secondCompilation = compiler.compile(secondWorkspace);
78+
assertThatCompilation(secondCompilation).isSuccessfulWithoutWarnings();
79+
}
80+
}
81+
82+
@DisplayName(
83+
"I can compile sources to classes and provide them in the classpath to a second "
84+
+ "compilation within a JAR"
85+
)
86+
@JavacCompilerTest
87+
void compileSourcesToClassesAndProvideThemInClassPathToSecondCompilationWithinJar(
88+
JctCompiler<?, ?> compiler
89+
) {
90+
try (
91+
var firstWorkspace = Workspaces.newWorkspace();
92+
var secondWorkspace = Workspaces.newWorkspace()
93+
) {
94+
firstWorkspace
95+
.createSourcePathPackage()
96+
.createFile("org", "example", "first", "Adder.java")
97+
.withContents(
98+
"package org.example.first;",
99+
"",
100+
"public class Adder {",
101+
" public int add(int a, int b) {",
102+
" return a + b;",
103+
" }",
104+
"}"
105+
);
106+
107+
var firstCompilation = compiler.compile(firstWorkspace);
108+
assertThatCompilation(firstCompilation).isSuccessfulWithoutWarnings();
109+
firstWorkspace
110+
.createClassOutputPackage()
111+
.createFile("first.jar")
112+
.asJarFrom(firstWorkspace.getClassOutputPackages().get(0));
113+
114+
var firstJar = firstWorkspace.getClassOutputPackages().get(1).getPath().resolve("first.jar");
115+
secondWorkspace.addClassPathPackage(firstJar);
116+
secondWorkspace.createSourcePathPackage()
117+
.createFile("org", "example", "second", "Main.java")
118+
.withContents(
119+
"package org.example.second;",
120+
"",
121+
"import org.example.first.Adder;",
122+
"",
123+
"public class Main {",
124+
" public static int addTogether(int a, int b) {",
125+
" Adder adder = new Adder();",
126+
" return adder.add(a, b);",
127+
" }",
128+
"}"
129+
);
130+
131+
var secondCompilation = compiler.compile(secondWorkspace);
132+
assertThatCompilation(secondCompilation).isSuccessfulWithoutWarnings();
133+
}
134+
}
135+
}

0 commit comments

Comments
 (0)