summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorGeorge Fraser <george@fivetran.com>2019-01-01 20:02:04 -0800
committerGeorge Fraser <george@fivetran.com>2019-01-01 20:02:04 -0800
commitf3faf409445e82cfa12f9993c4075a5523000c0e (patch)
tree48d9df5fb20ae00b0345d0f941515f8296a2cb8b /src/test
parent280e801d4e529f471fc0631dc880b778815aa394 (diff)
downloadjava-language-server-f3faf409445e82cfa12f9993c4075a5523000c0e.zip
Error-prone is working but super slow
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/javacs/JavaCompilerServiceTest.java36
-rw-r--r--src/test/test-project/simple/UnusedVar.java5
2 files changed, 33 insertions, 8 deletions
diff --git a/src/test/java/org/javacs/JavaCompilerServiceTest.java b/src/test/java/org/javacs/JavaCompilerServiceTest.java
index 82fe157..e06e72a 100644
--- a/src/test/java/org/javacs/JavaCompilerServiceTest.java
+++ b/src/test/java/org/javacs/JavaCompilerServiceTest.java
@@ -16,6 +16,8 @@ import java.util.StringJoiner;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import javax.lang.model.element.Element;
+import javax.tools.Diagnostic;
+import javax.tools.JavaFileObject;
import org.junit.Test;
public class JavaCompilerServiceTest {
@@ -285,19 +287,37 @@ public class JavaCompilerServiceTest {
assertThat(diags, not(empty()));
}
- @Test
- public void errorProne() {
- var uri = resourceUri("ErrorProne.java");
- var files = Collections.singleton(uri);
- var diags = compiler.reportErrors(files);
+ private static List<String> errorStrings(List<Diagnostic<? extends JavaFileObject>> diags) {
+ var strings = new ArrayList<String>();
for (var d : diags) {
- var file = d.getSource().toUri().getPath();
+ var file = Parser.fileName(d.getSource().toUri());
var line = d.getLineNumber();
var kind = d.getKind();
var msg = d.getMessage(null);
- System.out.println(String.format("%s(%d)\t%s\t%s", file, line, kind, msg));
+ var string = String.format("%s(%d): %s", file, line, msg);
+ strings.add(string);
}
- assertThat(diags, not(empty()));
+ return strings;
+ }
+
+ @Test
+ public void errorProne() {
+ // TODO verify that error-prone *only* runs when you call reportErrors(),
+ // by calling compileFile() and checking no diagnostic is reported
+ var uri = resourceUri("ErrorProne.java");
+ var files = Collections.singleton(uri);
+ var diags = compiler.reportErrors(files);
+ var strings = errorStrings(diags);
+ assertThat(strings, hasItem(containsString("ErrorProne.java(7): [CollectionIncompatibleType]")));
+ }
+
+ @Test
+ public void unusedVar() {
+ var uri = resourceUri("UnusedVar.java");
+ var files = Collections.singleton(uri);
+ var diags = compiler.reportErrors(files);
+ var strings = errorStrings(diags);
+ assertThat(strings, hasItem(containsString("UnusedVar.java(3): [Unused]")));
}
@Test
diff --git a/src/test/test-project/simple/UnusedVar.java b/src/test/test-project/simple/UnusedVar.java
new file mode 100644
index 0000000..e6f3315
--- /dev/null
+++ b/src/test/test-project/simple/UnusedVar.java
@@ -0,0 +1,5 @@
+class UnusedVar {
+ void main() {
+ var x = 1;
+ }
+} \ No newline at end of file