RELEASE LiveCode 6.6 DP1
Richard Gaskin
ambassador at fourthworld.com
Thu Feb 20 12:48:31 EST 2014
Björnke von Gierke wrote:
> On 20.02.2014, at 16:37, Richard Gaskin wrote:
>
>> The key point there is that both only catch things the engine
>> considers errors.
>>
>> Assert compliments those by providing for things which may be
>> syntactically correct and completely executable, yet are errors
>> within the context of the business logic of your app.
>
>
> I'm not a smart man, and can't imagine any such error ever happening
in a program. Can you give a simple example where you'd use assert to
catch that kind of error?
As Trevor noted a few days ago:
I believe it was added in order to aid with adding test coverage
to LiveCode. At least I seem to recall reading something about
that in some commit notes on GitHub.
So in that spirit of building test harnesses, let's assume you're
testing your app with a known set of data and expecting known results
for what the app does with that data.
You may have two entry fields named "FirstName" and "LastName", and a
third named "DisplayName" which concatenates both.
An assert statement that ensures the first and last name fields have
been populated correctly and that the concatenation is correct might be:
put MyFancyConcatenationAlgo(fld "FirstName", field "LastName) \
into fld "DisplayName"
assert fld "DisplayName" = "Richard Gaskin"
If the "DisplayName" field contains any other value, chances are the
engine will never know the difference.
But for the data set you're testing with "Richard Gaskin" is the only
acceptable value, so the assert will fail, triggering an assertError
message:
assertError handlerName, line, column, objectLongId
...and with that info you can know exactly where the erroneous value
occurred so you can explore ways to correct it.
True, these wouldn't be too hard to check by other means, but once we
also get the ability to turn off assert evaluations globally as most
other implementations have, we have a very powerful opportunity for much
deeper automated quality control.
--
Richard Gaskin
Fourth World
LiveCode training and consulting: http://www.fourthworld.com
Webzine for LiveCode developers: http://www.LiveCodeJournal.com
Follow me on Twitter: http://twitter.com/FourthWorldSys
More information about the use-livecode
mailing list