helpers: Add --trace to asciidoctor args

This will help to understand and fix errors by
seeing stacktrace of an error.

See #3714
This commit is contained in:
Vasyl Solovei 2017-07-21 12:07:56 +03:00 committed by Anthony Fok
parent ff433f9813
commit b60aa1a504
3 changed files with 35 additions and 13 deletions

View file

@ -544,36 +544,58 @@ func truncateWordsToWholeSentenceOld(content string, max int) (string, bool) {
} }
func getAsciidocExecPath() string { func getAsciidocExecPath() string {
path, err := exec.LookPath("asciidoctor") path, err := exec.LookPath("asciidoc")
if err != nil { if err != nil {
path, err = exec.LookPath("asciidoc") return ""
if err != nil {
return ""
}
} }
return path return path
} }
// HasAsciidoc returns whether Asciidoctor or Asciidoc is installed on this computer. // HasAsciidoc returns whether Asciidoc is installed on this computer.
func HasAsciidoc() bool { func HasAsciidoc() bool {
return getAsciidocExecPath() != "" return getAsciidocExecPath() != ""
} }
func getAsciidoctorExecPath() string {
path, err := exec.LookPath("asciidoctor")
if err != nil {
return ""
}
return path
}
// HasAsciidoctor returns whether Asciidoctor is installed on this computer.
func HasAsciidoctor() bool {
return getAsciidoctorExecPath() != ""
}
// getAsciidocContent calls asciidoctor or asciidoc as an external helper // getAsciidocContent calls asciidoctor or asciidoc as an external helper
// to convert AsciiDoc content to HTML. // to convert AsciiDoc content to HTML.
func getAsciidocContent(ctx *RenderingContext) []byte { func getAsciidocContent(ctx *RenderingContext) []byte {
content := ctx.Content content := ctx.Content
cleanContent := bytes.Replace(content, SummaryDivider, []byte(""), 1) cleanContent := bytes.Replace(content, SummaryDivider, []byte(""), 1)
path := getAsciidocExecPath() var isAsciidoctor bool
path := getAsciidoctorExecPath()
if path == "" { if path == "" {
jww.ERROR.Println("asciidoctor / asciidoc not found in $PATH: Please install.\n", path = getAsciidocExecPath()
" Leaving AsciiDoc content unrendered.") if path == "" {
return content jww.ERROR.Println("asciidoctor / asciidoc not found in $PATH: Please install.\n",
" Leaving AsciiDoc content unrendered.")
return content
}
} else {
isAsciidoctor = true
} }
jww.INFO.Println("Rendering", ctx.DocumentName, "with", path, "...") jww.INFO.Println("Rendering", ctx.DocumentName, "with", path, "...")
cmd := exec.Command(path, "--no-header-footer", "--safe", "-") args := []string{"--no-header-footer", "--safe"}
if isAsciidoctor {
// asciidoctor-specific arg to show stack traces on errors
args = append(args, "--trace")
}
args = append(args, "-")
cmd := exec.Command(path, args...)
cmd.Stdin = bytes.NewReader(cleanContent) cmd.Stdin = bytes.NewReader(cleanContent)
var out, cmderr bytes.Buffer var out, cmderr bytes.Buffer
cmd.Stdout = &out cmd.Stdout = &out

View file

@ -561,7 +561,7 @@ func testAllMarkdownEnginesForPages(t *testing.T,
}{ }{
{"md", func() bool { return true }}, {"md", func() bool { return true }},
{"mmark", func() bool { return true }}, {"mmark", func() bool { return true }},
{"ad", func() bool { return helpers.HasAsciidoc() }}, {"ad", func() bool { return helpers.HasAsciidoctor() || helpers.HasAsciidoc() }},
// TODO(bep) figure a way to include this without too much work.{"html", func() bool { return true }}, // TODO(bep) figure a way to include this without too much work.{"html", func() bool { return true }},
{"rst", func() bool { return helpers.HasRst() }}, {"rst", func() bool { return helpers.HasRst() }},
} }

View file

@ -555,7 +555,7 @@ tags:
th := testHelper{s.Cfg, s.Fs, t} th := testHelper{s.Cfg, s.Fs, t}
for _, test := range tests { for _, test := range tests {
if strings.HasSuffix(test.contentPath, ".ad") && !helpers.HasAsciidoc() { if strings.HasSuffix(test.contentPath, ".ad") && !helpers.HasAsciidoctor() && !helpers.HasAsciidoc() {
fmt.Println("Skip Asciidoc test case as no Asciidoc present.") fmt.Println("Skip Asciidoc test case as no Asciidoc present.")
continue continue
} else if strings.HasSuffix(test.contentPath, ".rst") && !helpers.HasRst() { } else if strings.HasSuffix(test.contentPath, ".rst") && !helpers.HasRst() {