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);
}
}
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);
}
Aggregations