Skip to content

Commit

Permalink
Make tests almost entirely quiet (#3725)
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth authored and KristofferC committed May 9, 2024
1 parent 325b462 commit 607d288
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 58 deletions.
22 changes: 13 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,30 @@ jobs:
- os: macOS-latest
julia-arch: x86
steps:
- name: Set git to use LF
- name: Set git to use LF and fix TEMP on windows
if: matrix.os == 'windows-latest'
run: |
git config --global core.autocrlf false
git config --global core.eol lf
# See https://github.com/actions/virtual-environments/issues/712
echo "TMP=${USERPROFILE}\AppData\Local\Temp" >> ${GITHUB_ENV}
echo "TEMP=${USERPROFILE}\AppData\Local\Temp" >> ${GITHUB_ENV}
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.julia-version }}
arch: ${{ matrix.julia-arch }}
- name: Fix TEMP on windows
if: matrix.os == 'windows-latest'
run: |
# See https://github.com/actions/virtual-environments/issues/712
echo "TMP=${USERPROFILE}\AppData\Local\Temp" >> ${GITHUB_ENV}
echo "TEMP=${USERPROFILE}\AppData\Local\Temp" >> ${GITHUB_ENV}
- run: julia --project --color=yes --pkgimages=no --check-bounds=yes -e 'import Pkg; Pkg.build(); Pkg.test(; coverage=true)'
- uses: julia-actions/julia-runtest@v1
with:
coverage: true
env:
JULIA_PKG_SERVER: ${{ matrix.pkg-server }}
JULIA_PKG_TEST_QUIET: "true" # "true" is the default. i.e. tests are quiet when this env var isn't set
JULIA_TEST_VERBOSE_LOGS_DIR: ${{ github.workspace }}
- uses: actions/upload-artifact@v3
if: ${{ always() }}
with:
name: ${{ join(matrix.*, '-') }}_Pkg.log
path: ${{ github.workspace }}/Pkg.log
- uses: julia-actions/julia-processcoverage@v1
env:
JULIA_PKG_SERVER: ${{ matrix.pkg-server }}
Expand Down
30 changes: 13 additions & 17 deletions test/new.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2706,26 +2706,22 @@ for v in (nothing, "true")
withenv("JULIA_PKG_USE_CLI_GIT" => v, "GIT_TERMINAL_PROMPT" => 0) do
@testset "downloads with JULIA_PKG_USE_CLI_GIT = $v" begin
isolate() do
@testset "libgit2 downloads" begin
@testset "via name" begin
Pkg.add(TEST_PKG.name; use_git_for_all_downloads=true)
@testset "via name" begin
Pkg.add(TEST_PKG.name; use_git_for_all_downloads=true)
@test haskey(Pkg.dependencies(), TEST_PKG.uuid)
@eval import $(Symbol(TEST_PKG.name))
@test_throws SystemError open(pathof(eval(Symbol(TEST_PKG.name))), "w") do io end # check read-only
Pkg.rm(TEST_PKG.name)
end
if (Base.get_bool_env("JULIA_PKG_USE_CLI_GIT", false) == false) && !Sys.iswindows()
# TODO: fix. On GH windows runners cli git will prompt for credentials and hang.
# On other runners git cli is noisy when an url is given.
@testset "via url" begin
Pkg.add(url="https://github.com/JuliaLang/Example.jl", use_git_for_all_downloads=true)
@test haskey(Pkg.dependencies(), TEST_PKG.uuid)
@eval import $(Symbol(TEST_PKG.name))
@test_throws SystemError open(pathof(eval(Symbol(TEST_PKG.name))), "w") do io end # check read-only
Pkg.rm(TEST_PKG.name)
end
if (Base.get_bool_env("JULIA_PKG_USE_CLI_GIT", false) && Sys.iswindows()) == false
# TODO: fix. on GH windows runners cli git will prompt for credentials here
@testset "via url" begin
Pkg.add(url="https://github.com/JuliaLang/Example.jl", use_git_for_all_downloads=true)
@test haskey(Pkg.dependencies(), TEST_PKG.uuid)
Pkg.rm(TEST_PKG.name)
end
end
end
if !Sys.iswindows()
# TODO: fix. on GH windows runners cli git will prompt for credentials here
@testset "libgit2 failures" begin
@testset "failures" begin
doesnotexist = "https://github.com/DoesNotExist/DoesNotExist.jl"
@test_throws Pkg.Types.PkgError Pkg.add(url=doesnotexist, use_git_for_all_downloads=true)
@test_throws Pkg.Types.PkgError Pkg.Registry.add(Pkg.RegistrySpec(url=doesnotexist))
Expand Down
57 changes: 25 additions & 32 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,61 +10,54 @@ original_project = Base.active_project()
module PkgTestsInner

import Pkg

# Because julia CI doesn't run stdlib tests via `Pkg.test` test deps must be manually installed if missing
if Base.find_package("HistoricalStdlibVersions") === nothing
@debug "Installing HistoricalStdlibVersions for Pkg tests"
iob = IOBuffer()
Pkg.activate(; temp = true)
try
Pkg.add("HistoricalStdlibVersions", io=iob) # Needed for custom julia version resolve tests
catch
println(String(take!(iob)))
rethrow()
end
end

import HistoricalStdlibVersions

using Test, Logging

@testset "Test that we have imported the correct package" begin
@test realpath(dirname(dirname(Base.pathof(Pkg)))) == realpath(dirname(@__DIR__))
if realpath(dirname(dirname(Base.pathof(Pkg)))) != realpath(dirname(@__DIR__))
@show dirname(dirname(Base.pathof(Pkg))) realpath(dirname(@__DIR__))
error("The wrong Pkg is being tested")
end

ENV["JULIA_PKG_PRECOMPILE_AUTO"]=0

if (server = Pkg.pkg_server()) !== nothing && Sys.which("curl") !== nothing
s = read(`curl -sLI $(server)`, String);
@info "Pkg Server metadata:\n$s"
end

### Disable logging output if true (default)
hide_logs = Base.get_bool_env("JULIA_PKG_TEST_QUIET", true)

logdir = get(ENV, "JULIA_TEST_VERBOSE_LOGS_DIR", nothing)
### Send all Pkg output to a file called Pkg.log

islogging = logdir !== nothing

if islogging
logfile = joinpath(logdir, "Pkg.log")
Pkg.DEFAULT_IO[] = open(logfile, "a")
@info "Pkg test output is being logged to file" logfile
elseif hide_logs
Pkg.DEFAULT_IO[] = Base.BufferStream()
@info "Pkg test output is silenced"
else
Pkg.DEFAULT_IO[] = stdout
end

Pkg.REPLMode.minirepl[] = Pkg.REPLMode.MiniREPL() # re-set this given DEFAULT_IO has changed

include("utils.jl")
Logging.with_logger(islogging ? Logging.ConsoleLogger(Pkg.DEFAULT_IO[]) : Logging.current_logger()) do

# Because julia CI doesn't run stdlib tests via `Pkg.test` test deps must be manually installed if missing
if Base.find_package("HistoricalStdlibVersions") === nothing
@debug "Installing HistoricalStdlibVersions for Pkg tests"
iob = IOBuffer()
Pkg.activate(; temp = true)
try
Pkg.add("HistoricalStdlibVersions", io=iob) # Needed for custom julia version resolve tests
catch
println(String(take!(iob)))
rethrow()
end
end

@eval import HistoricalStdlibVersions

if (server = Pkg.pkg_server()) !== nothing && Sys.which("curl") !== nothing
s = read(`curl -sLI $(server)`, String);
@info "Pkg Server metadata:\n$s"
end

Utils.check_init_reg()
Utils.check_init_reg()

Logging.with_logger(hide_logs ? Logging.NullLogger() : Logging.current_logger()) do
@testset "Pkg" begin
try
@testset "$f" for f in [
Expand Down

0 comments on commit 607d288

Please sign in to comment.