mirror of https://github.com/mpastell/Weave.jl
add test for `clear_module!`
parent
79579053f1
commit
3b8201df04
|
@ -1,21 +1,48 @@
|
|||
# TODO: test `clear_module!`
|
||||
@testset "evaluation module" begin
|
||||
function mock_output(document, mod = nothing)
|
||||
parsed = Weave.parse_doc(document, "markdown")
|
||||
doc = Weave.WeaveDoc("dummy.jmd", parsed, Dict())
|
||||
result_doc = run_doc(doc, mod = mod)
|
||||
@test isdefined(result_doc.chunks[1], :output)
|
||||
return result_doc.chunks[1].output
|
||||
end
|
||||
|
||||
function mock_output(document, mod = nothing)
|
||||
parsed = Weave.parse_doc(document, "markdown")
|
||||
doc = Weave.WeaveDoc("dummy.jmd", parsed, Dict())
|
||||
result_doc = run_doc(doc, mod = mod)
|
||||
@test isdefined(result_doc.chunks[1], :output)
|
||||
return result_doc.chunks[1].output
|
||||
document = """
|
||||
```julia
|
||||
@__MODULE__
|
||||
```
|
||||
"""
|
||||
|
||||
# in sandbox
|
||||
@test occursin(r"\#+WeaveSandBox[\#\d]+", mock_output(document))
|
||||
|
||||
# in Main
|
||||
@test strip(mock_output(document, Main)) == "Main"
|
||||
end
|
||||
|
||||
document = """
|
||||
```julia
|
||||
@__MODULE__
|
||||
```
|
||||
"""
|
||||
@testset "clear_module!" begin
|
||||
ary = rand(1000000)
|
||||
size = Base.summarysize(ary)
|
||||
|
||||
# in sandbox
|
||||
@test occursin(r"\#+WeaveSandBox[\#\d]+", mock_output(document))
|
||||
# simple case
|
||||
m = Core.eval(@__MODULE__, :(module $(gensym(:WeaveTestModule)) end))
|
||||
Core.eval(m, :(a = $ary))
|
||||
Weave.clear_module!(m)
|
||||
@test Base.summarysize(m) < size
|
||||
|
||||
# in Main
|
||||
@test strip(mock_output(document, Main)) == "Main"
|
||||
# recursive case
|
||||
m = Core.eval(@__MODULE__, :(module $(gensym(:WeaveTestModule)) end))
|
||||
Core.eval(m, :(
|
||||
module $(gensym(:WeaveTestSubModule))
|
||||
a = $ary
|
||||
end
|
||||
))
|
||||
Weave.clear_module!(m)
|
||||
@test Base.summarysize(m) < size
|
||||
|
||||
# doesn't work with constants
|
||||
m = Core.eval(@__MODULE__, :(module $(gensym(:WeaveTestModule)) end))
|
||||
Core.eval(m, :(const a = $ary))
|
||||
Weave.clear_module!(m)
|
||||
@test_broken Base.summarysize(m) < size
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue