From 7c6ac75b9f864d1a4e9b5d82967d71a8853d7c71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mos=C3=A8=20Giordano?= Date: Tue, 24 Sep 2024 00:48:29 +0100 Subject: [PATCH] Make tests less noisy and actually test logging messages --- src/genkeys.jl | 10 +++++----- test/generate.jl | 6 +++--- test/outdated.jl | 2 +- test/runtests.jl | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/genkeys.jl b/src/genkeys.jl index 732ece2..64e23a7 100644 --- a/src/genkeys.jl +++ b/src/genkeys.jl @@ -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" @@ -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 @@ -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 """ @@ -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.") @@ -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 diff --git a/test/generate.jl b/test/generate.jl index c28035f..d3436f4 100644 --- a/test/generate.jl +++ b/test/generate.jl @@ -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")) @@ -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 diff --git a/test/outdated.jl b/test/outdated.jl index d5d71e9..c9f564f 100644 --- a/test/outdated.jl +++ b/test/outdated.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 6bdd67e..f4a525c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -9,7 +9,7 @@ import Documenter @testset "genkeys-added" begin using Example - DocumenterTools.genkeys(user="JuliaLang", repo="git@github.com: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="git@github.com:JuliaLang/Example.jl.git", io=devnull) end @testset "genkeys-deved" begin @@ -17,12 +17,12 @@ import Documenter # 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