implements PLN-0110
This commit is contained in:
+80
@@ -1,12 +1,23 @@
|
||||
package p.studio.compiler.specs;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import p.studio.compiler.messages.BuildingIssueSink;
|
||||
import p.studio.compiler.messages.FrontendPhaseContext;
|
||||
import p.studio.compiler.models.FrontendSpec;
|
||||
import p.studio.compiler.models.IRBackend;
|
||||
import p.studio.compiler.services.FrontendPhaseService;
|
||||
import p.studio.compiler.services.FrontendProvider;
|
||||
import p.studio.compiler.source.diagnostics.DiagnosticSink;
|
||||
import p.studio.utilities.logs.LogAggregator;
|
||||
import p.studio.utilities.structures.ReadOnlySet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
class FrontendProviderBoundaryTest {
|
||||
@@ -37,6 +48,45 @@ class FrontendProviderBoundaryTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void commonModulesMustNotInstantiatePbsEditorialSupportServiceDirectly() throws IOException {
|
||||
final var repoRoot = findRepoRoot(Path.of("").toAbsolutePath().normalize());
|
||||
final var sourceRoots = List.of(
|
||||
repoRoot.resolve("prometeu-compiler/prometeu-build-pipeline/src/main/java"),
|
||||
repoRoot.resolve("prometeu-compiler/prometeu-deps/src/main/java"),
|
||||
repoRoot.resolve("prometeu-lsp/prometeu-lsp-v1/src/main/java"),
|
||||
repoRoot.resolve("prometeu-studio/src/main/java"),
|
||||
repoRoot.resolve("prometeu-app/src/main/java"));
|
||||
|
||||
for (final var sourceRoot : sourceRoots) {
|
||||
if (!Files.exists(sourceRoot)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try (final var files = Files.walk(sourceRoot)) {
|
||||
final var violations = files
|
||||
.filter(path -> path.toString().endsWith(".java"))
|
||||
.filter(path -> contains(path, "new PbsEditorialSupportService("))
|
||||
.toList();
|
||||
if (!violations.isEmpty()) {
|
||||
fail("common modules must resolve PBS editor behavior through FrontendProvider.languageService(): " + violations);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void compileOnlyFrontendProviderMayOmitLanguageService() {
|
||||
final FrontendProvider provider = new CompileOnlyFrontendProvider();
|
||||
|
||||
assertTrue(provider.languageService().isEmpty());
|
||||
assertNotNull(provider.compiler().compile(
|
||||
null,
|
||||
DiagnosticSink.empty(),
|
||||
LogAggregator.empty(),
|
||||
BuildingIssueSink.empty()));
|
||||
}
|
||||
|
||||
private boolean contains(final Path path, final String needle) {
|
||||
try {
|
||||
return Files.readString(path).contains(needle);
|
||||
@@ -56,4 +106,34 @@ class FrontendProviderBoundaryTest {
|
||||
fail("unable to locate repository root from " + start);
|
||||
return start;
|
||||
}
|
||||
|
||||
private static final class CompileOnlyFrontendProvider implements FrontendProvider {
|
||||
private final FrontendSpec specification = FrontendSpec.builder()
|
||||
.languageId("compile-only")
|
||||
.allowedExtensions(ReadOnlySet.from("co"))
|
||||
.sourceRoots(ReadOnlySet.from("src"))
|
||||
.build();
|
||||
private final FrontendPhaseService compiler = new CompileOnlyFrontendPhaseService();
|
||||
|
||||
@Override
|
||||
public FrontendSpec specification() {
|
||||
return specification;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FrontendPhaseService compiler() {
|
||||
return compiler;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class CompileOnlyFrontendPhaseService implements FrontendPhaseService {
|
||||
@Override
|
||||
public IRBackend compile(
|
||||
final FrontendPhaseContext request,
|
||||
final DiagnosticSink diagnostics,
|
||||
final LogAggregator logs,
|
||||
final BuildingIssueSink issues) {
|
||||
return IRBackend.builder().build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user