Skip to content

Improve dryrun #17

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 4 commits into from
Mar 1, 2021
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
84 changes: 60 additions & 24 deletions src/ReTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,6 @@ function resolve!(mod::Module, ts::TestsetExpr, rx::Regex;
# and ts.run == true

function giveup()
if !ts.run
@warn "could not evaluate testset description, default to inclusion"
end
ts.run = true
if shown
# set ts.descwidth to a lower bound to reduce misalignment
Expand Down Expand Up @@ -469,9 +466,12 @@ function retest(args::Union{Module,AbstractString,Regex}...;

if dry
showmod = overall || implicitmodules
showmod &&
println(mod)
foreach(ts -> dryrun(mod, ts, regex, showmod*2), tests)
if showmod
imod > 1 && verbose > 0 &&
println()
printstyled(mod, '\n', bold=true)
end
foreach(ts -> dryrun(mod, ts, regex, showmod*2, verbose=verbose>0), tests)
continue
end

Expand Down Expand Up @@ -941,39 +941,75 @@ end

isindented(verbose, overall, many) = (verbose > 0) & (overall | !many)

function dryrun(mod::Module, ts::TestsetExpr, rx::Regex, align::Int=0, parentsubj="", )
ts.run || return
function dryrun(mod::Module, ts::TestsetExpr, rx::Regex, align::Int=0, parentsubj=""
; evaldesc=true, repeated=nothing, verbose)
ts.run && verbose || return
desc = ts.desc

giveup() = println(' '^align, desc)

if ts.loops === nothing || desc isa String
if !(desc isa String)
if ts.loops === nothing
if evaldesc && !(desc isa String)
try
desc = Core.eval(mod, desc)
catch
return giveup()
end
end
subject = parentsubj * '/' * desc
if isfinal(ts)
occursin(rx, subject) || return

subject = nothing
if parentsubj isa String && desc isa String
subject = parentsubj * '/' * desc
if isfinal(ts)
occursin(rx, subject) || return
end
end
printstyled(' '^align, desc, color = desc isa String ? :normal : Base.warn_color())

if repeated !== nothing
printstyled(" (repeated",
repeated == -1 ? ")" : " $repeated times)", '\n',
color=:light_black)
else
println()
end
println(' '^align, desc)
for tsc in ts.children
dryrun(mod, tsc, rx, align + 2, subject)
dryrun(mod, tsc, rx, align + 2, subject, verbose=ts.options.transient_verbose)
end
else
loopvalues = ts.loopvalues
loopvalues === nothing && return giveup()
for x in loopvalues
descx = eval_desc(mod, ts, x)
descx === nothing && return giveup()
function dryrun_beginend(descx, repeated=nothing)
# avoid repeating ourselves, transform this iteration into a "begin/end" testset
beginend = TestsetExpr(ts.source, ts.mod, descx, ts.options, nothing,
ts.parent, ts.children)
beginend.run = true
dryrun(mod, beginend, rx, align, parentsubj)
dryrun(mod, beginend, rx, align, parentsubj; evaldesc=false,
repeated=repeated, verbose=verbose)
end

loopvalues = ts.loopvalues
if loopvalues === nothing
# ts.desc is probably a String (cf. resolve!); if so, don't print repeated
# identitical lines (caveat: if subjects of children would change randomly)
# but still try simply to evaluate the length of the iterator
repeated = -1
if ts.desc isa String
local iterlen
try
iterlen = 1
for loop in ts.loops
iterlen *= Core.eval(mod, :(length($(loop.args[2]))))
end
repeated = iterlen
catch
end
end
dryrun_beginend(ts.desc, repeated)
else
for (i, x) in enumerate(loopvalues)
descx = eval_desc(mod, ts, x)
if descx === nothing
@assert i == 1
return dryrun_beginend(ts.desc, length(loopvalues))
end
dryrun_beginend(descx === nothing ? ts.desc : descx)
end
end
end
end
Expand Down
47 changes: 44 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ RUN = []
end
end

@test_logs (:warn, r"could not evaluate testset description.*") retest(Loops1, r"asd")
@test Loops1.RUN == [1, 0, 2, 0]
empty!(Loops1.RUN)
# @test_logs (:warn, r"could not evaluate testset description.*") retest(Loops1, r"asd")
# @test Loops1.RUN == [1, 0, 2, 0]
# empty!(Loops1.RUN)
retest(Loops1) # should not log
@test Loops1.RUN == [1, 0, -1, 2, 0, -1]

Expand Down Expand Up @@ -612,6 +612,47 @@ for dry=(true, false),
retest(mod..., regex; shuffle=true, verbose=verbose, stats=stats, dry=dry)
end

### dry-run

module DryRun
using ReTest

X = 'a'

@testset "a" for i=1:2
@testset "b" begin end
end
@testset "a$X" for i=1:2
@testset "b" begin end
end
@testset "x$i" for i=1:2
@testset "b$i" begin
@testset "c" begin end
end
@testset "d$i$j" for j=1:2
end
end
@testset "y$i" for i=1:1
@testset "b" for j=1:i
@testset "c" begin end
end
end

end # DryRun

retest(DryRun, dry=true)
retest(DryRun, dry=true, verbose=0)
retest(DryRun, dry=true, verbose=5)

module DryRun2
using ReTest

@testset "just a dummy module" begin end
end # DryRun2

retest(DryRun, DryRun2, dry=true, verbose=0)
retest(DryRun, DryRun2, dry=true, verbose=1)

### InlineTest ###############################################################

using Pkg
Expand Down