/** * Gets the compiler options to use for this test. Use getProcessor to determine what passes * should be run. */ protected CompilerOptions getOptions(CompilerOptions options) { options.setLanguageIn(acceptedLanguage); // This doesn't affect whether checkSymbols is run--it just affects // whether variable warnings are filtered. options.checkSymbols = true; options.setWarningLevel(DiagnosticGroups.MISSING_PROPERTIES, CheckLevel.WARNING); options.setWarningLevel(DiagnosticGroups.INVALID_CASTS, CheckLevel.WARNING); options.setCodingConvention(getCodingConvention()); return options; }
private Node parse(String[] original) { String[] argStrings = args.toArray(new String[] {}); CommandLineRunner runner = new CommandLineRunner(argStrings); Compiler compiler = runner.createCompiler(); List<SourceFile> inputs = Lists.newArrayList(); for (int i = 0; i < original.length; i++) { inputs.add(SourceFile.fromCode(getFilename(i), original[i])); } CompilerOptions options = new CompilerOptions(); // ECMASCRIPT5 is the most forgiving. options.setLanguageIn(LanguageMode.ECMASCRIPT5); compiler.init(externs, inputs, options); Node all = compiler.parseInputs(); Preconditions.checkState(compiler.getErrorCount() == 0); Preconditions.checkNotNull(all); Node n = all.getLastChild(); return n; }
/** * Verifies that the compiler pass's JS output matches the expected output and (optionally) that * an expected warning is issued. Or, if an error is expected, this method just verifies that the * error is encountered. * * @param externs Externs inputs * @param js Inputs * @param expected Expected output, or null if an error is expected * @param error Expected error, or null if no error is expected * @param warning Expected warning, or null if no warning is expected * @param description The description of the expected warning, or null if no warning is expected * or if the warning's description should not be examined */ private void test( List<SourceFile> externs, List<SourceFile> js, String expected, DiagnosticType error, DiagnosticType warning, String description) { Compiler compiler = createCompiler(); lastCompiler = compiler; CompilerOptions options = getOptions(); options.setLanguageIn(acceptedLanguage); // Note that in this context, turning on the checkTypes option won't // actually cause the type check to run. options.checkTypes = parseTypeInfo; compiler.init(externs, js, options); BaseJSTypeTestCase.addNativeProperties(compiler.getTypeRegistry()); test(compiler, maybeCreateArray(expected), error, warning, description); }