D - Unit test tools
- J Anderson (40/40) Dec 16 2003 Just an idea that can parhaps be added to phobos or the language itself
Just an idea that can parhaps be added to phobos or the language itself
for unit tests.
Often you want a function to keep it's behavior, or at least be informed
when it changed from last time.
I suggest a term test, that when called for the first time, creates a
file (using the test name, .tst) and stores the given value. On the
second call of the unittest, the tests would only check if the output
had changed. If it had, the tests would write a .bad file and report the
inconstancy. If the user wanted the function to change, they could
simply delete the .tst file. Test would support the basic primitive
types (bool, char [], int, float, ect...).
ie //testIt.d
char [] func() { return "I shouldn't change"; }
char [] func2() { return "I shouldn't change either"; }
unittest
{
beginTest("func and func2"); //Starts the testing
test(func()); //Writes "I shouldn't change." the first time, the
second time it checks to make sure that func returns "I shouldn't change."
test(func2()); //Writes "I shouldn't change either" the first time,
the second time it checks to make sure that func returns "I shouldn't
change either"
}
unittest
{
beginTest("func"); //Starts the testing
test(func()); //Writes "I shouldn't change." the first time, the
second time it checks to make sure that func returns "I shouldn't change."
}
The first time it would produce a test file (testIt.tst) like (although
it would probably be binary):
func and func2:
I shouldn't change.
I shouldn't change either
func:
I shouldn't change.
The second time, it would just check to make sure it was the same
output. If not it would write a testIt.bad file that looks much like the
testIt.tst file, but with the inconsistencies.
-Anderson
Dec 16 2003








J Anderson <REMOVEanderson badmama.com.au>