<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

rm(joinpath(Documenter_root, "build"); recursive = true)

# Try generating documentation with generate()

pkg_generate = if VERSION >= v"0.5-"
    isdir(Pkg.dir("PkgDev")) || Pkg.add("PkgDev")
    import PkgDev
    PkgDev.generate
else
    Pkg.generate
end

const testpkgname = "DocumenterTestPackage"

function check_generated_files(path)
    @test isdir(path)
    @test isfile(joinpath(path, "mkdocs.yml"))
    @test isfile(joinpath(path, ".gitignore"))
    @test isfile(joinpath(path, "make.jl"))
    @test isdir(joinpath(path, "src"))
    @test isfile(joinpath(path, "src", "index.md"))
end

if ispath(Pkg.dir(testpkgname))
    error("A package is already installed at $(Pkg.dir(testpkgname))")
else
    try
        pkg_generate(testpkgname,"MIT",config=Dict("user.name"=>"Julia Test", "user.email"=>"tests@docs.julia"))
        Documenter.generate(testpkgname)
        check_generated_files(Pkg.dir(testpkgname,"docs"))
    finally
        Pkg.rm(testpkgname)
    end
end

# try generating at a custom location
let path = joinpath(Pkg.dir("Documenter"), "test", "docs")
    Documenter.generate(testpkgname, dir=path)
    check_generated_files(path)
    rm(path,recursive=true)
end

end


<MSG> Remove PkgDev dep

Just test against a mock package. Also test that `generate` throws
errors on bad input.

Replace macro `mkdocs_defaults` with a function.

<DFF> @@ -432,45 +432,20 @@ end
 
 rm(joinpath(Documenter_root, "build"); recursive = true)
 
-# Try generating documentation with generate()
-
-pkg_generate = if VERSION >= v"0.5-"
-    isdir(Pkg.dir("PkgDev")) || Pkg.add("PkgDev")
-    import PkgDev
-    PkgDev.generate
-else
-    Pkg.generate
-end
-
-const testpkgname = "DocumenterTestPackage"
-
-function check_generated_files(path)
-    @test isdir(path)
-    @test isfile(joinpath(path, "mkdocs.yml"))
-    @test isfile(joinpath(path, ".gitignore"))
-    @test isfile(joinpath(path, "make.jl"))
-    @test isdir(joinpath(path, "src"))
-    @test isfile(joinpath(path, "src", "index.md"))
-end
-
-if ispath(Pkg.dir(testpkgname))
-    error("A package is already installed at $(Pkg.dir(testpkgname))")
-else
-    try
-        pkg_generate(testpkgname,"MIT",config=Dict("user.name"=>"Julia Test", "user.email"=>"tests@docs.julia"))
-        Documenter.generate(testpkgname)
-        check_generated_files(Pkg.dir(testpkgname,"docs"))
-    finally
-        Pkg.rm(testpkgname)
+mktempdir() do root
+    let path = joinpath(root, "docs")
+        Documenter.generate("DocumenterTestPackage", dir = path)
+        @test isdir(path)
+        @test isfile(joinpath(path, "mkdocs.yml"))
+        @test isfile(joinpath(path, ".gitignore"))
+        @test isfile(joinpath(path, "make.jl"))
+        @test isdir(joinpath(path, "src"))
+        @test isfile(joinpath(path, "src", "index.md"))
     end
 end
 
-# try generating at a custom location
-let path = joinpath(Pkg.dir("Documenter"), "test", "docs")
-    Documenter.generate(testpkgname, dir=path)
-    check_generated_files(path)
-    rm(path,recursive=true)
-end
+@test_throws ErrorException Documenter.generate("Documenter")
+@test_throws ErrorException Documenter.generate(randstring())
 
 end
 

Remove PkgDev dep