Skip to content

Replace LoggingExtras.jl dep with our own debug macro #195

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

Merged
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
2 changes: 0 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ version = "1.30.0"
[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
LoggingExtras = "e6f89c97-d47a-5376-807f-9c37f3926c36"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
Expand All @@ -15,7 +14,6 @@ TestEnv = "1e6cf692-eddd-4d53-88a5-2d735e33781b"
[compat]
Dates = "1"
Logging = "1"
LoggingExtras = "1"
Pkg = "1"
Profile = "1"
Random = "1"
Expand Down
8 changes: 4 additions & 4 deletions src/ReTestItems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ using Test: Test, DefaultTestSet, TestSetException
using .Threads: @spawn, nthreads
using Pkg: Pkg
using TestEnv
using Logging
using LoggingExtras: LoggingExtras, @debugv
using Logging: current_logger, with_logger

export runtests, runtestitem
export @testsetup, @testitem
Expand Down Expand Up @@ -66,6 +65,7 @@ function softscope_all!(@nospecialize ex)
end
end

include("debug.jl")
include("workers.jl")
using .Workers
include("macros.jl")
Expand Down Expand Up @@ -304,7 +304,7 @@ function runtests(
cfg = _Config(; nworkers, nworker_threads, worker_init_expr, test_end_expr, testitem_timeout, testitem_failfast, failfast, retries, logs, report, verbose_results, timeout_profile_wait, memory_threshold, gc_between_testitems)
debuglvl = Int(debug)
if debuglvl > 0
LoggingExtras.withlevel(LoggingExtras.Debug; verbosity=debuglvl) do
withdebug(debuglvl) do
_runtests(ti_filter, paths′, cfg)
end
else
Expand Down Expand Up @@ -642,7 +642,7 @@ function manage_worker(
close(timer)
end
catch e
@debugv 2 "Error" exception=e
@debugv 2 "Error: $e"
# Handle the exception
if e isa TimeoutException
if cfg.timeout_profile_wait > 0
Expand Down
36 changes: 36 additions & 0 deletions src/debug.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
DEBUG_LEVEL::Int = 0

function setdebug!(level::Int)
global DEBUG_LEVEL = level
return nothing
end

"""
withdebug(level::Int) do
func()
end
"""
function withdebug(f, level::Int)
old = DEBUG_LEVEL
try
setdebug!(level)
f()
finally
setdebug!(old)
end
end

"""
@debugv 1 "msg"
"""
macro debugv(level::Int, messsage)
quote
if DEBUG_LEVEL >= $level
_full_file = $String($(QuoteNode(__source__.file)))
_file = $last($splitdir(_full_file))
_line = $(QuoteNode(__source__.line))
msg = $(esc(messsage))
$print("DEBUG @ $(_file):$(_line) | $msg\n")
end
end
end
2 changes: 1 addition & 1 deletion src/testcontext.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function get_starting_testitems(ti::TestItems, n)
len = length(ti.testitems)
step = max(1, len / n)
testitems = [ti.testitems[round(Int, i)] for i in 1:step:len]
@debugv 2 "get_starting_testitems" len n allunique(testitems)
@debugv 2 "get_starting_testitems len=$len n=$n allunique=$(allunique(testitems))"
@assert length(testitems) == min(n, len) && allunique(testitems)
for (i, t) in enumerate(testitems)
@atomic t.scheduled_for_evaluation.value = true
Expand Down
4 changes: 2 additions & 2 deletions test/integrationtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,9 @@ end
@test !contains(c.output, "tests done")
end
if debug
@test contains(c.output, "Debug:")
@test contains(c.output, "DEBUG @")
else
@test !contains(c.output, "Debug:")
@test !contains(c.output, "DEBUG @")
end
# Test we have the expected summary table
testset = c.value
Expand Down
Loading