diff --git a/src/ArgCheck.jl b/src/ArgCheck.jl index 624a920..daa602d 100644 --- a/src/ArgCheck.jl +++ b/src/ArgCheck.jl @@ -130,7 +130,7 @@ build_error_with_fancy_message(code, variables, values, args...) = build_error(c end function fancy_error_message(code, exprs, values) - lines = ["$code must hold. Got"] + lines = String[] foreach(exprs, values) do ex, val sex = string(ex) sval = string(val) @@ -138,6 +138,12 @@ function fancy_error_message(code, exprs, values) push!(lines, "$sex => $sval") end end + firstline = if isempty(lines) + "$code must hold." + else + "$code must hold. Got" + end + unshift!(lines, firstline) join(lines, '\n') end diff --git a/test/runtests.jl b/test/runtests.jl index ad44f31..5424e47 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -152,7 +152,11 @@ end @test contains(msg, "y") @test contains(msg, "z") @test contains(msg, "x") + @test contains(msg, "Got") @test contains(msg, "fail_function") + + err = @catch_exception_object @argcheck issorted([2,1]) + @test !contains(err.msg, "Got") end @testset "keyword arguments" begin