Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there an easy way to check "@fact_does_not_throw f()" #47

Open
tbreloff opened this issue May 1, 2015 · 3 comments
Open

Is there an easy way to check "@fact_does_not_throw f()" #47

tbreloff opened this issue May 1, 2015 · 3 comments

Comments

@tbreloff
Copy link
Contributor

tbreloff commented May 1, 2015

I want success when there is no error in the function. Is that possible currently?

@IainNZ
Copy link
Contributor

IainNZ commented May 1, 2015

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?

@tbreloff
Copy link
Contributor Author

tbreloff commented May 1, 2015

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)

@tom--lee
Copy link

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 57e4d5b.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants