Skip to content

Commit

Permalink
maintenance: use the same pattern for setting ans in sandbox modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Jan 23, 2019
1 parent c56035c commit 87cc2a5
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/DocTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,27 +158,19 @@ function eval_repl(block, sandbox, meta::Dict, doc::Documents.Document, page)
result.hide = REPL.ends_with_semicolon(str)
(value, success, backtrace, text) = Utilities.withoutput() do
disable_color() do
Core.eval(sandbox, ex)
Core.eval(sandbox, Expr(:(=), :ans, ex))
end
end
result.value = value
print(result.stdout, text)
if success
# Redefine the magic `ans` binding available in the REPL.
__ans__!(sandbox, result.value)
else
if !success
result.bt = backtrace
end
end
checkresult(sandbox, result, meta, doc)
end
end

function __ans__!(m::Module, value)
isdefined(m, :__ans__!) || Core.eval(m, :(__ans__!(value) = global ans = value))
return Core.eval(m, Expr(:call, () -> m.__ans__!(value)))
end

function eval_script(block, sandbox, meta::Dict, doc::Documents.Document, page)
# TODO: decide whether to keep `# output` syntax for this. It's a bit ugly.
# Maybe use double blank lines, i.e.
Expand Down

0 comments on commit 87cc2a5

Please sign in to comment.