From b5e02cad36bc4d5134498b78909746d2757de92c Mon Sep 17 00:00:00 2001 From: Matti Pastell Date: Thu, 26 Jul 2018 00:12:48 +0300 Subject: [PATCH] Add tests for running in Main or sandbox module. Closes #101 --- test/runtests.jl | 4 ++++ test/sandbox_test.jl | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 test/sandbox_test.jl diff --git a/test/runtests.jl b/test/runtests.jl index 9d86d27..c73c7c9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -12,6 +12,10 @@ using Test include("errors_test.jl") end + @testset "Eval in module" begin + include("sandbox_test.jl") + end + @testset "Conversions" begin @info("Test: Converting") include("convert_test.jl") diff --git a/test/sandbox_test.jl b/test/sandbox_test.jl new file mode 100644 index 0000000..74fe412 --- /dev/null +++ b/test/sandbox_test.jl @@ -0,0 +1,35 @@ +using Weave +using Test + +function weavestring(source; doctype = "pandoc", informat="markdown", mod=Main) + p1 = Weave.parse_doc(source, informat) + doc = Weave.WeaveDoc("dummy1.jmd", p1, Dict()) + return Weave.run(doc, doctype=doctype, mod=mod) +end + +smod = """ +```julia +module TestMod + x = 3 + + function printx() + print("x") + end + + export printx +end +``` + +```julia +using .TestMod +printx() +``` +""" + +wdoc = weavestring(smod) +@test wdoc.chunks[1].output == "Main.TestMod\n" +@test wdoc.chunks[2].output == "x" + +sdoc = weavestring(smod, mod=:sandbox) +@test occursin(r"Weave.ReportSandBox[0-9]*.TestMod\n", sdoc.chunks[1].output) +@test sdoc.chunks[2].output == "x"