New project: DUnitAssertions

With the cats all in the hospital, I’ve been looking for something to keep me busy, so I don’t spend all my time worrying. So it’s been a good time to work on one of my latest projects: DUnitAssertions. The goal is to make NUnitLite-style assertions available in Delphi and DUnit.

This was an interesting problem from the beginning, because several of the names used in NUnitLite aren’t available in Delphi. Here’s what a typical NUnitLite assertion might look like:

Assert.That(2 + 2, Is.EqualTo(4));

They’ve got a class called Assert with static methods, and another class called Is with static methods. Neither of those is going to fly in Delphi, because Assert is a semi-magic method, and is is a flat-out keyword. (This is one of those cases where using a case-insensitive language is a major pain!)

So I’m changing the syntax to look like one or the other of these:

Expect.That(2 + 2, Tis.EqualTo(4));
Expect.That(2 + 2, Be.EqualTo(4));

I was originally going to use the second line, ’cause it sounds all pirate-y (though obviously it could use an “Arr!” somewhere). But then Brian suggested “Tis”, pointing out that putting a “T” on the beginning of “Is” is more the Delphi way. And it sounds kind of poetic. Two plus two, ’tis four. Classy, no?

Interestingly enough, the following is perfectly valid Delphi syntax, even though not is very much a keyword:

Expect.That(2 + 2, Tis.Not.EqualTo(5));

I think this became possible in Delphi 8, when they tweaked the naming rules for .NET support. If it’s after a dot, they can safely consider it to be an identifier instead of a keyword.

Leave a Reply

Your email address will not be published. Required fields are marked *