unittest "name" {}

Steven Schveighoffer schveiguy at gmail.com
Fri Feb 10 21:48:00 UTC 2023


On 2/10/23 4:08 PM, Dennis wrote:
> 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](https://code.dlang.org/packages/silly)) uses the first string 
> UDA as a name:
> 
> ```D
> @("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
> }
> ```

If you are going that route, just `unittest Johnny` would be fine.

But just to warn you, there's no place to store this in the ModuleInfo, 
it stores *one* function pointer for the whole file.

I personally am fine with the requirements to use a UDA.

And I also prefer the simple "first string" method, because one thing 
that is super-annoying is to have to depend on the unittest library for 
normal builds (I recently removed this for mysql-native).

-Steve


More information about the Digitalmars-d mailing list