Problem
Currently, there is no easy way to check an expectation without failing the test. The current workaround is using the ExpectToBeXXX functions, then provide the result to the actual Expectation to not make the test fail.
Proposition
I propose the introduction of a Try function, much like the already existing tryFunction, but that will allows to revert the test expectation to their when-called state between each tries.
Example
Sequence("MySequence", function()
Test("MyTest", function()
Expect(doMeasure(), "My first measure"):ToBeInPercentage(3.3, 10)
Try(
function(args) Expect(doMeasure(), "My second measure"):ToBeInPercentage(3.3, 10) end,
{
max_retries = 5, -- Max number of tries to do, default to 1
cooldown_ms = 100, -- Delay between each tries, default to 0
args = {"arg1", "arg2"} -- Args to forward to function, can be nil
}
)
end)
end)
Implementation
The following pseudocode provide an implementation example
- Check function is called inside a Test Scope, raise error if not.
- Store the current number of expectation in scope.
- Check if has remaining tries, if not, exit function.
- Call provided function, while forwarding arguments, if any.
- For each new expectation
a. If success, continue
b. If failure
1. delete all new expectation
2. sleep for cooldown_ms
3. increment try counter
4. jump back to step 3
Limitations
- The Try function can only be used when inside a Test scope
Problem
Currently, there is no easy way to check an expectation without failing the test. The current workaround is using the ExpectToBeXXX functions, then provide the result to the actual Expectation to not make the test fail.
Proposition
I propose the introduction of a Try function, much like the already existing tryFunction, but that will allows to revert the test expectation to their when-called state between each tries.
Example
Implementation
The following pseudocode provide an implementation example
a. If success, continue
b. If failure
1. delete all new expectation
2. sleep for cooldown_ms
3. increment try counter
4. jump back to step 3
Limitations