Merge pull request #320 from JunoLab/avi/robusttest

more robust error rendering test
pull/319/head
Shuhei Kadowaki 2020-05-09 23:17:24 +09:00 committed by GitHub
commit f1df02c2b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 39 deletions

View File

@ -1,35 +0,0 @@
str = """
```julia
using NonExisting
```
```julia
x =
```
```julia;term=true
plot(x)
y = 10
print(y
```
"""
let
doc = run_doc(mock_doc(str), doctype = "pandoc")
@test doc.chunks[1].output == "Error: ArgumentError: Package NonExisting not found in current path:\n- Run `import Pkg; Pkg.add(\"NonExisting\")` to install the NonExisting package.\n\n"
@test doc.chunks[2].output == "Error: syntax: incomplete: premature end of input\n"
@test doc.chunks[3].output == "\njulia> plot(x)\nError: UndefVarError: plot not defined\n\njulia> y = 10\n10\n\njulia> print(y\nError: syntax: incomplete: premature end of input\n"
end
@test_throws ArgumentError run_doc(mock_doc(str), doctype = "pandoc", throw_errors = true)
let
doc = run_doc(mock_doc(str), doctype = "md2html")
@test doc.chunks[1].rich_output == "<pre class=\"julia-error\">\nERROR: ArgumentError: Package NonExisting not found in current path:\n- Run &#96;import Pkg; Pkg.add&#40;&quot;NonExisting&quot;&#41;&#96; to install the NonExisting package.\n\n</pre>\n"
@test doc.chunks[2].rich_output == "<pre class=\"julia-error\">\nERROR: syntax: incomplete: premature end of input\n</pre>\n"
@test doc.chunks[3].output == "\njulia> plot(x)\nError: UndefVarError: plot not defined\n\njulia> y = 10\n10\n\njulia> print(y\nError: syntax: incomplete: premature end of input\n"
@test doc.chunks[3].rich_output == ""
end

View File

@ -15,10 +15,6 @@ mock_doc(str, chunk_parser = Weave.parse_markdown) = Weave.WeaveDoc("dummy", chu
include("chunk_options.jl")
end
@testset "Error handling " begin
include("errors_test.jl")
end
@testset "module evaluation" begin
include("test_module_evaluation.jl")
end
@ -27,6 +23,10 @@ mock_doc(str, chunk_parser = Weave.parse_markdown) = Weave.WeaveDoc("dummy", chu
include("test_header.jl")
end
@testset "error rendering" begin
include("test_error_rendering.jl")
end
@testset "Conversions" begin
include("convert_test.jl")
end

View File

@ -0,0 +1,49 @@
function get_err_str(ex)
try
eval(ex)
catch err
return sprint(showerror, err)
end
end
get_err_str(str::AbstractString) = get_err_str(Meta.parse(str; raise = false))
err_stmt1 = "using NonExisting"
err_stmt2 = "x = "
err_stmt3 = """
plot(x)
y = 10
f(y
"""
str = """
```julia
$err_stmt1
```
```julia
$err_stmt2
```
```julia; term=true
$err_stmt3
```
"""
err_str1 = get_err_str(err_stmt1)
err_str2 = get_err_str(err_stmt2)
err_str3_1 = get_err_str("plot(x)")
err_str3_2 = get_err_str("f(y")
let doc = run_doc(mock_doc(str), doctype = "pandoc")
get_output(i) = doc.chunks[i].output
@test occursin(err_str1, get_output(1))
@test occursin(err_str2, get_output(2))
@test occursin(err_str3_1, get_output(3))
@test occursin(err_str3_2, get_output(3))
end
@test_throws ArgumentError run_doc(mock_doc(str), doctype = "pandoc", throw_errors = true)
# TODO: test error rendering in `rich_output`