Skip to content

Commit

Permalink
Update tests and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kdheepak committed May 20, 2021
1 parent 926970e commit 853c57f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,36 @@ function get_xpress_error_message(xprs_ptr)
e = "(Unable to extract error message for $(typeof(xprs_ptr)).)"
end

"""
@checked f(prob)
Lets you invoke a lower level `Lib` function and check that Xpress does not error.
Use this macro to minimize repetition and increase readability.
The first argument must be a object that can be cast into an Xpress pointer, e.g. `Ptr{XpressProblem}`.
This is passed to `get_xpress_error_message(xprs_ptr)` to get the error message.
Examples:
@checked Lib.XPRSsetprobname(prob, name)
As an example of what @checked expands to:
```
julia> @macroexpand @checked Lib.XPRSsetprobname(prob, name)
quote
r = Lib.XPRSsetprobname(prob, name)
if r != 0
xprs_ptr = prob
e = get_xpress_error_message(xprs_ptr)
throw(XpressError(r, "Unable to call `Xpress.setprobname`:\n\n\$(e).\n"))
else
nothing
end
end
```
"""
macro checked(expr)
@assert expr.head == :call "Can only use @checked on function calls"
@assert ( expr.args[1].head == :(.) ) && ( expr.args[1].args[1] == :Lib) "Can only use @checked on Lib.\$function"
Expand Down
3 changes: 2 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ end
@test Xpress.getcontrol(prob, "HEURTHREADS") == 0
@test Xpress.getcontrol(prob, :HEURTHREADS) == 0

@test_throws Xpress.XpressError Xpress.copyprob(prob, prob)
msg = "Unable to call `Xpress.copyprob`:\n\n91 Error: No problem has been input.\n"
@test_throws Xpress.XpressError(32,msg) Xpress.copyprob(prob, prob)
end

0 comments on commit 853c57f

Please sign in to comment.