Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tests less noisy and actually test logging messages #94

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/genkeys.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ssh-rsa AAAAB3NzaC2yc2EAAAaDAQABAAABAQDrNsUZYBWJtXYUk21wxZbX3KxcH8EqzR3ZdTna0Wgk
LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlFb3dJQkFBS0NBUUVBNnpiRkdXQVZpYlIy...QkVBRWFjY3BxaW9uNjFLaVdOcDU5T2YrUkdmCi0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg==
```
"""
function genkeys(; user="\$USER", repo="\$REPO")
function genkeys(; user="\$USER", repo="\$REPO", io::IO=stdout)
sshkeygen = ssh_keygen()

filename = "documenter-private-key"
Expand All @@ -73,7 +73,7 @@ function genkeys(; user="\$USER", repo="\$REPO")
Add the key below as a new 'Deploy key' on GitHub ($url) with read and write access.
The 'Title' field can be left empty as GitHub can infer it from the key comment.
"""
println("\n", read("$filename.pub", String))
println(io, "\n", read("$filename.pub", String))
end

# Base64 encode the private key and prompt user to add it to travis. The key is
Expand All @@ -82,7 +82,7 @@ function genkeys(; user="\$USER", repo="\$REPO")
let github_url = "https://github.com/$user/$repo/settings/secrets"
@info("Add a secure 'Repository secret' named 'DOCUMENTER_KEY' " *
"(to $(github_url) if you deploy using GitHub Actions) with value:")
println("\n", base64encode(read(filename, String)), "\n")
println(io, "\n", base64encode(read(filename, String)), "\n")
end
catch e
@error """
Expand Down Expand Up @@ -137,7 +137,7 @@ ssh-rsa AAAAB3NzaC2yc2EAAAaDAQABAAABAQDrNsUZYBWJtXYUk21wxZbX3KxcH8EqzR3ZdTna0Wgk
LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlFb3dJQkFBS0NBUUVBNnpiRkdXQVZpYlIy...QkVBRWFjY3BxaW9uNjFLaVdOcDU5T2YrUkdmCi0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg==
```
"""
function genkeys(package::Module; remote="origin")
function genkeys(package::Module; remote="origin", io::IO=stdout)
# Error checking. Do the required programs exist?
if Sys.iswindows()
success(`where where`) || error("'where' not found.")
Expand All @@ -161,5 +161,5 @@ function genkeys(package::Module; remote="origin")
end

# Generate the ssh key pair.
genkeys(; user=user, repo=repo)
genkeys(; user=user, repo=repo, io=io)
end
6 changes: 3 additions & 3 deletions test/generate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ using Example
Pkg.generate("Pkg1")
Pkg.develop(PackageSpec(path = "Pkg1"))
@eval using Pkg1
DocumenterTools.generate(Pkg1; format = :html)
@test_logs (:info, r"deploying documentation to") (:info, r"Generating \.gitignore") (:info, r"Generating make\.jl") (:info, r"Generating Project\.toml") (:info, r"Generating src/index\.md") DocumenterTools.generate(Pkg1; format = :html)
check_docdir(joinpath("Pkg1", "docs"); format = :html)
@test_throws ArgumentError DocumenterTools.generate(Pkg1)
Pkg.rm(PackageSpec("Pkg1"))

# generate from path
Pkg.generate("Pkg2")
DocumenterTools.generate(joinpath("Pkg2", "docs"); format = :markdown)
@test_logs (:info, r"name of package automatically determined to be") (:info, r"deploying documentation to") (:info, r"Generating \.gitignore") (:info, r"Generating make\.jl") (:info, r"Generating mkdocs\.yml") (:info, r"Generating Project\.toml") (:info, r"Generating src/index\.md") DocumenterTools.generate(joinpath("Pkg2", "docs"); format = :markdown)
check_docdir(joinpath("Pkg2", "docs"); format = :markdown)
@test_throws ArgumentError DocumenterTools.generate(joinpath("Pkg2", "docs"))

Expand All @@ -39,7 +39,7 @@ using Example
write(joinpath("Pkg3", "src", "Pkg3.jl"), "module Pkg3\nend\n")
write(joinpath("Pkg3", "src", "Pkg4.jl"), "module Pkg4\nend\n")
@test_throws ArgumentError DocumenterTools.generate(joinpath("Pkg3", "docs"))
DocumenterTools.generate(joinpath("Pkg3", "docs"); name = "Pkg3", format = :pdf)
@test_logs (:info, r"deploying documentation to") (:info, r"Generating \.gitignore") (:info, r"Generating make\.jl") (:info, r"Generating Project\.toml") (:info, r"Generating src/index\.md") DocumenterTools.generate(joinpath("Pkg3", "docs"); name = "Pkg3", format = :pdf)
check_docdir(joinpath("Pkg3", "docs"), format = :pdf)

# throw for a package that is installed and not deved
Expand Down
2 changes: 1 addition & 1 deletion test/outdated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mktempdir() do TMP

transient_path = joinpath(TMP, "fixtures", "transient")
cp(joinpath(TMP, "fixtures", "pre"), transient_path, force=true)
OutdatedWarning.generate(transient_path)
@test_logs (:warn, r"Adding an `OutdatedWarning`") OutdatedWarning.generate(transient_path)

for (root, _, files) in walkdir(transient_path)
for file in files
Expand Down
6 changes: 3 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ import Documenter

@testset "genkeys-added" begin
using Example
DocumenterTools.genkeys(user="JuliaLang", repo="[email protected]:JuliaLang/Example.jl.git")
@test_logs (:info, r"Add the key below") (:info, r"Add a secure 'Repository secret' named 'DOCUMENTER_KEY'") DocumenterTools.genkeys(user="JuliaLang", repo="[email protected]:JuliaLang/Example.jl.git", io=devnull)
end

@testset "genkeys-deved" begin
import Pkg
# It's unlikely that Revise will ever enter our dependency graph
Pkg.develop("Revise")
import Revise
DocumenterTools.genkeys(Revise)
@test_logs (:info, r"Add the key below") (:info, r"Add a secure 'Repository secret' named 'DOCUMENTER_KEY'") DocumenterTools.genkeys(Revise; io=devnull)
end

@testset "outdated warnings" begin
include("outdated.jl")
end

Documenter.doctest(nothing, [DocumenterTools])
@test_logs (:info, r"SetupBuildDirectory") (:info, r"Doctest") (:info, r"Skipped ExpandTemplates step") (:info, r"Skipped CrossReferences step") (:info, r"Skipped CheckDocument step") (:info, r"Skipped Populate step") (:info, r"Skipped RenderDocument step") Documenter.doctest(nothing, [DocumenterTools])
end
Loading