Skip to content

Commit bd59157

Browse files
committed
tests: @chapter defaults to wrap body in a Test.@testset
1 parent 009aee1 commit bd59157

File tree

2 files changed

+34
-24
lines changed

2 files changed

+34
-24
lines changed

test/runtests.jl

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ end
385385

386386
# * toplevel .................................................................
387387

388-
@chapter toplevel begin
388+
@chapter toplevel false begin
389389
# The following test is just to exert `@assert allunique(TESTED_MODULES)` in
390390
# computemodules!, and must be run before any toplevel @testset in declared,
391391
# so that `Main` is not yet in TESTED_MODULES; we check that previous
@@ -815,15 +815,12 @@ end
815815
@chapter MiscSeed begin
816816
rands = VERSION < v"1.7-" ? [0x24ae, 0x837e] :
817817
VERSION <= v"1.7" ? [0x1f33, 0x415f] :
818-
error("update the seeds")
819-
820-
Test.@testset "seed" begin
821-
MiscSeed.runtests(verbose=0, seed=1)
822-
@test MiscSeed.RAND1 === MiscSeed.RAND2 === rands[1]
823-
MiscSeed.runtests(verbose=0, seed=2)
824-
@test MiscSeed.RAND1 === MiscSeed.RAND2 === rands[2]
825-
# TODO: test in a distributed setting
826-
end
818+
error("update the seeds")
819+
MiscSeed.runtests(verbose=0, seed=1)
820+
@test MiscSeed.RAND1 === MiscSeed.RAND2 === rands[1]
821+
MiscSeed.runtests(verbose=0, seed=2)
822+
@test MiscSeed.RAND1 === MiscSeed.RAND2 === rands[2]
823+
# TODO: test in a distributed setting
827824
end
828825

829826
module Bugs
@@ -853,15 +850,13 @@ using ReTest
853850
end
854851

855852
@chapter TestsetErrors begin
856-
Test.@testset "TestsetErrors" begin
857-
@test_logs (
858-
:error, "expected begin/end block or for loop as argument to @testset") (
859-
:error, "unsupported @testset option") (
860-
:error, "unsupported @testset" ) (
861-
:error, "expected begin/end block or for loop as argument to @testset") (
862-
:error, "expected begin/end block or for loop as argument to @testset"
863-
) TestsetErrors.runtests()
864-
end
853+
@test_logs (
854+
:error, "expected begin/end block or for loop as argument to @testset") (
855+
:error, "unsupported @testset option") (
856+
:error, "unsupported @testset" ) (
857+
:error, "expected begin/end block or for loop as argument to @testset") (
858+
:error, "expected begin/end block or for loop as argument to @testset"
859+
) TestsetErrors.runtests()
865860
end
866861

867862

@@ -1157,7 +1152,7 @@ Pkg.activate("./FakePackage")
11571152
Pkg.develop(PackageSpec(path="../InlineTest"))
11581153
Pkg.develop(PackageSpec(path="..")) # ReTest
11591154

1160-
@chapter InlineTest begin
1155+
@chapter InlineTest false begin
11611156
Pkg.test("FakePackage")
11621157
end
11631158

@@ -1167,7 +1162,7 @@ using ReTest: process_args
11671162
module Load end
11681163
module Load2 end
11691164

1170-
@chapter load begin
1165+
@chapter load false begin
11711166
using FakePackage
11721167
@assert !isdefined(Main, :FakePackageTests)
11731168

@@ -1214,7 +1209,7 @@ end
12141209

12151210
# * Hijack ...................................................................
12161211

1217-
@chapter Hijack begin
1212+
@chapter Hijack false begin
12181213
Pkg.activate("./Hijack")
12191214
Pkg.develop(PackageSpec(path="..")) # ReTest
12201215
Pkg.test("Hijack")

test/setup.jl

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,26 @@ function check(x...; runtests=false, output::Union{Nothing,String}=nothing,
4646
@test Trace.RUN == expected
4747
end
4848

49-
macro chapter(title, x)
49+
# @chapter title [wrap_in_testset::Bool=true] body
50+
macro chapter(title, wrap_in_testset, body=nothing)
5051
title = string(title)
52+
if body === nothing
53+
body = wrap_in_testset
54+
wrap_in_testset = true
55+
else
56+
wrap_in_testset::Bool
57+
end
5158

5259
if isempty(ARGS) || any(pat -> occursin(Regex(pat, "i"), title), ARGS)
5360
printstyled("\n\n", rpad("## $title #", 78, '#'), "\n\n", bold=true, color=:cyan)
54-
esc(x)
61+
if wrap_in_testset
62+
quote
63+
Test.@testset $("$title") begin
64+
$(esc(body))
65+
end
66+
end
67+
else
68+
esc(body)
69+
end
5570
end
5671
end

0 commit comments

Comments
 (0)