Skip to content

Commit

Permalink
Fix tests for non-dev environment (#860)
Browse files Browse the repository at this point in the history
Create a temporary Git repo to run tests in.

(cherry picked from commit 837a4c4)
  • Loading branch information
mortenpi committed Oct 24, 2018
1 parent f75cf92 commit 1abf436
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions test/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 1abf436

Please sign in to comment.