I have some tests written in clojure. This is a simple example:
(defn test1
[]
(start-server)
(run-pvt-and-expect "PVT-0")
(stop-server)
)
I would like to return the result of "run-pvt-and-expect", but I need to execute other functions after it. How can I do this in clojure in a functional way (without using constructs like "let")? Thanks.
Note: I read this question and its answers but couldn't apply it to my case. Also, a comment asked for examples that were never given, so please consider this as an example...
You can do this using a finally block.
(try
(+ 2 3)
(finally (+ 6 7)))
produces a result of 5 not 13.
Here is the relevant doc page. The releavant part is:
any finally exprs will be evaluated for their side effects.
Another option would be to write a macro like with-open to start and stop your server while returning the right results. Though that just moves the problem to how do you write the macro, since it would either need to use a let or the try finally construct above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With