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