Skip to content

Commit 64b1a6c

Browse files
Replace LoggingExtras.jl dep with our own debug macro (#195)
* Replace LoggingExtras.jl dep with our own debug macro * Update debug log syntax in tests * fixup! Replace LoggingExtras.jl dep with our own debug macro * fixup! Replace LoggingExtras.jl dep with our own debug macro
1 parent 16162fa commit 64b1a6c

File tree

5 files changed

+43
-9
lines changed

5 files changed

+43
-9
lines changed

Project.toml

-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ version = "1.30.0"
55
[deps]
66
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
77
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
8-
LoggingExtras = "e6f89c97-d47a-5376-807f-9c37f3926c36"
98
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
109
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
1110
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
@@ -15,7 +14,6 @@ TestEnv = "1e6cf692-eddd-4d53-88a5-2d735e33781b"
1514
[compat]
1615
Dates = "1"
1716
Logging = "1"
18-
LoggingExtras = "1"
1917
Pkg = "1"
2018
Profile = "1"
2119
Random = "1"

src/ReTestItems.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ using Test: Test, DefaultTestSet, TestSetException
66
using .Threads: @spawn, nthreads
77
using Pkg: Pkg
88
using TestEnv
9-
using Logging
10-
using LoggingExtras: LoggingExtras, @debugv
9+
using Logging: current_logger, with_logger
1110

1211
export runtests, runtestitem
1312
export @testsetup, @testitem
@@ -66,6 +65,7 @@ function softscope_all!(@nospecialize ex)
6665
end
6766
end
6867

68+
include("debug.jl")
6969
include("workers.jl")
7070
using .Workers
7171
include("macros.jl")
@@ -304,7 +304,7 @@ function runtests(
304304
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)
305305
debuglvl = Int(debug)
306306
if debuglvl > 0
307-
LoggingExtras.withlevel(LoggingExtras.Debug; verbosity=debuglvl) do
307+
withdebug(debuglvl) do
308308
_runtests(ti_filter, paths′, cfg)
309309
end
310310
else
@@ -642,7 +642,7 @@ function manage_worker(
642642
close(timer)
643643
end
644644
catch e
645-
@debugv 2 "Error" exception=e
645+
@debugv 2 "Error: $e"
646646
# Handle the exception
647647
if e isa TimeoutException
648648
if cfg.timeout_profile_wait > 0

src/debug.jl

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
DEBUG_LEVEL::Int = 0
2+
3+
function setdebug!(level::Int)
4+
global DEBUG_LEVEL = level
5+
return nothing
6+
end
7+
8+
"""
9+
withdebug(level::Int) do
10+
func()
11+
end
12+
"""
13+
function withdebug(f, level::Int)
14+
old = DEBUG_LEVEL
15+
try
16+
setdebug!(level)
17+
f()
18+
finally
19+
setdebug!(old)
20+
end
21+
end
22+
23+
"""
24+
@debugv 1 "msg"
25+
"""
26+
macro debugv(level::Int, messsage)
27+
quote
28+
if DEBUG_LEVEL >= $level
29+
_full_file = $String($(QuoteNode(__source__.file)))
30+
_file = $last($splitdir(_full_file))
31+
_line = $(QuoteNode(__source__.line))
32+
msg = $(esc(messsage))
33+
$print("DEBUG @ $(_file):$(_line) | $msg\n")
34+
end
35+
end
36+
end

src/testcontext.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ function get_starting_testitems(ti::TestItems, n)
156156
len = length(ti.testitems)
157157
step = max(1, len / n)
158158
testitems = [ti.testitems[round(Int, i)] for i in 1:step:len]
159-
@debugv 2 "get_starting_testitems" len n allunique(testitems)
159+
@debugv 2 "get_starting_testitems len=$len n=$n allunique=$(allunique(testitems))"
160160
@assert length(testitems) == min(n, len) && allunique(testitems)
161161
for (i, t) in enumerate(testitems)
162162
@atomic t.scheduled_for_evaluation.value = true

test/integrationtests.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,9 @@ end
461461
@test !contains(c.output, "tests done")
462462
end
463463
if debug
464-
@test contains(c.output, "Debug:")
464+
@test contains(c.output, "DEBUG @")
465465
else
466-
@test !contains(c.output, "Debug:")
466+
@test !contains(c.output, "DEBUG @")
467467
end
468468
# Test we have the expected summary table
469469
testset = c.value

0 commit comments

Comments
 (0)