Some functions in Squish need to be called in pairs to work correctly. For example fixateResultContext and restoreResultContext should go always together just like startsection and endSection. This is crucial in order to prevent any malfunctioning script behavior and misleading test results.
In order to ensure this will never happen even when script exceptions are raised or the control flow bypasses one of the statements, it is advisable to wrap the calls to the function pairs into helper functions which ensure that they always go together.
Here is one Javascript examples for how to ensure that fixateResultContext and restoreResultContext always go together. The same can be applied to startSection and endSection:
[code]
function withSection(f)
{
test.fixateResultContext(1);
try {
return f();
} finally {
test.restoreResultContext();
}
}
function main()
{
withSection(function() {
test.compare("Apples", "Apples");
});
withSection(function() {
test.compare("Oranges", "Apples");
});
}
[/code]
Animated result example (click image to enlarge):