|
33 | 33 | import org.junit.jupiter.params.provider.ArgumentsSource; |
34 | 34 |
|
35 | 35 | /** |
36 | | - * Annotation that can be applied to a {@link ParameterizedTest} to enable passing in a range of |
37 | | - * {@link JavacJctCompilerImpl} instances with specific configured versions as the first |
38 | | - * parameter. |
| 36 | + * Annotation that can be applied to a JUnit parameterized test to invoke that test case across |
| 37 | + * multiple compilers, each configured to a specific version in a range of Java language versions. |
39 | 38 | * |
40 | 39 | * <p>This will also add the {@code "java-compiler-testing-test"} tag and {@code "javac-test"} |
41 | 40 | * tags to your test method, meaning you can instruct your IDE or build system to optionally only |
|
45 | 44 | * <p>If your build is running in a GraalVM Native Image, then this test will not execute, as |
46 | 45 | * the <em>Java Compiler Testing</em> API is not yet tested within Native Images. |
47 | 46 | * |
| 47 | + * <p>For example, to run a simple test on Java 11 through 17 (inclusive): |
| 48 | + * |
| 49 | + * <pre><code> |
| 50 | + * class SomeTest { |
| 51 | + * {@literal @JavacCompilerTest(minVersion = 11, maxVersion = 17)} |
| 52 | + * void canCompileHelloWorld(JctCompiler<?, ?>> compiler) { |
| 53 | + * // Given |
| 54 | + * try (var workspace = Workspaces.newWorkspace()) { |
| 55 | + * workspace |
| 56 | + * .createFile("org", "example", "HelloWorld.java") |
| 57 | + * .withContents(""" |
| 58 | + * package org.example; |
| 59 | + * |
| 60 | + * public class HelloWorld { |
| 61 | + * public static void main(String[] args) { |
| 62 | + * System.out.println("Hello, World!"); |
| 63 | + * } |
| 64 | + * } |
| 65 | + * """); |
| 66 | + * |
| 67 | + * var compilation = compiler.compile(workspace); |
| 68 | + * |
| 69 | + * assertThat(compilation) |
| 70 | + * .isSuccessfulWithoutWarnings(); |
| 71 | + * } |
| 72 | + * } |
| 73 | + * } |
| 74 | + * </code></pre> |
| 75 | + * |
48 | 76 | * @author Ashley Scopes |
49 | 77 | * @since 0.0.1 |
50 | 78 | */ |
|
66 | 94 | /** |
67 | 95 | * Minimum version to use (inclusive). |
68 | 96 | * |
| 97 | + * <p>By default, it will use the lowest possible version supported by the compiler. This |
| 98 | + * varies between versions of the JDK that are in use. |
| 99 | + * |
| 100 | + * <p>If the version is lower than the minimum supported version, then the minimum supported |
| 101 | + * version of the compiler will be used instead. This enables writing tests that will work on |
| 102 | + * a range of JDKs during builds without needing to duplicate the test to satisfy different |
| 103 | + * JDK supported version ranges. |
| 104 | + * |
69 | 105 | * @return the minimum version. |
70 | 106 | */ |
71 | 107 | int minVersion() default Integer.MIN_VALUE; |
72 | 108 |
|
73 | 109 | /** |
74 | 110 | * Maximum version to use (inclusive). |
75 | 111 | * |
| 112 | + * <p>By default, it will use the highest possible version supported by the compiler. This |
| 113 | + * varies between versions of the JDK that are in use. |
| 114 | + * |
| 115 | + * <p>If the version is higher than the maximum supported version, then the maximum supported |
| 116 | + * version of the compiler will be used instead. This enables writing tests that will work on |
| 117 | + * a range of JDKs during builds without needing to duplicate the test to satisfy different |
| 118 | + * JDK supported version ranges. |
| 119 | + * |
76 | 120 | * @return the maximum version. |
77 | 121 | */ |
78 | 122 | int maxVersion() default Integer.MAX_VALUE; |
79 | 123 |
|
80 | 124 | /** |
81 | | - * Get an array of compiler configurers to apply in-order before starting the test. |
| 125 | + * Get an array of compiler configurer classes to apply in-order before starting the test. |
82 | 126 | * |
83 | 127 | * <p>Each configurer must have a public no-args constructor, and their package must be |
84 | 128 | * open to this module if JPMS modules are in-use, for example: |
|
92 | 136 | * } |
93 | 137 | * </code></pre> |
94 | 138 | * |
| 139 | + * An example of usage: |
| 140 | + * |
| 141 | + * <pre><code> |
| 142 | + * public class WerrorConfigurer implements JctCompilerConfigurer<RuntimeException> { |
| 143 | + * {@literal @Override} |
| 144 | + * public void configure(JctCompiler<?, ?> compiler) { |
| 145 | + * compiler.failOnWarnings(true); |
| 146 | + * } |
| 147 | + * } |
| 148 | + * |
| 149 | + * // ... |
| 150 | + * |
| 151 | + * class SomeTest { |
| 152 | + * {@literal @JavacCompilerTest(configurers = WerrorConfigurer.class)} |
| 153 | + * void someTest(JctCompiler<?, ?> compiler) { |
| 154 | + * // ... |
| 155 | + * } |
| 156 | + * } |
| 157 | + * </code></pre> |
| 158 | + * |
95 | 159 | * @return an array of classes to run to configure the compiler. These run in the given order. |
96 | 160 | */ |
97 | 161 | Class<? extends JctCompilerConfigurer<?>>[] configurers() default {}; |
|
103 | 167 | * modules. |
104 | 168 | * |
105 | 169 | * @return {@code true} if we need to support modules, or {@code false} if we do not. |
| 170 | + * @deprecated this will be removed in a future release, since Java 8 is reaching end-of-life. |
106 | 171 | */ |
| 172 | + @Deprecated(forRemoval = true, since = "0.0.2") |
107 | 173 | boolean modules() default false; |
108 | 174 |
|
109 | 175 | /** |
|
0 commit comments