From 885cb7c2af74dbd4ad8fcf6bdd6cf99ad5e5a4e0 Mon Sep 17 00:00:00 2001 From: Morten Piibeleht Date: Sun, 27 Oct 2019 11:45:55 +0100 Subject: [PATCH] Test LaTeX backend on Travis --- .travis.yml | 7 ++++- test/TestUtilities.jl | 19 ++++++++++++++ test/examples/make.jl | 35 +++++++++++++++++++++++++ test/examples/src.latex_simple/index.md | 4 +++ test/examples/tests_latex.jl | 27 +++++++++++++++++++ 5 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 test/examples/src.latex_simple/index.md create mode 100644 test/examples/tests_latex.jl diff --git a/.travis.yml b/.travis.yml index a5da0db3f77..3c7c1ae673f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,10 +30,15 @@ after_success: jobs: include: - - stage: "Themes" + - stage: "Additional tests" script: - julia --project=test/themes -e 'using Pkg; Pkg.instantiate(); Pkg.develop(PackageSpec(path=pwd()))' - julia --project=test/themes test/themes/themes.jl + name: "Themes" + - script: + - julia --project=test/examples -e 'using Pkg; Pkg.instantiate(); Pkg.develop(PackageSpec(path=pwd())); Pkg.add("DocumenterMarkdown")' + - julia --project=test/examples test/examples/tests_latex.jl + name: "PDF/LaTeX backend" - stage: "Documentation" script: - julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()' diff --git a/test/TestUtilities.jl b/test/TestUtilities.jl index 49e8c1c12d3..7e9b20ef2a3 100644 --- a/test/TestUtilities.jl +++ b/test/TestUtilities.jl @@ -4,6 +4,10 @@ using Documenter.Utilities: withoutput export @quietly +const QUIETLY_LOG = joinpath(@__DIR__, "quietly.log") + +__init__() = isfile(QUIETLY_LOG) && rm(QUIETLY_LOG) + struct QuietlyException <: Exception exception backtrace @@ -16,6 +20,21 @@ end function _quietly(f, expr, source) result, success, backtrace, output = withoutput(f) + haskey(ENV, "DOCUMENTER_TEST_QUIETLY") && open(QUIETLY_LOG; write=true, append=true) do io + println(io, "@quietly: success = $(success) / $(sizeof(output)) bytes of output captured") + println(io, "@quietly: $(source.file):$(source.line)") + println(io, "@quietly: typeof(result) = ", typeof(result)) + println(io, "@quietly: STDOUT") + println(io, output) + println(io, "@quietly: end of STDOUT") + if success + println(io, "@quietly: result =") + println(io, result) + else + println(io, "@quietly: result (error) =") + showerror(io, result, backtrace) + end + end if success printstyled("@quietly: success, $(sizeof(output)) bytes of output hidden\n"; color=:magenta) return result diff --git a/test/examples/make.jl b/test/examples/make.jl index a651d1a9cc4..672943858eb 100644 --- a/test/examples/make.jl +++ b/test/examples/make.jl @@ -241,3 +241,38 @@ else @info "Skipping build: Markdown" EXAMPLE_BUILDS get(ENV, "DOCUMENTER_TEST_EXAMPLES", nothing) nothing end + +# PDF/LaTeX +examples_latex_simple_doc = if "latex_simple" in EXAMPLE_BUILDS + @info("Building mock package docs: LaTeXWriter/simple") + @quietly makedocs( + format = Documenter.Writers.LaTeXWriter.LaTeX(platform = "docker"), + sitename = "Documenter LaTeX Simple", + root = examples_root, + build = "builds/latex_simple", + source = "src.latex_simple", + pages = ["Main section" => ["index.md"]], + doctest = false, + debug = true, + ) +else + @info "Skipping build: LaTeXWriter/simple" EXAMPLE_BUILDS get(ENV, "DOCUMENTER_TEST_EXAMPLES", nothing) + nothing +end + +examples_latex_simple_nondocker_doc = if "latex_simple_nondocker" in EXAMPLE_BUILDS + @info("Building mock package docs: LaTeXWriter/latex_simple_nondocker") + @quietly makedocs( + format = Documenter.Writers.LaTeXWriter.LaTeX(), + sitename = "Documenter LaTeX Simple Non-Docker", + root = examples_root, + build = "builds/latex_simple_nondocker", + source = "src.latex_simple", + pages = ["Main section" => ["index.md"]], + doctest = false, + debug = true, + ) +else + @info "Skipping build: LaTeXWriter/latex_simple_nondocker" EXAMPLE_BUILDS get(ENV, "DOCUMENTER_TEST_EXAMPLES", nothing) + nothing +end diff --git a/test/examples/src.latex_simple/index.md b/test/examples/src.latex_simple/index.md new file mode 100644 index 00000000000..cc21fdbf5fd --- /dev/null +++ b/test/examples/src.latex_simple/index.md @@ -0,0 +1,4 @@ +# Simple LaTeX build + +This build only contains a single paragraph of text to make sure that a +near-empty LaTeX builds passes. diff --git a/test/examples/tests_latex.jl b/test/examples/tests_latex.jl new file mode 100644 index 00000000000..a4925923dd4 --- /dev/null +++ b/test/examples/tests_latex.jl @@ -0,0 +1,27 @@ +using Test + +# DOCUMENTER_TEST_EXAMPLES can be used to control which builds are performed in +# make.jl, and we need to set it to the relevant LaTeX builds. +ENV["DOCUMENTER_TEST_EXAMPLES"] = "latex_simple" + +# When the file is run separately we need to include make.jl which actually builds +# the docs and defines a few modules that are referred to in the docs. The make.jl +# has to be expected in the context of the Main module. +if (@__MODULE__) === Main && !@isdefined examples_root + include("make.jl") +elseif (@__MODULE__) !== Main && isdefined(Main, :examples_root) + using Documenter + const examples_root = Main.examples_root +elseif (@__MODULE__) !== Main && !isdefined(Main, :examples_root) + error("examples/make.jl has not been loaded into Main.") +end + +@testset "Examples/LaTeX" begin + @testset "PDF/LaTeX: simple" begin + doc = Main.examples_latex_simple_doc + @test isa(doc, Documenter.Documents.Document) + let build_dir = joinpath(examples_root, "builds", "latex_simple") + @test joinpath(build_dir, "DocumenterLaTeXSimple.pdf") |> isfile + end + end +end