Skip to content

Commit

Permalink
Print syntax errors for test visibility, and polish test.
Browse files Browse the repository at this point in the history
  • Loading branch information
traceyyoshima committed Nov 9, 2023
1 parent 4746bcd commit 0c6a53a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/org/openrewrite/kotlin/KotlinParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public Stream<SourceFile> parseInputs(Iterable<Input> sources, @Nullable Path re
assert kotlinSource.getFirFile().getSource() != null;
PsiElement psi = ((KtRealPsiSourceElement) kotlinSource.getFirFile().getSource()).getPsi();
AnalyzerWithCompilerReport.SyntaxErrorReport report =
AnalyzerWithCompilerReport.Companion.reportSyntaxErrors(psi, MessageCollector.Companion.getNONE());
AnalyzerWithCompilerReport.Companion.reportSyntaxErrors(psi, new PrintingMessageCollector(System.err, PLAIN_FULL_PATHS, true));
if (report.isHasErrors()) {
return ParseError.build(KotlinParser.this, kotlinSource.getInput(), relativeTo, ctx, new RuntimeException());
}
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/org/openrewrite/kotlin/AssertionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.openrewrite.kotlin;

import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.ExpectedToFail;
import org.openrewrite.ExecutionContext;
Expand Down Expand Up @@ -61,11 +62,17 @@ class A {
);
}

/**
* This test is expected to fail due to invalid syntax and exists to prevent a regression in the compiler configuration.
* {@link AnalyzerWithCompilerReport} is used to analyze the syntax in each source to produce a ParserError if a syntax
* error exists in the source code.
*/
@ExpectedToFail
@Test
void invalidSyntax() {
rewriteRun(
kotlin(
//language=none
"""
a++
"""
Expand Down

0 comments on commit 0c6a53a

Please sign in to comment.