diff --git a/asciidoctorj-core/src/main/java/org/asciidoctor/cli/AsciidoctorInvoker.java b/asciidoctorj-core/src/main/java/org/asciidoctor/cli/AsciidoctorInvoker.java index 70d4ac8b3..215753a44 100644 --- a/asciidoctorj-core/src/main/java/org/asciidoctor/cli/AsciidoctorInvoker.java +++ b/asciidoctorj-core/src/main/java/org/asciidoctor/cli/AsciidoctorInvoker.java @@ -39,7 +39,11 @@ public void invoke(String... parameters) { System.out.println("Asciidoctor " + asciidoctor.asciidoctorVersion() + " [http://asciidoctor.org]"); return; } - + + if (asciidoctorCliOptions.isVerbose()) { + JRubyRuntimeContext.get().evalScriptlet("$VERBOSE=true"); + } + List inputFiles = getInputFiles(asciidoctorCliOptions); if (inputFiles.isEmpty()) { diff --git a/asciidoctorj-core/src/main/resources/org/asciidoctor/internal/asciidoctorclass.rb b/asciidoctorj-core/src/main/resources/org/asciidoctor/internal/asciidoctorclass.rb index 4b3610e5c..f05927e8f 100644 --- a/asciidoctorj-core/src/main/resources/org/asciidoctor/internal/asciidoctorclass.rb +++ b/asciidoctorj-core/src/main/resources/org/asciidoctor/internal/asciidoctorclass.rb @@ -1,6 +1,3 @@ -# Set the global variable VERBOSE to true to get invalid refs into the log -#$VERBOSE=true - module AsciidoctorJ include_package 'org.asciidoctor' module Extensions diff --git a/asciidoctorj-core/src/test/java/org/asciidoctor/WhenAsciidoctorLogsToConsole.java b/asciidoctorj-core/src/test/java/org/asciidoctor/WhenAsciidoctorLogsToConsole.java index 19ef62e3d..2a68a9d4a 100644 --- a/asciidoctorj-core/src/test/java/org/asciidoctor/WhenAsciidoctorLogsToConsole.java +++ b/asciidoctorj-core/src/test/java/org/asciidoctor/WhenAsciidoctorLogsToConsole.java @@ -2,16 +2,19 @@ import org.asciidoctor.ast.Cursor; import org.asciidoctor.internal.JRubyAsciidoctor; +import org.asciidoctor.internal.JRubyRuntimeContext; import org.asciidoctor.log.LogHandler; import org.asciidoctor.log.LogRecord; import org.asciidoctor.log.TestLogHandlerService; import org.asciidoctor.util.ClasspathResources; import org.junit.After; import org.junit.Before; +import org.junit.FixMethodOrder; import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; +import org.junit.runners.MethodSorters; import java.io.File; import java.io.IOException; @@ -30,6 +33,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; +@FixMethodOrder(MethodSorters.NAME_ASCENDING) public class WhenAsciidoctorLogsToConsole { @Rule @@ -122,7 +126,6 @@ public void log(LogRecord logRecord) { } @Test - @Ignore("Until invalid refs are logged by default") public void shouldLogInvalidRefs() throws Exception { final List logRecords = new ArrayList<>(); @@ -135,6 +138,9 @@ public void log(LogRecord logRecord) { }; asciidoctor.registerLogHandler(logHandler); + // Asciidoctor currently only logs invalid refs if this global var is set + JRubyRuntimeContext.get().evalScriptlet("$VERBOSE=true"); + File inputFile = classpath.getResource("documentwithinvalidrefs.adoc"); String renderContent = asciidoctor.renderFile(inputFile, options() @@ -151,6 +157,32 @@ public void log(LogRecord logRecord) { assertThat(cursor, is(nullValue())); } + @Test + public void shouldNotLogInvalidRefsWithoutVerbose() throws Exception { + + final List logRecords = new ArrayList<>(); + + final LogHandler logHandler = new LogHandler() { + @Override + public void log(LogRecord logRecord) { + logRecords.add(logRecord); + } + }; + asciidoctor.registerLogHandler(logHandler); + + File inputFile = classpath.getResource("documentwithinvalidrefs.adoc"); + String renderContent = asciidoctor.renderFile(inputFile, + options() + .inPlace(true) + .safe(SafeMode.SERVER) + .toFile(false) + .attributes( + AttributesBuilder.attributes().allowUriRead(true)) + .asMap()); + + assertThat(logRecords, hasSize(0)); + } + @Test public void shouldOnlyNotifyFromRegisteredAsciidoctor() throws Exception {