Skip to content

Commit 770e2f7

Browse files
authored
Merge pull request #763 from ascopes/task/remove-jpms-from-unit-tests
Remove JPMS from unit tests as a simplification
2 parents d607b76 + f44f8ed commit 770e2f7

127 files changed

Lines changed: 245 additions & 923 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

java-compiler-testing/src/it/dogfood/src/test/java/io/github/ascopes/jct/acceptancetests/dogfood/JctDogfoodTest.java

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
class JctDogfoodTest {
3737

3838
static final String MAIN_MODULE = "io.github.ascopes.jct";
39-
static final String TEST_MODULE = "io.github.ascopes.jct.testing";
4039

4140
static final Path PROJECT_ROOT = projectBase()
4241
.resolve("java-compiler-testing")
@@ -48,19 +47,10 @@ class JctDogfoodTest {
4847
.resolve("main")
4948
.resolve("java");
5049

51-
static final Path SRC_TEST_JAVA = PROJECT_ROOT
52-
.resolve("src")
53-
.resolve("test")
54-
.resolve("java");
55-
5650
static final Path TARGET_CLASSES = PROJECT_ROOT
5751
.resolve("target")
5852
.resolve("classes");
5953

60-
static final Path TARGET_TEST_CLASSES = PROJECT_ROOT
61-
.resolve("target")
62-
.resolve("test-classes");
63-
6454
@DisplayName("JCT can compile itself as a legacy module source")
6555
@JavacCompilerTest(minVersion = 11, configurers = JctCompilationConfigurer.class)
6656
void jctCanCompileItselfAsLegacyModule(JctCompiler compiler) throws IOException {
@@ -83,63 +73,6 @@ void jctCanCompileItselfAsLegacyModule(JctCompiler compiler) throws IOException
8373
}
8474
}
8575

86-
@DisplayName("JCT can compile its unit tests as a legacy module source")
87-
@JavacCompilerTest(minVersion = 11, configurers = JctCompilationConfigurer.class)
88-
void jctCanCompileUnitTestsAsLegacyModule(JctCompiler compiler) throws IOException {
89-
// Given
90-
try (var workspace = Workspaces.newWorkspace()) {
91-
workspace
92-
.createSourcePathPackage()
93-
.copyContentsFrom(SRC_TEST_JAVA);
94-
95-
// When
96-
var compilation = compiler.compile(workspace);
97-
98-
// Then
99-
assertThat(compilation)
100-
.isSuccessful();
101-
102-
assertThat(compilation)
103-
.classPathPackages()
104-
.allFilesExist(getClassesFrom(TARGET_TEST_CLASSES));
105-
}
106-
}
107-
108-
@DisplayName("JCT can compile itself and its unit tests as a multiple-module source")
109-
@JavacCompilerTest(minVersion = 11, configurers = JctCompilationConfigurer.class)
110-
void jctCanCompileItselfAndUnitTestsAsMultiModule(JctCompiler compiler) throws IOException {
111-
// Given
112-
try (var workspace = Workspaces.newWorkspace()) {
113-
workspace
114-
.createSourcePathModule(MAIN_MODULE)
115-
.copyContentsFrom(SRC_MAIN_JAVA);
116-
workspace
117-
.createSourcePathModule(TEST_MODULE)
118-
.copyContentsFrom(SRC_TEST_JAVA);
119-
120-
// When
121-
var compilation = compiler.compile(workspace);
122-
123-
// Then
124-
var expectedMainFiles = getClassesFrom(TARGET_CLASSES);
125-
var expectedTestFiles = getClassesFrom(TARGET_TEST_CLASSES);
126-
127-
assertThat(compilation)
128-
.isSuccessful();
129-
130-
assertThat(compilation)
131-
.classOutputModules()
132-
.satisfies(
133-
modules -> assertThat(modules.getModule(MAIN_MODULE))
134-
.withFailMessage("Missing classes from main source root")
135-
.allFilesExist(expectedMainFiles),
136-
modules -> assertThat(modules.getModule(TEST_MODULE))
137-
.withFailMessage("Missing classes from test source root")
138-
.allFilesExist(expectedTestFiles)
139-
);
140-
}
141-
}
142-
14376
private static Set<String> getClassesFrom(Path location) throws IOException {
14477
try (var walker = Files.walk(location)) {
14578
return walker

java-compiler-testing/src/main/java/io/github/ascopes/jct/junit/AbstractCompilersProvider.java

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -275,29 +275,7 @@ private JctCompilerConfigurer<?> initializeConfigurer(
275275
);
276276
}
277277

278-
try {
279-
// Force-enable reflective access. If the user is using a SecurityManager for any reason then
280-
// tough luck. JVM go bang.
281-
// If the module is not open to JCT, then we will get an InaccessibleObjectException that
282-
// we should wrap and rethrow.
283-
constructor.setAccessible(true);
284-
285-
} catch (InaccessibleObjectException ex) {
286-
287-
throw new JctJunitConfigurerException(
288-
"The constructor in " + configurerClass.getSimpleName() + " cannot be called from JCT."
289-
+ "\n"
290-
+ "This is likely because JPMS modules are in use and you have not granted "
291-
+ "permission for JCT to access your classes reflectively."
292-
+ "\n"
293-
+ "To fix this, add the following line into your module-info.java within the "
294-
+ "'module' block:"
295-
+ "\n\n"
296-
+ " opens " + constructor.getDeclaringClass().getPackageName() + " to "
297-
+ getClass().getModule().getName() + ";",
298-
ex
299-
);
300-
}
278+
constructor.setAccessible(true);
301279

302280
try {
303281
return constructor.newInstance();

java-compiler-testing/src/main/java/module-info.java

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -150,34 +150,4 @@
150150
///////////////////////////////////
151151

152152
provides URLStreamHandlerProvider with MemoryFileSystemUrlHandlerProvider;
153-
154-
//////////////////////////////////////////////////////
155-
/// EXPOSURE OF INTERNALS TO THE TESTING NAMESPACE ///
156-
//////////////////////////////////////////////////////
157-
158-
exports io.github.ascopes.jct.compilers.impl to io.github.ascopes.jct.testing;
159-
exports io.github.ascopes.jct.containers.impl to io.github.ascopes.jct.testing;
160-
exports io.github.ascopes.jct.filemanagers.impl to io.github.ascopes.jct.testing;
161-
exports io.github.ascopes.jct.utils to io.github.ascopes.jct.testing;
162-
exports io.github.ascopes.jct.workspaces.impl to io.github.ascopes.jct.testing;
163-
164-
//////////////////////////////////////////////////////////////////////////
165-
/// EXPOSURE OF ALL COMPONENTS TO THE TESTING NAMESPACE FOR REFLECTION ///
166-
//////////////////////////////////////////////////////////////////////////
167-
168-
opens io.github.ascopes.jct.assertions to io.github.ascopes.jct.testing;
169-
opens io.github.ascopes.jct.compilers to io.github.ascopes.jct.testing;
170-
opens io.github.ascopes.jct.compilers.impl to io.github.ascopes.jct.testing;
171-
opens io.github.ascopes.jct.containers to io.github.ascopes.jct.testing;
172-
opens io.github.ascopes.jct.containers.impl to io.github.ascopes.jct.testing;
173-
opens io.github.ascopes.jct.diagnostics to io.github.ascopes.jct.testing;
174-
opens io.github.ascopes.jct.ex to io.github.ascopes.jct.testing;
175-
opens io.github.ascopes.jct.filemanagers to io.github.ascopes.jct.testing;
176-
opens io.github.ascopes.jct.filemanagers.config to io.github.ascopes.jct.testing;
177-
opens io.github.ascopes.jct.filemanagers.impl to io.github.ascopes.jct.testing;
178-
opens io.github.ascopes.jct.junit to io.github.ascopes.jct.testing;
179-
opens io.github.ascopes.jct.repr to io.github.ascopes.jct.testing;
180-
opens io.github.ascopes.jct.utils to io.github.ascopes.jct.testing;
181-
opens io.github.ascopes.jct.workspaces to io.github.ascopes.jct.testing;
182-
opens io.github.ascopes.jct.workspaces.impl to io.github.ascopes.jct.testing;
183153
}

java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/assertions/AbstractContainerGroupAssertTest.java renamed to java-compiler-testing/src/test/java/io/github/ascopes/jct/assertions/AbstractContainerGroupAssertTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.github.ascopes.jct.tests.unit.assertions;
16+
package io.github.ascopes.jct.assertions;
1717

18-
import static io.github.ascopes.jct.tests.helpers.Fixtures.someLocation;
18+
import static io.github.ascopes.jct.fixtures.Fixtures.someLocation;
1919
import static org.assertj.core.api.Assertions.assertThat;
2020
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2121
import static org.mockito.ArgumentMatchers.any;
@@ -24,8 +24,6 @@
2424
import static org.mockito.Mockito.verifyNoMoreInteractions;
2525
import static org.mockito.Mockito.when;
2626

27-
import io.github.ascopes.jct.assertions.AbstractContainerGroupAssert;
28-
import io.github.ascopes.jct.assertions.LocationAssert;
2927
import io.github.ascopes.jct.containers.ContainerGroup;
3028
import java.util.List;
3129
import java.util.ServiceLoader;

java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/assertions/AbstractEnumAssertTest.java renamed to java-compiler-testing/src/test/java/io/github/ascopes/jct/assertions/AbstractEnumAssertTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.github.ascopes.jct.tests.unit.assertions;
16+
package io.github.ascopes.jct.assertions;
1717

1818
import static org.assertj.core.api.Assertions.assertThat;
1919
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2020

21-
import io.github.ascopes.jct.assertions.AbstractEnumAssert;
2221
import java.util.Arrays;
2322
import java.util.List;
2423
import org.jspecify.annotations.Nullable;

java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/assertions/AbstractJavaFileObjectAssertTest.java renamed to java-compiler-testing/src/test/java/io/github/ascopes/jct/assertions/AbstractJavaFileObjectAssertTest.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,16 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.github.ascopes.jct.tests.unit.assertions;
16+
package io.github.ascopes.jct.assertions;
1717

18-
import static io.github.ascopes.jct.tests.helpers.Fixtures.someBinaryData;
19-
import static io.github.ascopes.jct.tests.helpers.Fixtures.someCharset;
20-
import static io.github.ascopes.jct.tests.helpers.Fixtures.someJavaFileObject;
21-
import static io.github.ascopes.jct.tests.helpers.Fixtures.somePath;
18+
import static io.github.ascopes.jct.fixtures.Fixtures.someBinaryData;
19+
import static io.github.ascopes.jct.fixtures.Fixtures.someCharset;
20+
import static io.github.ascopes.jct.fixtures.Fixtures.someJavaFileObject;
21+
import static io.github.ascopes.jct.fixtures.Fixtures.somePath;
2222
import static org.assertj.core.api.Assertions.assertThat;
2323
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2424
import static org.mockito.Mockito.when;
2525

26-
import io.github.ascopes.jct.assertions.AbstractJavaFileObjectAssert;
27-
import io.github.ascopes.jct.assertions.JavaFileObjectKindAssert;
2826
import java.io.ByteArrayInputStream;
2927
import java.io.IOException;
3028
import java.nio.charset.Charset;

java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/assertions/ClassLoaderAssertTest.java renamed to java-compiler-testing/src/test/java/io/github/ascopes/jct/assertions/ClassLoaderAssertTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.github.ascopes.jct.tests.unit.assertions;
16+
package io.github.ascopes.jct.assertions;
1717

1818
import static org.mockito.Mockito.mock;
1919

20-
import io.github.ascopes.jct.assertions.ClassLoaderAssert;
2120
import org.junit.jupiter.api.DisplayName;
2221
import org.junit.jupiter.api.Test;
2322

java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/assertions/DiagnosticKindAssertTest.java renamed to java-compiler-testing/src/test/java/io/github/ascopes/jct/assertions/DiagnosticKindAssertTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.github.ascopes.jct.tests.unit.assertions;
16+
package io.github.ascopes.jct.assertions;
1717

1818
import static org.assertj.core.api.Assertions.assertThat;
1919
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2020

21-
import io.github.ascopes.jct.assertions.DiagnosticKindAssert;
2221
import javax.tools.Diagnostic.Kind;
2322
import org.junit.jupiter.api.DisplayName;
2423
import org.junit.jupiter.api.Nested;

java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/assertions/JavaFileObjectAssertTest.java renamed to java-compiler-testing/src/test/java/io/github/ascopes/jct/assertions/JavaFileObjectAssertTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.github.ascopes.jct.tests.unit.assertions;
16+
package io.github.ascopes.jct.assertions;
1717

18-
import static io.github.ascopes.jct.tests.helpers.Fixtures.someJavaFileObject;
18+
import static io.github.ascopes.jct.fixtures.Fixtures.someJavaFileObject;
1919
import static org.assertj.core.api.Assertions.assertThat;
2020

21-
import io.github.ascopes.jct.assertions.AbstractJavaFileObjectAssert;
22-
import io.github.ascopes.jct.assertions.JavaFileObjectAssert;
2321
import org.junit.jupiter.api.DisplayName;
2422
import org.junit.jupiter.api.Test;
2523

java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/assertions/JavaFileObjectKindAssertTest.java renamed to java-compiler-testing/src/test/java/io/github/ascopes/jct/assertions/JavaFileObjectKindAssertTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.github.ascopes.jct.tests.unit.assertions;
16+
package io.github.ascopes.jct.assertions;
1717

1818
import static org.assertj.core.api.Assertions.assertThat;
1919
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2020

21-
import io.github.ascopes.jct.assertions.JavaFileObjectKindAssert;
2221
import javax.tools.JavaFileObject;
2322
import javax.tools.JavaFileObject.Kind;
2423
import org.assertj.core.api.AbstractStringAssert;

0 commit comments

Comments
 (0)