Jump to page: 1 25  
Page
Thread overview
unittest "name" {}
Feb 10, 2023
Dennis
Feb 10, 2023
ProtectAndHide
Feb 10, 2023
ProtectAndHide
Feb 10, 2023
ProtectAndHide
Feb 11, 2023
Mike Shah
Feb 10, 2023
Dennis
Feb 11, 2023
WebFreak001
Feb 11, 2023
Alexandru Ermicioi
Feb 13, 2023
Atila Neves
Feb 16, 2023
Bogdan
Feb 16, 2023
Atila Neves
Feb 16, 2023
IGotD-
Feb 16, 2023
bachmeier
Feb 16, 2023
Ben Jones
Feb 16, 2023
Paul Backus
Feb 17, 2023
bachmeier
Feb 16, 2023
ProtectAndHide
Feb 16, 2023
ProtectAndHide
Feb 16, 2023
Guillaume Piolat
Feb 16, 2023
Guillaume Piolat
Feb 17, 2023
ProtectAndHide
Feb 11, 2023
max haughton
Feb 11, 2023
Bradley Chatha
Feb 11, 2023
Andrew
Feb 12, 2023
IGotD-
Feb 12, 2023
deadalnix
Feb 12, 2023
Max Samukha
Feb 12, 2023
Max Samukha
Feb 16, 2023
Guillaume Piolat
Feb 16, 2023
Guillaume Piolat
Feb 16, 2023
apz28
Feb 19, 2023
FeepingCreature
February 10, 2023

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?

February 10, 2023
On Friday, 10 February 2023 at 21:08:38 UTC, Dennis wrote:
>
> ...
> Question to the community: do you name tests, and do you like the idea?

Nice idea.

I'd prefer it was consistent with the import statement though:

unittest : mytest
{

}
February 10, 2023
On Friday, 10 February 2023 at 21:15:23 UTC, ProtectAndHide wrote:
> On Friday, 10 February 2023 at 21:08:38 UTC, Dennis wrote:
>>
>> ...
>> Question to the community: do you name tests, and do you like the idea?
>
> Nice idea.
>
> I'd prefer it was consistent with the import statement though:
>
> unittest : mytest
> {
>
> }

Also maybe a way to tell the compiler what unittest to run perhaps (i.e. passing in the name of the unittest (all unittests being the default).

unittest : myQuicktest // dmd -unittest:myQuicktest
{

}

unittest : myLongtest // dmd -unittest:myLongtest
{

}
February 10, 2023
On Friday, 10 February 2023 at 21:21:30 UTC, ProtectAndHide wrote:
>
>
> Also maybe a way to tell the compiler what unittest to run perhaps (i.e. passing in the name of the unittest (all unittests being the default).
>
> unittest : myQuicktest // dmd -unittest:myQuicktest
> {
>
> }
>
> unittest : myLongtest // dmd -unittest:myLongtest
> {
>
> }

better be consistent here as well:

dmd -unittest                          (as per current. runs all unittests)
dmd -unittest=myQuicktest              (runs only that named unittest)
dmd -unittest=myQuicktest,myLongtest   (runs these named unittests only)

February 10, 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) 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
}

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

February 10, 2023

On Friday, 10 February 2023 at 21:48:00 UTC, Steven Schveighoffer wrote:

>

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

And I also prefer the simple "first string" method,

My proposal is purely syntactic sugar, it's exactly the same as adding a first string UDA.

February 11, 2023
I'm ok with ``unittest "name" {}`` syntax. It should also support identifiers too.

We'll need to think about how to handle this at the ModuleInfo level though.
February 11, 2023

On Friday, 10 February 2023 at 22:24:54 UTC, Dennis wrote:

>

On Friday, 10 February 2023 at 21:48:00 UTC, Steven Schveighoffer wrote:

>

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

And I also prefer the simple "first string" method,

My proposal is purely syntactic sugar, it's exactly the same as adding a first string UDA.

I like this idea, and I think as @("") has already become the de-facto standard across testing frameworks on DUB we can just make it behave like that and everyone will be happy without breaking changes + it's all quite an easy change for everyone.

Maybe it's a good idea to do some critical thinking about this, but let's not overdo it, I think this solution is quite practical. (though I haven't have critically thought about this yet very much)

Q: what does unittest foo {} do? try to read variable foo? I think if we support that a syntax like unittest(foo) {} would be more consistent, but maybe we should just make it be identifiers that are output as-is into a string. (it would look like function definitions and we could add duplication checking into the compiler)

February 10, 2023

On 2/10/23 5:24 PM, Dennis wrote:

>

On Friday, 10 February 2023 at 21:48:00 UTC, Steven Schveighoffer wrote:

>

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

And I also prefer the simple "first string" method,

My proposal is purely syntactic sugar, it's exactly the same as adding a first string UDA.

In that case, I'm not in favor of it. I don't think the first form is so much worse that it needs adjusting:

// existing
@("foo") unittest {
   ...
}

// proposed
unittest "foo" {
   ...
}

-Steve

February 11, 2023

On Saturday, 11 February 2023 at 00:03:50 UTC, WebFreak001 wrote:

>

I like this idea, and I think as @("") has already become the de-facto standard across testing frameworks on DUB we can just make it behave like that and everyone will be happy without breaking changes + it's all quite an easy change for everyone.

Maybe it's a good idea to do some critical thinking about this, but let's not overdo it, I think this solution is quite practical. (though I haven't have critically thought about this yet very much)

This is kinda constraining, to a single form. If changes are to be done to language, then perhaps it would be best to consider also parameterized tests, interpolated test names, or test names that are not strings at all but something convertible to string.

« First   ‹ Prev
1 2 3 4 5