Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable automatic logging of invalid refs and enable it via verbose m… #689

Merged
merged 2 commits into from
Oct 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<File> inputFiles = getInputFiles(asciidoctorCliOptions);

if (inputFiles.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,6 +33,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class WhenAsciidoctorLogsToConsole {

@Rule
Expand Down Expand Up @@ -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<LogRecord> logRecords = new ArrayList<>();
Expand All @@ -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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this need to be unset again after the test is run? Or do tests not share the JRuby runtime context?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be fine, hopefully.
Every Asciidoctor instance gets its own JRuby instance and should have it's own global state if I am not wrong.
But definitely sth to retest.


File inputFile = classpath.getResource("documentwithinvalidrefs.adoc");
String renderContent = asciidoctor.renderFile(inputFile,
options()
Expand All @@ -151,6 +157,32 @@ public void log(LogRecord logRecord) {
assertThat(cursor, is(nullValue()));
}

@Test
public void shouldNotLogInvalidRefsWithoutVerbose() throws Exception {

final List<LogRecord> 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 {

Expand Down