Search in sources :

Example 1 with Compilation

use of com.google.testing.compile.Compilation in project auto by google.

the class AutoValueJava8Test method setUpClass.

// This is appalling. Some versions of javac do not correctly report annotations on type uses in
// certain cases, for example on type variables or arrays. Since some of the tests here are for
// exactly that, we compile a test program with a test annotation processor to see whether we
// might be in the presence of such a javac, and if so we skip the tests that would fail because
// of the bug. This isn't completely sound because we can't be entirely sure that the javac that
// Compiler.javac() finds is the same as the javac that was used to build this test (and therefore
// run AutoValueProcessor), but it's better than just ignoring the tests outright.
@BeforeClass
public static void setUpClass() {
    JavaFileObject javaFileObject = JavaFileObjects.forSourceLines("Test", "import java.lang.annotation.ElementType;", "import java.lang.annotation.Retention;", "import java.lang.annotation.RetentionPolicy;", "import java.lang.annotation.Target;", "public abstract class Test<T> {", "  @Retention(RetentionPolicy.RUNTIME)", "  @Target(ElementType.TYPE_USE)", "  public @interface Nullable {}", "", "  public abstract @Nullable T t();", "}");
    Compilation compilation = Compiler.javac().withProcessors(new BugTestProcessor()).compile(javaFileObject);
    if (compilation.errors().isEmpty()) {
        javacHandlesTypeAnnotationsCorrectly = true;
    } else {
        assertThat(compilation).hadErrorCount(1);
        assertThat(compilation).hadErrorContaining(JAVAC_HAS_BUG_ERROR);
    }
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Compilation(com.google.testing.compile.Compilation) BeforeClass(org.junit.BeforeClass)

Example 2 with Compilation

use of com.google.testing.compile.Compilation in project auto by google.

the class TypeSimplifierTest method testErrorTypes.

// This test checks that we correctly throw MissingTypeException if there is an ErrorType anywhere
// inside a type we are asked to simplify. There's no way to get an ErrorType from typeUtils or
// elementUtils, so we need to fire up the compiler with an erroneous source file and use an
// annotation processor to capture the resulting ErrorType. Then we can run tests within that
// annotation processor, and propagate any failures out of this test.
@Test
public void testErrorTypes() {
    JavaFileObject source = JavaFileObjects.forSourceString("ExtendsUndefinedType", "class ExtendsUndefinedType extends UndefinedParent {}");
    Compilation compilation = javac().withProcessors(new ErrorTestProcessor()).compile(source);
    assertThat(compilation).failed();
    assertThat(compilation).hadErrorContaining("UndefinedParent");
    assertThat(compilation).hadErrorCount(1);
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Compilation(com.google.testing.compile.Compilation) Test(org.junit.Test)

Aggregations

Compilation (com.google.testing.compile.Compilation)2 JavaFileObject (javax.tools.JavaFileObject)2 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1