Skip to content

Commit

Permalink
fix coverage tests
Browse files Browse the repository at this point in the history
  • Loading branch information
disberd committed May 28, 2024
1 parent 0dd408c commit 22504b9
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions test/frompackage/basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -370,31 +370,30 @@ end

# This tests macroexpand and the multiple calls error
@testset "Macroexpand" begin
Base.with_logger(Base.NullLogger()) do
id1 = "4dc0e7fa-6ddc-48ba-867d-8e74d7e6e373"
id2 = "5288e998-6b66-4d46-ab8d-4aa3159c0982"
file_path = joinpath(TestPackage_path, "test_macroexpand.jl")
inpluto_path(id) = join([file_path, "#==#", id])
# Reset
FromPackage.macro_cell[] = "undefined"
# Create the fake module
m = Module(gensym(:MacroExpand))
# Load the macro in the module
m.var"@fromparent" = var"@fromparent"
# We simulate a call from cell 1 with the normal macro
fromparent_call_ex = Expr(:macrocall, Symbol("@fromparent"), LineNumberNode(36, Symbol(inpluto_path(id1))), :(import *))
macroexpand_ex = Expr(:macrocall, Symbol("@fromparent"), LineNumberNode(36, Symbol(inpluto_path(id1))), fromparent_call_ex)
# We try macroexpand and check that the custom variable was not generated
variable_name_id1 = FromPackage._id_name(id1)
Core.eval(m, macroexpand_ex)
@test !isdefined(m, variable_name_id1)
# Without the macroexpand, the variable should be generated
Core.eval(m, fromparent_call_ex)
@test isdefined(m, variable_name_id1)
# Lastly, we try calling the macro from another cell and test that it throws
# Run the macro
Core.eval(m, fromparent_call_ex);
# Check that the dummy variable generated by the macro is defined in the module
@test isdefined(m, FromPackage._id_name(id1))
# We try calling the macro from another cell and test that it throws
error_ex = Expr(:macrocall, Symbol("@fromparent"), LineNumberNode(41, Symbol(inpluto_path(id2))), :(import *))
Core.eval(m, error_ex)
@test !isdefined(m, FromPackage._id_name(id2))
end
macroexpand_ex = Expr(:macrocall, Symbol("@macroexpand"), LineNumberNode(41, Symbol(inpluto_path(id2))), error_ex)
# We test that this thorws a CapturedException
out = Core.eval(m, error_ex)
@test out isa CapturedException
# We test that Multiple Calls is in the error exception message
@test contains(out.ex.msg, "Multiple Calls")
# We try macroexpand, which should directly rethrow without the CaptureException
@test_throws "Multiple Calls" Core.eval(m, macroexpand_ex)
end

# This test is just for 100% coverage by checking that absolute path includes are respected
Expand Down

0 comments on commit 22504b9

Please sign in to comment.