Names on unittests can be useful for documentation, a better message on failure, or to selectively run a specific test. D has no built-in way to name unittests, but the most popular library test runner (silly) uses the first string UDA as a name:
@("Johny")
unittest {
// This unittest is named Johny
}
This isn't too pretty though, and typing parentheses and quotes is annoying (using a QWERTY keyboard with US-layout).
I was thinking it could be improved by either allowing @"string"
attributes, similar to @identifier
, or by allowing a string literal after the unittest
keyword:
unittest "Johny" {
// Has @("Johny") as first UDA
}
This would provide a more ergonomic, standardized way of naming tests, and it's a very simple parser change (there's currently nothing allowed between unittest {
).
In many other languages, unittests are regular functions with names, but Zig-test has this syntax for comparison:
test "Johny" {
}
Question to the community: do you name tests, and do you like the idea?