From 05d0b42dbf267e9157d7086a239dd6752c62c047 Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Fri, 31 Aug 2018 17:45:17 +0200 Subject: [PATCH] Define include in the sandbox module, fix #31. --- src/Literate.jl | 6 ++++++ test/runtests.jl | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/src/Literate.jl b/src/Literate.jl index 59cea0c..b3c753b 100644 --- a/src/Literate.jl +++ b/src/Literate.jl @@ -511,6 +511,12 @@ end function execute_notebook(nb) m = Module(gensym()) + # eval(expr) is available in the REPL (i.e. Main) so we emulate that for the sandbox + Core.eval(m, :(eval(x) = Core.eval($m, x))) + # modules created with Module() does not have include defined + # abspath is needed since this will call `include_relative` + Core.eval(m, :(include(x) = Base.include($m, abspath(x)))) + io = IOBuffer() execution_count = 0 diff --git a/test/runtests.jl b/test/runtests.jl index ab2fdbf..48df58e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -628,6 +628,13 @@ end lastidx = nextind(notebook, last(idx)) end + # issue #31 + write(inputfile, "include(\"issue31.jl\")") + write(joinpath(outdir, "issue31.jl"), "10 + 21") + Literate.notebook(inputfile, outdir) + notebook = read(joinpath(outdir, "inputfile.ipynb"), String) + @test occursin("\"data\": {\n \"text/plain\": \"31\"\n }", notebook) + # test error when executing notebook write(inputfile, "for i in 1:10\n println(i)") r = try