February 16, 2023

On Monday, 13 February 2023 at 12:05:05 UTC, Atila Neves wrote:

>

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

>

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.

The reason I used a string UDA initially (and, probably why silly does the same thing) is to avoid having to import a symbol to use it there. It's the simplest thing that will work and not "corrupt" production code.

Don't get me started on version(unittest).

I think using @("") is some kind of a hack because if you use a documentation generator, you will have to also add a /// comment to have a nice description of the example. But since there is already a way to explain what a unit test is doing, and I am referring to the /// comment, why don't you just use that comment?

This is what I implemented in trial, and it works great. Currently, the code is parsed using libdparse, but I must admit that it would be great if there would be a trait that gives you the documentation comment of a symbol. I know there were discussions about this a few years ago, and it was decided not to have such a compiler feature.

February 16, 2023

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

>

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

I'm actually for that it should be unittest "Johnny" instead of without the quotations. The reason is that we want something that describes the test much as possible and that will often include spaces.

For example:

unittest "Johnny download test fail to find server"

instead of

unittest Johnny download test fail to find server

which certainly will confuse the parser.

You can overcome this by having snake case but that it kind of ugly

unittest Johnny_download_test_fail_to_find_server

With quotation marks we will have more freedom how to name the tests.

February 16, 2023

On Thursday, 16 February 2023 at 08:29:44 UTC, Bogdan wrote:

>

On Monday, 13 February 2023 at 12:05:05 UTC, Atila Neves wrote:

>

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

>

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.

The reason I used a string UDA initially (and, probably why silly does the same thing) is to avoid having to import a symbol to use it there. It's the simplest thing that will work and not "corrupt" production code.

Don't get me started on version(unittest).

I think using @("") is some kind of a hack

People didn't generally attach string UDAs to tests before, so it doesn't intrude and "just works".

>

because if you use a documentation generator, you will have to also add a /// comment to have a nice description of the example.

IMHO that should go on the function, not the test.

>

But since there is already a way to explain what a unit test is doing, and I am referring to the /// comment, why don't you just use that comment?

For me at least, because it'd be incredibly annoying to select that test to run in the command line. I think that if you need a comment to explain what the test is doing, then you should rewrite the test.

February 16, 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?

Personally I'm not sure if I could find an interesting name for tests, but I can certainly express their intent in a string literal like in Zig.

February 17, 2023
On 17/02/2023 2:20 AM, Guillaume Piolat wrote:
> Personally I'm not sure if I could find an interesting name for tests, but I can certainly express their intent in a string literal like in Zig.

Identifier support should probably be only syntax level deep, and be treated as if it was a string in the implementation.

So for rapid prototyping and debugging it may be desirable to just use an identifier rather than a string if you need it.

Thoughts?
February 16, 2023
On Thursday, 16 February 2023 at 13:29:48 UTC, Richard (Rikki) Andrew Cattermole wrote:
>
> So for rapid prototyping and debugging it may be desirable to just use an identifier rather than a string if you need it.
>
> Thoughts?

Can certainly live with either (this is a decision for core people) but what is the purpose of an identifier there?
February 17, 2023
On 17/02/2023 2:58 AM, Guillaume Piolat wrote:
> On Thursday, 16 February 2023 at 13:29:48 UTC, Richard (Rikki) Andrew Cattermole wrote:
>>
>> So for rapid prototyping and debugging it may be desirable to just use an identifier rather than a string if you need it.
>>
>> Thoughts?
> 
> Can certainly live with either (this is a decision for core people) but what is the purpose of an identifier there?

It wouldn't be either or, you'd do both. After all you'd just convert the identifier to a string during parsing no extra semantics.

February 16, 2023

On Friday, 10 February 2023 at 21:08:38 UTC, 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
}

module sample;

class X { void foo() {} }

Refer below form -> it can be expanded with addition attribute(s) in future with consistent structure
unittest(name="good", document="class X")
{}
unittest(name="good", document="class X.foo")
{}

name = name of unittest
document = generate document for class X
generate document for function class X.foo

for running test
unitttest=name:"good"
unittest=module:"sample"

name = only run unittest with matching name "good"
module = only run unittest(s) for module "sample"

February 17, 2023
On 17/02/2023 3:22 AM, apz28 wrote:
> document = generate document for class X
>             generate document for function class X.foo

We could easily generate such strings in this example.

We also have access to core.attributes to make the compiler understand other information, if its desired.

There are solutions here that don't require making this more complicated. So we'd need a concrete attributes above name of easily extracted from the AST.
February 16, 2023

On 2/16/23 5:40 AM, IGotD- wrote:

>

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

>

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

I'm actually for that it should be unittest "Johnny" instead of without the quotations. The reason is that we want something that describes the test much as possible and that will often include spaces.

For example:

unittest "Johnny download test fail to find server"

instead of

unittest Johnny download test fail to find server

which certainly will confuse the parser.

You can overcome this by having snake case but that it kind of ugly

unittest Johnny_download_test_fail_to_find_server

With quotation marks we will have more freedom how to name the tests.

I actually prefer without the quotes. Why? Because it matches what we currently do:

struct foo
class bar
unittest baz

In addition, if you make it a string, since D has CTFE, this is going to get confusing:

sneaky.d:
enum Johnny = "Freddy";

othermodule.d:

unittest Johnny {
}

"unittest Freddy failed"

user: huh?

So you have to come up with a name that has no spaces. Are you a programmer or not?

I would couch this by saying, I don't really think we need anything here. The @("Johnny") is good enough for me. In fact, I'm fine without labeling unittests at all, and just looking at the file/line of the failed tests.

-Steve