Please vote on std.datetime

Jens Mueller jens.k.mueller at gmx.de
Fri Dec 10 06:29:40 PST 2010


Andrei Alexandrescu wrote:
> Jonathan M. Davis has diligently worked on his std.datetime
> proposal, and it has been through a few review cycles in this
> newsgroup.
> 
> It's time to vote. Please vote for or against inclusion of datetime
> into Phobos, along with your reasons.

I cannot say anything regarding the datetime module but I'd like to say
something about the unittest module. First it is really great having
these asserts with improved output.
I do not understand why one needs assertOpCmp!"=="(). According to TDPL
there should be <, <=, >=, and >. == will be rewritten using opEquals.
So I think <= and >= are missing and I do not know why there is
assertOpCmp!"==".
Further I'll find the following implementation of assertOpCmp better.

immutable result = mixin("lhs" ~ op ~ "rhs");
if(!result)
{   
	if(msg.empty)
		throw new AssertError(format("[%s] %s [%s] failed", lhs, op, rhs), file, line);
	else
		throw new AssertError(format("[%s] %s [%s] failed: %s", %lhs, op, rhs, msg), %file, line);
}

It is shorter and gives the similar diagnostics than the current
version. But I haven't tested the code above.
The actual version is hard coded to lhs.opCmp(rhs). Better leave the
decision lhs.opCmp(rhs) vs rhs.opCmp(lhs) to the compiler.

Not sure about the following but maybe having something spelled out like
this assertLessThan, assertLessEqual, etc. is also nice.

For assertEqual I'd like it to mirror opEqual similar to as I did it
above for opCmp. So have something like assertOpEquals() and then maybe
also the name assertEquals as a synonym. I have to admit I do not know
how to integrate !=.

Why the binary predicate?
With the current version I can write something like
assertEqual!"a != b"(1, 2)
which I find strange. Why not only do the check for equality.
I.e.
if(!(mixin("actual" ~ op ~ "expected"))
{
	if(msg.empty)
		throw new AssertError(format("assertEquals() failed: actual [%s], expected [%s].", actual, expected), file, line);
	else
		throw new AssertError(format("assertEquals() failed: actual [%s], expected [%s]: %s", actual, expected, msg), file, line);
}

What's the benefit of the binary predicate? Clearly it makes it more
flexible but I dislike allowing something like assertEqual!"a != b"(1,
2).

In summary: I really like the unittest module. It's a great step forward
for writing test. The assertions feel much like in google-test. A great
module. I hope that I managed to explain my minor annoyance. I'll do my
very best. Jonathan, thanks for this great module. +1 for std.unittest.

Jens


More information about the Digitalmars-d mailing list