I am using Erlang's EUnit for unit testing an application.
I want to assert that a certain test value is between 2 and 3. There's no built-in support for this, so I am trying to use a pair of guards, like this:
myTestCase ->
?assertMatch({ok, V} when V>2, V<3,
unitUnderTest() % expected to return 2.54232...
).
This tries to use the guard syntax for andalso
.
However, this does not work, presumably because Erlang's parser can't tell the difference between multiple guards and multiple arguments to assertMatch
. I tried wrapping various things in parentheses, but haven't found anything that works. On the other hand, when I reduce the expression to just one clause, it succeeds.
Is there a way to express multiple clauses here?
You cannot use commas in the syntax, simply because then ?assertMatch is interpreted as a macro with 3 - or more - parameters, and there is no definition for that. But the syntax andalso and orelse works. Why don't you use :
test: