Skip to content

Commit

Permalink
Merge pull request JuliaDocs#250 from MichaelHatherly/mh/doctest-setu…
Browse files Browse the repository at this point in the history
…p-0.4-fix

Evaluate blocks as :toplevel
  • Loading branch information
MichaelHatherly authored Sep 4, 2016
2 parents 08aced9 + 3adb13d commit 70225b6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/DocChecks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ end
function doctest(block::Markdown.Code, meta::Dict, doc::Documents.Document, page)
if block.language == "jldoctest"
code, sandbox = replace(block.code, "\r\n", "\n"), Module(:Main)
haskey(meta, :DocTestSetup) && eval(sandbox, meta[:DocTestSetup])
if haskey(meta, :DocTestSetup)
expr = meta[:DocTestSetup]
Meta.isexpr(expr, :block) && (expr.head = :toplevel)
eval(sandbox, expr)
end
if ismatch(r"^julia> "m, code)
eval_repl(code, sandbox, meta, doc, page)
block.language = "jlcon"
Expand Down
9 changes: 9 additions & 0 deletions test/examples/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ zeros(5, 5)
zeros(50, 50)
```

```@meta
DocTestSetup = quote
using Base
x = -3:0.01:3
y = -4:0.02:5
z = [Float64((xi^2 + yi^2)) for xi in x, yi in y]
end
```

```jldoctest
julia> [1.0, 2.0, 3.0]
3-element Array{Float64,1}:
Expand Down

0 comments on commit 70225b6

Please sign in to comment.