| 17 | import static org.junit.Assume.*; |
| 18 | |
| 19 | @RunWith(JQF.class) |
| 20 | public class CompilerTest { |
| 21 | |
| 22 | static { |
| 23 | // Disable all logging by Closure passes, to speed up fuzzing |
| 24 | java.util.logging.LogManager.getLogManager().reset(); |
| 25 | } |
| 26 | |
| 27 | // Compiler, options, and predefined JS environment |
| 28 | private Compiler compiler = new Compiler(new PrintStream(new ByteArrayOutputStream(), false)); |
| 29 | private CompilerOptions options = new CompilerOptions(); |
| 30 | private SourceFile externs = SourceFile.fromCode("externs", ""); |
| 31 | |
| 32 | @Before // Runs before tests are executed |
| 33 | public void initCompiler() { |
| 34 | // Don't use threads |
| 35 | compiler.disableThreads(); |
| 36 | // Don't print things |
| 37 | options.setPrintConfig(false); |
| 38 | // Enable all safe optimizations |
| 39 | CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options); |
| 40 | } |
| 41 | |
| 42 | /** Compiles an input and returns its result */ |
| 43 | private Result compile(SourceFile input) { |
| 44 | Result result = compiler.compile(externs, input, options); |
| 45 | assumeTrue(result.success); // Semantic validity check |
| 46 | return result; |
| 47 | } |
| 48 | |
| 49 | /** Entry point for fuzzing with default (arbitrary) string generator */ |
| 50 | @Fuzz |
| 51 | public void testWithGenerator(@From(JavaScriptCodeGenerator.class) String code) { |
| 52 | SourceFile input = SourceFile.fromCode("input", code); |
| 53 | compile(input); |
| 54 | } |
| 55 | } |
nothing calls this directly
no outgoing calls
no test coverage detected