Search in sources :

Example 46 with ErrorReporter

use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.

the class TemplateSubject method isNotWellFormed.

public void isNotWellFormed() {
    ErrorReporter errorReporter = doParse();
    Truth.assertThat(errorReporter.hasErrors()).isTrue();
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter)

Example 47 with ErrorReporter

use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.

the class TemplateParserTest method assertInvalidTemplate.

private static void assertInvalidTemplate(String input) {
    ErrorReporter errorReporter = ErrorReporter.createForTest();
    parseTemplateContent(input, errorReporter);
    assertThat(errorReporter.getErrors()).isNotEmpty();
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter)

Example 48 with ErrorReporter

use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.

the class MsgHtmlTagNodeTest method testErrorNodeReturnedWhenPhNameAttrIsMalformed.

@Test
public void testErrorNodeReturnedWhenPhNameAttrIsMalformed() {
    ErrorReporter errorReporter = ErrorReporter.createForTest();
    parseMsgHtmlTagNode("<div phname=\".+\" />", errorReporter);
    assertThat(Iterables.getOnlyElement(errorReporter.getErrors()).message()).isEqualTo("'phname' is not a valid identifier.");
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) Test(org.junit.Test)

Example 49 with ErrorReporter

use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.

the class BytecodeCompiler method compileToJar.

/**
 * Compiles all the templates in the given registry to a jar file written to the given output
 * stream.
 *
 * <p>If errors are encountered, the error reporter will be updated and we will return. The
 * contents of any data written to the sink at that point are undefined.
 *
 * @param registry All the templates to compile
 * @param reporter The error reporter
 * @param sink The output sink to write the JAR to.
 */
public static void compileToJar(TemplateRegistry registry, ErrorReporter reporter, ByteSink sink) throws IOException {
    ErrorReporter.Checkpoint checkpoint = reporter.checkpoint();
    if (reporter.errorsSince(checkpoint)) {
        return;
    }
    CompiledTemplateRegistry compilerRegistry = new CompiledTemplateRegistry(registry);
    if (reporter.errorsSince(checkpoint)) {
        return;
    }
    try (final SoyJarFileWriter writer = new SoyJarFileWriter(sink.openStream())) {
        compileTemplates(compilerRegistry, reporter, new CompilerListener<Void>() {

            @Override
            void onCompile(ClassData clazz) throws IOException {
                writer.writeEntry(clazz.type().internalName() + ".class", ByteSource.wrap(clazz.data()));
            }
        });
    }
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) ClassData(com.google.template.soy.jbcsrc.internal.ClassData) IOException(java.io.IOException) SoyJarFileWriter(com.google.template.soy.base.internal.SoyJarFileWriter)

Example 50 with ErrorReporter

use of com.google.template.soy.error.ErrorReporter in project closure-templates by google.

the class SoyDeprecatedTest method testSoyDeprecated.

@Test
public void testSoyDeprecated() throws Exception {
    ErrorReporter reporter = ErrorReporter.createForTest();
    SoyFileSetParserBuilder.forTemplateContents("{deprecated() |deprecated}").addSoyFunction(new DeprecatedFunction()).addPrintDirective(new DeprecatedPrintDirective()).errorReporter(reporter).parse();
    assertThat(reporter.getErrors()).isEmpty();
    assertThat(reporter.getWarnings()).hasSize(2);
    assertThat(reporter.getWarnings().get(0).message()).isEqualTo("deprecated is deprecated: please stop using this function.");
    assertThat(reporter.getWarnings().get(1).message()).isEqualTo("|deprecated is deprecated: please stop using this directive.");
}
Also used : ErrorReporter(com.google.template.soy.error.ErrorReporter) Test(org.junit.Test)

Aggregations

ErrorReporter (com.google.template.soy.error.ErrorReporter)70 Test (org.junit.Test)45 SoyFileSetNode (com.google.template.soy.soytree.SoyFileSetNode)19 TemplateNode (com.google.template.soy.soytree.TemplateNode)11 SoyError (com.google.template.soy.error.SoyError)7 MsgNode (com.google.template.soy.soytree.MsgNode)5 RawTextNode (com.google.template.soy.soytree.RawTextNode)3 SoyNode (com.google.template.soy.soytree.SoyNode)3 ArrayList (java.util.ArrayList)3 Point (com.google.template.soy.base.SourceLocation.Point)2 ExprNode (com.google.template.soy.exprtree.ExprNode)2 ClassData (com.google.template.soy.jbcsrc.internal.ClassData)2 SoyFileNode (com.google.template.soy.soytree.SoyFileNode)2 TemplateRegistry (com.google.template.soy.soytree.TemplateRegistry)2 Stopwatch (com.google.common.base.Stopwatch)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 SourceLocation (com.google.template.soy.base.SourceLocation)1 IncrementingIdGenerator (com.google.template.soy.base.internal.IncrementingIdGenerator)1 SoyFileSupplier (com.google.template.soy.base.internal.SoyFileSupplier)1 SoyJarFileWriter (com.google.template.soy.base.internal.SoyJarFileWriter)1