-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve parse error handling in compile-testing
RELNOTES=Improve parse error handling PiperOrigin-RevId: 592691296
- Loading branch information
Showing
3 changed files
with
62 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.google.testing.compile; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
import static org.junit.Assert.assertThrows; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import javax.tools.JavaFileObject; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
@RunWith(JUnit4.class) | ||
public final class ParserTest { | ||
|
||
private static final JavaFileObject HELLO_WORLD_BROKEN = | ||
JavaFileObjects.forSourceLines( | ||
"test.HelloWorld", "package test;", "", "public class HelloWorld {", "}}"); | ||
|
||
@Test | ||
public void failsToParse() { | ||
IllegalStateException expected = | ||
assertThrows( | ||
IllegalStateException.class, | ||
() -> Parser.parse(ImmutableList.of(HELLO_WORLD_BROKEN), "hello world")); | ||
assertThat(expected).hasMessageThat().contains("HelloWorld.java:4: error"); | ||
} | ||
} |