<NME> runtests.jl
<BEF> # Build the real docs first.
include(joinpath(dirname(@__FILE__), "..", "docs", "make.jl"))

# docs module
# ===========

module Mod

"""
    func(x)

[`T`](@ref)
"""
func(x) = x

"""
    T

[`func(x)`](@ref)
"""
type T end

end

# autodocs module
# ===============

"`AutoDocs` module."
module AutoDocs

module Pages

include("pages/a.jl")
include("pages/b.jl")
include("pages/c.jl")
include("pages/d.jl")
include("pages/e.jl")

end

"Function `f`."
f(x) = x

"Constant `K`."
const K = 1

"Type `T`."
type T end

"Macro `@m`."
macro m() end

"Module `A`."
module A

"Function `A.f`."
f(x) = x

"Constant `A.K`."
const K = 1

"Type `B.T`."
type T end

"Macro `B.@m`."
macro m() end

end

"Module `B`."
module B

"Function `B.f`."
f(x) = x

"Constant `B.K`."
const K = 1

"Type `B.T`."
type T end

"Macro `B.@m`."
macro m() end

end

end

module MissingDocs


    # 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

# setup
# =====

const example_root = joinpath(dirname(@__FILE__), "examples")

info("Building mock package docs: MarkdownWriter")
doc = makedocs(
    debug = true,
    root  = example_root,
    build = "build-markdown",
)

# tests
# =====

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

let build_dir  = joinpath(example_root, "build-markdown"),
    source_dir = joinpath(example_root, "src")

    @test isdir(build_dir)
    @test isdir(joinpath(build_dir, "assets"))
    )
end

@test doc.user.root   == example_root
@test doc.user.source == "src"
@test doc.user.build  == "build-markdown"
@test doc.user.clean  == true
@test doc.user.format == Documenter.Formats.Markdown

    @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("build-markdown", "lib", "functions.md"))
    let name = "Foo", path = joinpath("build-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(doc.internal.objects) == 36

info("Building mock package docs: HTMLWriter")
doc = makedocs(
    debug = true,
    root  = example_root,
    build = "build-html",
    format   = Documenter.Formats.HTML,
    sitename = "Documenter example",
    pages    = Any[
        "Home" => "index.md",
        "Manual" => [
            "man/tutorial.md",
        ],
        "Library" => [
            "lib/functions.md",
            "lib/autodocs.md",
        ]
    ]
)

# Documenter package docs:


<MSG> Move test/examples build code

Move the code of setting up the modules and building the examples docs
under examples/ to test/examples/make.jl. This allows the examples/ to
be built without calling the whole runtests.jl file. The pages/* are
considered to be part of the examples/.

The Mod and AutoDocs modules are now indented to help with readability.

Also, the output from the examples/ builds will now be stored under
test/examples/builds/<format>, instead of test/examples/build-<format>.

<DFF> @@ -1,90 +1,8 @@
 # Build the real docs first.
 include(joinpath(dirname(@__FILE__), "..", "docs", "make.jl"))
 
-# docs module
-# ===========
-
-module Mod
-
-"""
-    func(x)
-
-[`T`](@ref)
-"""
-func(x) = x
-
-"""
-    T
-
-[`func(x)`](@ref)
-"""
-type T end
-
-end
-
-# autodocs module
-# ===============
-
-"`AutoDocs` module."
-module AutoDocs
-
-module Pages
-
-include("pages/a.jl")
-include("pages/b.jl")
-include("pages/c.jl")
-include("pages/d.jl")
-include("pages/e.jl")
-
-end
-
-"Function `f`."
-f(x) = x
-
-"Constant `K`."
-const K = 1
-
-"Type `T`."
-type T end
-
-"Macro `@m`."
-macro m() end
-
-"Module `A`."
-module A
-
-"Function `A.f`."
-f(x) = x
-
-"Constant `A.K`."
-const K = 1
-
-"Type `B.T`."
-type T end
-
-"Macro `B.@m`."
-macro m() end
-
-end
-
-"Module `B`."
-module B
-
-"Function `B.f`."
-f(x) = x
-
-"Constant `B.K`."
-const K = 1
-
-"Type `B.T`."
-type T end
-
-"Macro `B.@m`."
-macro m() end
-
-end
-
-end
+# Build the example docs
+include(joinpath(dirname(@__FILE__), "examples", "make.jl"))
 
 module MissingDocs
 
@@ -380,25 +298,15 @@ for sym in [:none, :exports]
     )
 end
 
-# setup
-# =====
-
-const example_root = joinpath(dirname(@__FILE__), "examples")
-
-info("Building mock package docs: MarkdownWriter")
-doc = makedocs(
-    debug = true,
-    root  = example_root,
-    build = "build-markdown",
-)
-
 # tests
 # =====
 
+let examples_root = Main.examples_root, doc = Main.examples_markdown_doc
+
 @test isa(doc, Documenter.Documents.Document)
 
-let build_dir  = joinpath(example_root, "build-markdown"),
-    source_dir = joinpath(example_root, "src")
+let build_dir  = joinpath(examples_root, "builds", "markdown"),
+    source_dir = joinpath(examples_root, "src")
 
     @test isdir(build_dir)
     @test isdir(joinpath(build_dir, "assets"))
@@ -420,9 +328,9 @@ let build_dir  = joinpath(example_root, "build-markdown"),
     )
 end
 
-@test doc.user.root   == example_root
+@test doc.user.root   == examples_root
 @test doc.user.source == "src"
-@test doc.user.build  == "build-markdown"
+@test doc.user.build  == "builds/markdown"
 @test doc.user.clean  == true
 @test doc.user.format == Documenter.Formats.Markdown
 
@@ -441,8 +349,8 @@ let headers = doc.internal.headers
     @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("build-markdown", "lib", "functions.md"))
-    let name = "Foo", path = joinpath("build-markdown", "lib", "functions.md")
+    @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)
@@ -452,24 +360,7 @@ end
 
 @test length(doc.internal.objects) == 36
 
-info("Building mock package docs: HTMLWriter")
-doc = makedocs(
-    debug = true,
-    root  = example_root,
-    build = "build-html",
-    format   = Documenter.Formats.HTML,
-    sitename = "Documenter example",
-    pages    = Any[
-        "Home" => "index.md",
-        "Manual" => [
-            "man/tutorial.md",
-        ],
-        "Library" => [
-            "lib/functions.md",
-            "lib/autodocs.md",
-        ]
-    ]
-)
+end # for `let doc = examples_markdown_doc`
 
 # Documenter package docs:
 

Move test/examples build code