Closed peter1000 closed 9 years ago
Can you apply this diff to FactCheck.jl master:
diff --git a/src/FactCheck.jl b/src/FactCheck.jl
index ba29e58..22e5bfd 100644
--- a/src/FactCheck.jl
+++ b/src/FactCheck.jl
@@ -181,10 +181,10 @@ macro fact_throws(args...)
$(if is(extype, nothing)
:((true, "error"))
else
- :(if isa(ex,$extype)
+ :(if isa(ex,$(esc(extype)))
(true,"error")
else
- $(:((false, "wrong argument type, expected $($extype) got $(typeof(ex))")))
+ $(:((false, "wrong argument type, expected $($(esc(extype))) got $(typeof(ex))")))
end)
end)
end,
Appears to fix the issue of unescaped extype
not allowing for custom exceptions.
I'll send a PR if it works for you.
Ok I will try that just some minutes
:+1:
julia> Pkg.test("Lexicon")
INFO: Computing test dependencies for Lexicon...
INFO: No packages to install, update or remove
INFO: Testing Lexicon
Elements.
- Empty Nodes.
3 facts verified.
INFO: Lexicon tests passed
INFO: No packages to install, update or remove
julia>
lucky me was one time not my mistake ;)
BTW: Do you mind if we specify the Error a bit like this: makes it easier in the fact tests.
lucky me was one time not my mistake ;)
Yeah, when there's a problem with a macro call I always go to macroexpand
immediately. You'll notice that at # line 185:
the exception type is returned as FactCheck.EmptyNodeError
:
julia> macroexpand(:(@fact_throws EmptyNodeError document(a = 1)))
quote # /home/mike/.julia/v0.4/FactCheck/src/FactCheck.jl, line 177:
FactCheck.do_fact((()->begin # /home/mike/.julia/v0.4/FactCheck/src/FactCheck.jl, line 177:
try # line 178:
document(a=1) # line 179:
(false,"no error")
catch #22#ex # line 181:
if FactCheck.isa(#22#ex,FactCheck.EmptyNodeError) # line 185:
(true,"error")
else # line 187:
(false,"wrong argument type, expected $(FactCheck.EmptyNodeError) got $(FactCheck.typeof(#22#ex))")
end
end
end),$(Expr(:copyast, :($(QuoteNode(:(document(a=1))))))),FactCheck.ResultMetadata(line=FactCheck.getline(),msg=nothing))
end
BTW: Do you mind if we specify the Error a bit like this: makes it easier in the fact tests.
Yes, that's fine, but let's not end up with dozens of different error types. And only when a new FactCheck.jl version has been tagged of course.
hi, maybe you can spot where I made a mistake.
I just wanted to try to add some specific Errors which seems all fine but in Fact test I get an error:
UndefVarError: EmptyNodeError not defined
if I do the first fact example in the REPL
Thanks
Can be deleted after wards.