diff --git a/test/mocks/.gitignore b/test/mocks/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/test/mocks/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/test/runtests.jl b/test/runtests.jl index 001f18a..9f1084b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -44,6 +44,10 @@ end include("test_chunk_options.jl") end + @testset "evaluation's meta info" begin + include("test_meta.jl") + end + @testset "error rendering" begin include("test_error_rendering.jl") end diff --git a/test/test_error_rendering.jl b/test/test_error_rendering.jl index 99130d6..4c4c27d 100644 --- a/test/test_error_rendering.jl +++ b/test/test_error_rendering.jl @@ -1,11 +1,14 @@ -function get_err_str(ex) +using Weave: unwrap_load_err + + +function get_err_str(str::AbstractString) try - eval(ex) - catch err + include_string(Main, str) + catch _err + err = unwrap_load_err(_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 = " diff --git a/test/test_meta.jl b/test/test_meta.jl new file mode 100644 index 0000000..5df2c1a --- /dev/null +++ b/test/test_meta.jl @@ -0,0 +1,40 @@ +doc_body = """ +```julia +include("test_include.jl") +``` + +```julia +@__MODULE__ +``` + +```julia +@__DIR__ +``` + +```julia +@__FILE__ +``` + +```julia +@__LINE__ # broken +``` +""" +doc_dir = joinpath(@__DIR__, "mocks") +doc_path = joinpath(doc_dir, "test_meta.jmd") +write(doc_path, doc_body) + +script_line = ":include_me" +script_body = "$script_line" +script_path = joinpath(@__DIR__, "mocks", "test_include.jl") +write(script_path, script_body) + + +m = Core.eval(@__MODULE__, :(module $(gensym(:WeaveTestModule)) end)) +mock = run_doc(WeaveDoc(doc_path); mod = m) +check_output(i, s) = occursin(s, mock.chunks[i].output) + +@test check_output(1, script_line) +@test check_output(2, string(m)) +@test check_output(3, doc_dir) +@test check_output(4, doc_path) +@test_broken check_output(5, 18)