Skip to content

Commit de5bce1

Browse files
More tests for macro testitem (#201)
* More tests for `macro testitem` * fixup! More tests for `macro testitem`
1 parent 05609c6 commit de5bce1

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

test/macros.jl

+40
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,46 @@ end
420420
)
421421
end
422422

423+
@testset "testitem with `default_imports`" begin
424+
ti = @testitem "default_imports" default_imports=true _run=false begin
425+
@test @isdefined Test
426+
@test @isdefined ReTestItems
427+
end
428+
@test ti.default_imports == true
429+
res = ReTestItems.runtestitem(ti)
430+
@test n_passed(res) == 2
431+
432+
ti = @testitem "no_default_imports" default_imports=false _run=false begin
433+
# use `@assert` since we cannot use `@test`
434+
@assert !(@isdefined Test)
435+
@assert !(@isdefined ReTestItems)
436+
end
437+
@test ti.default_imports == false
438+
ReTestItems.runtestitem(ti) # check `@assert` not triggered
439+
440+
@test_throws "`default_imports` keyword must be passed a `Bool`" (
441+
@eval @testitem "Bad" default_imports=1 begin
442+
@test true
443+
end
444+
)
445+
end
446+
447+
@testset "testitem with unrecognised keyword" begin
448+
@test_throws "unknown `@testitem` keyword arg `quux`" (
449+
@eval @testitem "Bad" quux=1 begin
450+
@test true
451+
end
452+
)
453+
end
454+
455+
@testset "testitem without a body" begin
456+
@test_throws "expected `@testitem` to have a body" (@eval @testitem "wrong")
457+
@test_throws "expected `@testitem` to have a body" (@eval @testitem "wrong" @test 1==1)
458+
@test_throws "expected `@testitem` to have a body" (@eval @testitem "wrong" let @test 1==1 end)
459+
@test_throws "expected `@testitem` to have a body" (@eval @testitem "wrong" quote @test 1==1 end)
460+
end
461+
462+
423463
#=
424464
NOTE:
425465
These tests are disabled as we stopped using anonymous modules;

0 commit comments

Comments
 (0)