Weave.jl/test/run/test_error.jl

66 lines
1.1 KiB
Julia
Raw Normal View History

2020-06-13 18:43:32 +02:00
@testset "evaluation error handling" begin
2020-06-11 13:20:42 +02:00
using Weave: unwrap_load_err
function get_err_str(str::AbstractString)
2020-05-09 15:35:45 +02:00
try
2020-06-11 13:20:42 +02:00
include_string(Main, str)
catch _err
err = unwrap_load_err(_err)
2020-05-09 15:35:45 +02:00
return sprint(showerror, err)
end
end
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
2020-05-09 15:35:45 +02:00
$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 = mock_run(str; doctype = "github")
2020-05-09 15:35:45 +02:00
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
# TODO: move this into chunk option tests
str = """
```julia; error = true
using # won't be thrown
```
```julia; error = false
using NonExisting # will be thrown
```
"""
@test_throws ArgumentError mock_run(str; doctype = "github")
2020-05-09 15:35:45 +02:00
2020-06-13 18:43:32 +02:00
end # @testset "evaluation error handling"