From f75cf925ca48578ceb61ccb20e9504223c37b829 Mon Sep 17 00:00:00 2001 From: Twan Koolen Date: Wed, 10 Oct 2018 16:15:59 -0400 Subject: [PATCH 1/2] Fix Utilities.submodules for module aliases (#852) Fix #851, module aliases confuse Utilities.submodules. (cherry picked from commit fdddf002d7c6ede50076d3be42235c7ed284c431) --- src/Utilities/Utilities.jl | 2 +- test/utilities.jl | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Utilities/Utilities.jl b/src/Utilities/Utilities.jl index fc47cf9940..e49c7598df 100644 --- a/src/Utilities/Utilities.jl +++ b/src/Utilities/Utilities.jl @@ -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 diff --git a/test/utilities.jl b/test/utilities.jl index b3b4c0883f..058816c4af 100644 --- a/test/utilities.jl +++ b/test/utilities.jl @@ -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}()) @@ -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 From 1abf4361ac0627974505ceeeb2651cc87576ebea Mon Sep 17 00:00:00 2001 From: Morten Piibeleht Date: Wed, 24 Oct 2018 16:24:13 -0700 Subject: [PATCH 2/2] Fix tests for non-dev environment (#860) Create a temporary Git repo to run tests in. (cherry picked from commit 837a4c47d6a8859846da97587a0e0e86d554dd29) --- test/utilities.jl | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/test/utilities.jl b/test/utilities.jl index 058816c4af..5a94070f14 100644 --- a/test/utilities.jl +++ b/test/utilities.jl @@ -135,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()