diff --git a/test/errors_test.jl b/test/errors_test.jl deleted file mode 100644 index 5de002c..0000000 --- a/test/errors_test.jl +++ /dev/null @@ -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 == "
\nERROR: ArgumentError: Package NonExisting not found in current path:\n- Run `import Pkg; Pkg.add("NonExisting")` to install the NonExisting package.\n\n
\n" - @test doc.chunks[2].rich_output == "
\nERROR: syntax: incomplete: premature end of input\n
\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 diff --git a/test/runtests.jl b/test/runtests.jl index 69e6c4d..f1997f3 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 diff --git a/test/test_error_rendering.jl b/test/test_error_rendering.jl new file mode 100644 index 0000000..816aeed --- /dev/null +++ b/test/test_error_rendering.jl @@ -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`