Skip to content

Commit

Permalink
Merge pull request #859 from JuliaDocs/backports-0.19.7
Browse files Browse the repository at this point in the history
Backports for 0.19.7 (2)
  • Loading branch information
mortenpi authored Oct 25, 2018
2 parents af989ce + 1abf436 commit cc75bdf
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Utilities/Utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ function submodules(root::Module, seen = Set{Module}())
for name in Compat.names(root, all=true)
if Base.isidentifier(name) && isdefined(root, name) && !isdeprecated(root, name)
object = getfield(root, name)
if isa(object, Module) && !(object in seen)
if isa(object, Module) && !(object in seen) && parentmodule(object::Module) == root
submodules(object, seen)
end
end
Expand Down
53 changes: 41 additions & 12 deletions test/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ export OuterModule
end
end

module ExternalModule end
module ModuleWithAliases
using ..ExternalModule
Y = ExternalModule
module A
module B
const X = Main
end
end
end

@testset "Utilities" begin
let doc = @doc(length)
a = Documenter.Utilities.filterdocs(doc, Set{Module}())
Expand Down Expand Up @@ -69,6 +80,7 @@ end
@test OuterModule in Documenter.Utilities.submodules(OuterModule)
@test OuterModule.InnerModule in Documenter.Utilities.submodules(OuterModule)
@test length(Documenter.Utilities.submodules(OuterModule)) == 2
@test Documenter.Utilities.submodules(ModuleWithAliases) == Set([ModuleWithAliases, ModuleWithAliases.A, ModuleWithAliases.A.B])

@test Documenter.Utilities.isabsurl("file.md") === false
@test Documenter.Utilities.isabsurl("../file.md") === false
Expand Down Expand Up @@ -123,18 +135,35 @@ end
@test endswith(filepath, expected_filepath)
@show filepath expected_filepath
end
commit = Documenter.Utilities.repo_commit(filepath)

@test Documenter.Utilities.url("//blob/{commit}{path}#{line}", filepath) == "//blob/$(commit)/src/Utilities/Utilities.jl#"
@test Documenter.Utilities.url(nothing, "//blob/{commit}{path}#{line}", Documenter.Utilities, filepath, 10:20) == "//blob/$(commit)/src/Utilities/Utilities.jl#L10-L20"

# repo_root & relpath_from_repo_root
@test Documenter.Utilities.repo_root(@__FILE__) == dirname(abspath(joinpath(@__DIR__, ".."))) # abspath() keeps trailing /, hence dirname()
@test Documenter.Utilities.repo_root(@__FILE__; dbdir=".svn") == nothing
@test Documenter.Utilities.relpath_from_repo_root(@__FILE__) == joinpath("test", "utilities.jl")
# We assume that a temporary file is not in a repo
@test Documenter.Utilities.repo_root(tempname()) == nothing
@test Documenter.Utilities.relpath_from_repo_root(tempname()) == nothing

mktempdir() do path
cd(path) do
# Create a simple mock repo in a temporary directory with a single file.
@test success(`git init`)
@test success(`git config user.email "tester@example.com"`)
@test success(`git config user.name "Test Committer"`)
@test success(`git remote add origin git@github.com:JuliaDocs/Documenter.jl.git`)
mkpath("src")
filepath = abspath(joinpath("src", "SourceFile.jl"))
write(filepath, "X")
@test success(`git add -A`)
@test success(`git commit -m"Initial commit."`)

# Run tests
commit = Documenter.Utilities.repo_commit(filepath)

@test Documenter.Utilities.url("//blob/{commit}{path}#{line}", filepath) == "//blob/$(commit)/src/SourceFile.jl#"
@test Documenter.Utilities.url(nothing, "//blob/{commit}{path}#{line}", Documenter.Utilities, filepath, 10:20) == "//blob/$(commit)/src/SourceFile.jl#L10-L20"

# repo_root & relpath_from_repo_root
@test Documenter.Utilities.repo_root(filepath) == dirname(abspath(joinpath(dirname(filepath), ".."))) # abspath() keeps trailing /, hence dirname()
@test Documenter.Utilities.repo_root(filepath; dbdir=".svn") == nothing
@test Documenter.Utilities.relpath_from_repo_root(filepath) == joinpath("src", "SourceFile.jl")
# We assume that a temporary file is not in a repo
@test Documenter.Utilities.repo_root(tempname()) == nothing
@test Documenter.Utilities.relpath_from_repo_root(tempname()) == nothing
end
end

import Documenter.Documents: Document, Page, Globals
let page = Page("source", "build", [], IdDict(), Globals()), doc = Document()
Expand Down

0 comments on commit cc75bdf

Please sign in to comment.