<NME> runtests.jl
<BEF> using Test
import Documenter
include("TestUtilities.jl"); using Main.TestUtilities

@testset "Documenter" begin
    # Build the example docs
    @info "Building example/make.jl"
    include("examples/make.jl")

    # Test missing docs
    @info "Building missingdocs/make.jl"
    include("missingdocs/make.jl")

    # Error reporting.
    @info "Building errors/make.jl"
    @quietly include("errors/make.jl")

    # Unit tests for module internals.
    include("except.jl")
    include("utilities.jl")
    include("remotes.jl")

    # DocChecks tests
    include("docchecks.jl")

    # NavNode tests.
    include("navnode.jl")

    # DocSystem unit tests.
    include("docsystem.jl")

    # CrossReferences
    include("crossreferences.jl")

    # DocTest unit tests.
    @info "Running tests in doctests/"
    include("doctests/docmeta.jl")
    include("doctests/doctestapi.jl")
    include("doctests/doctests.jl")
    include("doctests/fix/tests.jl")

    # DOM Tests.
    include("dom.jl")

    # MDFlatten tests.
    include("mdflatten.jl")

    # Main build pipeline (Builder and Expanders modules)
    include("pipeline.jl")

    # HTMLWriter
    include("htmlwriter.jl")

    # LaTeXWriter
    include("latexwriter.jl")

    # Deployment configurations
    include("deployconfig.jl")
    include("deploydocs.jl")

    # Mock package docs.
    include("examples/tests.jl")

    # A simple build outside of a Git repository
    @info "Building nongit/tests.jl"
    @quietly include("nongit/tests.jl")

    # A simple build evaluating code outside build directory
    @info "Building workdir/tests.jl"
    @quietly include("workdir/tests.jl")

    # Passing a writer positionally (https://github.com/JuliaDocs/Documenter.jl/issues/1046)
    @test_throws ArgumentError makedocs(sitename="", HTML())

    # Running doctest() on our own manual
    @info "doctest() Documenter's manual"
    @quietly include("manual.jl")
end
    )
end

# tests
# =====

let examples_root = Main.examples_root, doc = Main.examples_markdown_doc

@test isa(doc, Documenter.Documents.Document)

let build_dir  = joinpath(examples_root, "builds", "markdown"),
    source_dir = joinpath(examples_root, "src")

    @test isdir(build_dir)
    @test isdir(joinpath(build_dir, "assets"))
    @test isdir(joinpath(build_dir, "lib"))
    @test isdir(joinpath(build_dir, "man"))

    @test isfile(joinpath(build_dir, "index.md"))
    @test isfile(joinpath(build_dir, "assets", "mathjaxhelper.js"))
    @test isfile(joinpath(build_dir, "assets", "Documenter.css"))
    @test isfile(joinpath(build_dir, "assets", "custom.css"))
    @test isfile(joinpath(build_dir, "assets", "custom.js"))
    @test isfile(joinpath(build_dir, "lib", "functions.md"))
    @test isfile(joinpath(build_dir, "man", "tutorial.md"))
    @test isfile(joinpath(build_dir, "man", "data.csv"))

    @test (==)(
        readstring(joinpath(source_dir, "man", "data.csv")),
        readstring(joinpath(build_dir,  "man", "data.csv")),
    )
end

@test doc.user.root   == examples_root
@test doc.user.source == "src"
@test doc.user.build  == "builds/markdown"
@test doc.user.clean  == true
@test doc.user.format == Documenter.Formats.Markdown

@test doc.internal.assets == normpath(joinpath(dirname(@__FILE__), "..", "assets"))

@test length(doc.internal.pages) == 5

let headers = doc.internal.headers
    @test Documenter.Anchors.exists(headers, "Documentation")
    @test Documenter.Anchors.exists(headers, "Documentation")
    @test Documenter.Anchors.exists(headers, "Index-Page")
    @test Documenter.Anchors.exists(headers, "Functions-Contents")
    @test Documenter.Anchors.exists(headers, "Tutorial-Contents")
    @test Documenter.Anchors.exists(headers, "Index")
    @test Documenter.Anchors.exists(headers, "Tutorial")
    @test Documenter.Anchors.exists(headers, "Function-Index")
    @test Documenter.Anchors.exists(headers, "Functions")
    @test Documenter.Anchors.isunique(headers, "Functions")
    @test Documenter.Anchors.isunique(headers, "Functions", joinpath("builds", "markdown", "lib", "functions.md"))
    let name = "Foo", path = joinpath("builds", "markdown", "lib", "functions.md")
        @test Documenter.Anchors.exists(headers, name, path)
        @test !Documenter.Anchors.isunique(headers, name)
        @test !Documenter.Anchors.isunique(headers, name, path)
        @test length(headers.map[name][path]) == 4
    end
end

@test length(doc.internal.objects) == 36

end # for `let doc = examples_markdown_doc`

# Documenter package docs:


<MSG> Move examples/ tests to a separate file

Moves the tests of the examples/ build to examples/tests.jl. The tests
can be run separately as well.

<DFF> @@ -298,69 +298,7 @@ for sym in [:none, :exports]
     )
 end
 
-# tests
-# =====
-
-let examples_root = Main.examples_root, doc = Main.examples_markdown_doc
-
-@test isa(doc, Documenter.Documents.Document)
-
-let build_dir  = joinpath(examples_root, "builds", "markdown"),
-    source_dir = joinpath(examples_root, "src")
-
-    @test isdir(build_dir)
-    @test isdir(joinpath(build_dir, "assets"))
-    @test isdir(joinpath(build_dir, "lib"))
-    @test isdir(joinpath(build_dir, "man"))
-
-    @test isfile(joinpath(build_dir, "index.md"))
-    @test isfile(joinpath(build_dir, "assets", "mathjaxhelper.js"))
-    @test isfile(joinpath(build_dir, "assets", "Documenter.css"))
-    @test isfile(joinpath(build_dir, "assets", "custom.css"))
-    @test isfile(joinpath(build_dir, "assets", "custom.js"))
-    @test isfile(joinpath(build_dir, "lib", "functions.md"))
-    @test isfile(joinpath(build_dir, "man", "tutorial.md"))
-    @test isfile(joinpath(build_dir, "man", "data.csv"))
-
-    @test (==)(
-        readstring(joinpath(source_dir, "man", "data.csv")),
-        readstring(joinpath(build_dir,  "man", "data.csv")),
-    )
-end
-
-@test doc.user.root   == examples_root
-@test doc.user.source == "src"
-@test doc.user.build  == "builds/markdown"
-@test doc.user.clean  == true
-@test doc.user.format == Documenter.Formats.Markdown
-
-@test doc.internal.assets == normpath(joinpath(dirname(@__FILE__), "..", "assets"))
-
-@test length(doc.internal.pages) == 5
-
-let headers = doc.internal.headers
-    @test Documenter.Anchors.exists(headers, "Documentation")
-    @test Documenter.Anchors.exists(headers, "Documentation")
-    @test Documenter.Anchors.exists(headers, "Index-Page")
-    @test Documenter.Anchors.exists(headers, "Functions-Contents")
-    @test Documenter.Anchors.exists(headers, "Tutorial-Contents")
-    @test Documenter.Anchors.exists(headers, "Index")
-    @test Documenter.Anchors.exists(headers, "Tutorial")
-    @test Documenter.Anchors.exists(headers, "Function-Index")
-    @test Documenter.Anchors.exists(headers, "Functions")
-    @test Documenter.Anchors.isunique(headers, "Functions")
-    @test Documenter.Anchors.isunique(headers, "Functions", joinpath("builds", "markdown", "lib", "functions.md"))
-    let name = "Foo", path = joinpath("builds", "markdown", "lib", "functions.md")
-        @test Documenter.Anchors.exists(headers, name, path)
-        @test !Documenter.Anchors.isunique(headers, name)
-        @test !Documenter.Anchors.isunique(headers, name, path)
-        @test length(headers.map[name][path]) == 4
-    end
-end
-
-@test length(doc.internal.objects) == 36
-
-end # for `let doc = examples_markdown_doc`
+include(joinpath(dirname(@__FILE__), "examples", "tests.jl"))
 
 # Documenter package docs:
 

Move examples/ tests to a separate file