|
1 | 1 | # This file is a part of Julia. License is MIT: https://julialang.org/license
|
2 | 2 |
|
| 3 | +import Base.StackTraces: StackFrame |
| 4 | + |
3 | 5 | nested_error_expr = quote
|
4 | 6 | try
|
5 | 7 | __not_a_binding__
|
|
57 | 59 | @test eval(:(ans = 1)) == 1
|
58 | 60 | @test eval(:(err = 1)) == 1
|
59 | 61 | end
|
| 62 | + |
| 63 | +@testset "scrub REPL-related frames" begin |
| 64 | + repl_bt = [StackFrame(:foo, "foo.jl", 1), |
| 65 | + StackFrame(:__repl_entry_anysuffix, "client.jl", 2), |
| 66 | + StackFrame(:bar, "bar.jl", 3)] |
| 67 | + scrubbed_repl_bt = Base.scrub_repl_backtrace(repl_bt) |
| 68 | + |
| 69 | + nonrepl_bt = [StackFrame(:foo, "foo.jl", 1), |
| 70 | + StackFrame(:baz, "baz.jl", 2), |
| 71 | + StackFrame(:bar, "bar.jl", 3)] |
| 72 | + scrubbed_nonrepl_bt = Base.scrub_repl_backtrace(nonrepl_bt) |
| 73 | + |
| 74 | + @test length(scrubbed_repl_bt) == 1 |
| 75 | + @test scrubbed_repl_bt[1].func == :foo |
| 76 | + @test length(scrubbed_nonrepl_bt) == 3 |
| 77 | + |
| 78 | + errio = IOBuffer() |
| 79 | + lower_errexpr = :(@bad) |
| 80 | + Base.eval_user_input(errio, lower_errexpr, false) |
| 81 | + outstr = String(take!(errio)) |
| 82 | + @test occursin("ERROR: LoadError: UndefVarError: `@bad`", outstr) |
| 83 | + @test !occursin("_repl_entry", outstr) |
| 84 | + @test !occursin(r"\.[/\\]client.jl", outstr) |
| 85 | + |
| 86 | + errexpr = :(error("fail")) |
| 87 | + Base.eval_user_input(errio, errexpr, false) |
| 88 | + outstr = String(take!(errio)) |
| 89 | + @test occursin("ERROR: fail", outstr) |
| 90 | + @test !occursin("_repl_entry", outstr) |
| 91 | + @test !occursin(r"\.[/\\]client.jl", outstr) |
| 92 | +end |
0 commit comments