FactCheck.jl
FactCheck.jl copied to clipboard
Is there an easy way to check "@fact_does_not_throw f()"
I want success when there is no error in the function. Is that possible currently?
I think @fact captures that case already right? And if it throws it records it as an error? So you could do @fact f() => anything kinda thing?
Close... I think below works. Does it make sense to have shorthand for this? @fact_nothrows?
julia> f() = nothing
f (generic function with 1 method)
julia> g() = error()
g (generic function with 1 method)
julia> facts() do
@fact f() => anyof(anything,nothing)
@fact g() => anyof(anything,nothing)
end
Error :: (line:-1)
g() => anyof(anything,nothing)
in g at none:1
in anonymous at /home/tom/.julia/v0.4/FactCheck/src/FactCheck.jl:142
in do_fact at /home/tom/.julia/v0.4/FactCheck/src/FactCheck.jl:201
in anonymous at none:142
in facts at /home/tom/.julia/v0.4/FactCheck/src/FactCheck.jl:315
in facts at /home/tom/.julia/v0.4/FactCheck/src/FactCheck.jl:328
Out of 2 total facts:
Verified: 1
Errored: 1
delayed_handler (generic function with 4 methods)
I would also find such a feature useful. For now I am using this approach:
julia> using FactCheck
julia> checkerror=not(NaN)
(anonymous function)
julia> f()=nothing; g()=NaN; h()=1; er()=error("something went wrong")
er (generic function with 1 method)
julia> facts("check for errors") do
@fact f() --> checkerror
@fact g() --> checkerror
@fact h() --> checkerror
@fact er() --> checkerror
end
check for errors
Error :: (line:505)
Expression: er() --> checkerror
something went wrong
in er at none:1
in anonymous at /Users/tomlee/.julia/v0.4/FactCheck/src/FactCheck.jl:271
in do_fact at /Users/tomlee/.julia/v0.4/FactCheck/src/FactCheck.jl:333
in anonymous at none:271
in facts at /Users/tomlee/.julia/v0.4/FactCheck/src/FactCheck.jl:448
Out of 4 total facts:
Verified: 3
Errored: 1
delayed_handler (generic function with 4 methods)
EDIT: the anything keyword mentioned in the above comments ~~doesn't seem to be defined?~~ has been removed 57e4d5b48fabaefa1e7d6b06af400b02c1e05700.