From 73b58b585b0e12b9baf263fdc55da2f2b501651f Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 29 Aug 2026 19:45:38 +0100 Subject: Generate empty TypeScript module for each namespace --- .../zwobble/hobgoblin/compiler/ExampleTests.java | 27 +++++++++----- .../lang/typescript/TypescriptWriterTests.java | 2 +- .../ast/TypescriptIdentifierMatcher.java | 41 ++++++++++++++++++++++ .../typescript/ast/TypescriptModuleMatcher.java | 6 ++++ 4 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptIdentifierMatcher.java (limited to 'src/test/java') diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java index 1c77a83..3cc7048 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java @@ -32,6 +32,7 @@ public class ExampleTests { var javaOutputPath = verifyJavaOutput(exampleSet); var rustOutputPath = verifyRustOutput(exampleSet); + verifyTypescriptOutput(exampleSet); // TODO: make detection more robust if (exampleSet.name().contains("transient-0")) { @@ -61,17 +62,24 @@ public class ExampleTests { } private Optional verifyJavaOutput(ExampleSet exampleSet) throws NoSuchAlgorithmException, IOException, InterruptedException { - return verifyOutput(exampleSet, "java", List.of("mvn", "test")); + return verifyOutput(exampleSet, "java", List.of(List.of("mvn", "test"))); } private Optional verifyRustOutput(ExampleSet exampleSet) throws NoSuchAlgorithmException, IOException, InterruptedException { - return verifyOutput(exampleSet, "rust", List.of("cargo", "test")); + return verifyOutput(exampleSet, "rust", List.of(List.of("cargo", "test"))); + } + + private Optional verifyTypescriptOutput(ExampleSet exampleSet) throws NoSuchAlgorithmException, IOException, InterruptedException { + return verifyOutput(exampleSet, "typescript", List.of( + List.of("./node_modules/.bin/tsc", "--noEmit"), + List.of("npm", "test")) + ); } private Optional verifyOutput( ExampleSet exampleSet, String name, - List command + List> commands ) throws NoSuchAlgorithmException, IOException, InterruptedException { var outputPath = exampleSet.path().resolve("output").resolve(name); @@ -89,11 +97,14 @@ public class ExampleTests { } try { - TestProcessRunner.command(command) - .cwd(outputPath) - .addEnvVar("HOBGOBLIN_OUTPUT_DIR", outputPath.toAbsolutePath().toString()) - .runCaptureOutput() - .throwOnError(); + for (var command : commands) { + TestProcessRunner.command(command) + .cwd(outputPath) + .addEnvVar("HOBGOBLIN_OUTPUT_DIR", outputPath.toAbsolutePath().toString()) + .runCaptureOutput() + .throwOnError(); + } + writeLastTestRun(lastTestRunPath, new LastTestRun(currentHash, true)); } catch (Throwable exception) { writeLastTestRun(lastTestRunPath, new LastTestRun(currentHash, false)); diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriterTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriterTests.java index 8712b4a..71978f0 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriterTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriterTests.java @@ -16,7 +16,7 @@ public class TypescriptWriterTests { @Test public void emptyModule() throws IOException { - var typescript = new TypescriptModule(); + var typescript = TypescriptModule.arbitrary().build(); var string = write(writer -> writer.writeModule(typescript)); diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptIdentifierMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptIdentifierMatcher.java new file mode 100644 index 0000000..d54b193 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptIdentifierMatcher.java @@ -0,0 +1,41 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.typescript.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifierMatcher imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifierMatcher imports + +public final class TypescriptIdentifierMatcher implements org.zwobble.precisely.Matcher { + public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifierMatcher isTypescriptIdentifier() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifierMatcher(java.util.List.of()); + } + + private final java.util.List> submatchers; + + private TypescriptIdentifierMatcher( + java.util.List> submatchers + ) { + this.submatchers = submatchers; + } + + public org.zwobble.precisely.MatchResult match(java.lang.Object actual) { + return this.toMatcher().match(actual); + } + + public org.zwobble.precisely.TextTree describe() { + return this.toMatcher().describe(); + } + + private org.zwobble.precisely.Matcher toMatcher() { + return org.zwobble.precisely.Matchers.instanceOf(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier.class, this.submatchers); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifierMatcher withValue(org.zwobble.precisely.Matcher value) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("value", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifier::value, value)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifierMatcher(submatchers); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifierMatcher body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptIdentifierMatcher body +} diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptModuleMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptModuleMatcher.java index 088dba0..2a9f2f5 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptModuleMatcher.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptModuleMatcher.java @@ -30,6 +30,12 @@ public final class TypescriptModuleMatcher implements org.zwobble.precisely.Matc return org.zwobble.precisely.Matchers.instanceOf(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule.class, this.submatchers); } + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModuleMatcher withName(org.zwobble.precisely.Matcher> name) { + var submatchers = new java.util.ArrayList>(this.submatchers); + submatchers.add(org.zwobble.precisely.Matchers.has("name", org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModule::name, name)); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModuleMatcher(submatchers); + } + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModuleMatcher body // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptModuleMatcher body } -- cgit v1.2.3