Skip to content

Commit

Permalink
Merge pull request #187 from tlienart/i186
Browse files Browse the repository at this point in the history
Add error message in eval block (see #186)
  • Loading branch information
tlienart authored Jul 8, 2019
2 parents 87924b5 + 7639d8c commit e4c4312
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/converter/md_blocks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ function convert_code_block(ss::SubString)::String
redirect_stdout(outf) do
try
Main.include(path)
catch
print("There was an error running the code.")
catch e
print("There was an error running the code: $(e.error).")
end
end
end
Expand Down
29 changes: 28 additions & 1 deletion test/converter/eval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ end
done.
""" * J.EOS |> seval
# errors silently
@test occursin("then: <pre><code>There was an error running the code.</code></pre>", h)
@test occursin("then: <pre><code>There was an error running the code: DomainError", h)
end

@testset "Eval code (no-julia)" begin
Expand All @@ -146,3 +146,30 @@ end

@test (@test_logs (:warn, "Eval of non-julia code blocks is not supported at the moment") h |> seval) == "<p>Simple code: <pre><code class=\"language-python\">sqrt(-1)\n</code></pre> done.</p>\n"
end

# temporary fix for 186: make error appear and also use `abspath` in internal include
@testset "eval #186" begin
h = raw"""
Simple code:
```julia:scripts/test186
fn = "tempf.jl"
write(fn, "a = 1+1")
println("Is this a file? $(isfile(fn))")
include(abspath(fn))
println("Now: $a")
rm(fn)
```
done.
\output{scripts/test186}
""" * J.EOS |> seval
@test isapproxstr(h, raw"""
<p>Simple code: <pre><code class="language-julia">fn = "tempf.jl"
write(fn, "a = 1+1")
println("Is this a file? $(isfile(fn))")
include(abspath(fn))
println("Now: $a")
rm(fn)</code></pre> done. <pre><code>Is this a file? true
Now: 2
</code></pre></p>
""")
end

0 comments on commit e4c4312

Please sign in to comment.