September 02, 2021

On Thursday, 2 September 2021 at 20:46:57 UTC, deadalnix wrote:

>

On Thursday, 2 September 2021 at 19:16:38 UTC, jfondren wrote:

>

The alternative to simple dumb flags is not a paradise where dmd always does what everyone expects; it's its own confusing hell where people are constantly surprised by behaviors that are too complex for the outcome to ever be predicted without a week-long course, instead of a quick check of the current manpage where each flag only needs a single sentence for a description.

This is not the alternative. This what exists today.

Case in point: https://issues.dlang.org/show_bug.cgi?id=22268

September 02, 2021

On 9/2/21 1:26 PM, deadalnix wrote:

>

On Tuesday, 31 August 2021 at 16:50:07 UTC, Steven Schveighoffer wrote:

>

So for instance, if you link against library X, and you didn't actually build library X with -unittest, then you won't run library X's unittests, only the ones in your project.

So I was curious at to what was meant by this. Let me try to make it explicit why the current behavior is nonsense. I ran something akin to:

$ dmd -m64 -Isrc -w -debug -g -main -unittest -i -run src/somemodule.d
3 modules passed unittests

It is clear that this is running random unitests I don't care about. Module that are brought in via the -i flag are also compiled with their unittests, which is nonsense.

The -i flag finds all dependencies and builds them all at once as if you weren't linking in the object code that is in a library. That's not what I was saying.

What I was saying is, you have a library, you built it without -unittest (on its own build line, or just use dub because it does the right thing), and then you build your main application with -unittest, linking in the already-built library (or its object files). The runtime runs all unittests it finds, and so it's running just the modules that were built with the -unittest flag.

When you use -i, it means ALL MODULES AND IMPORTS are built with the -unittest flag, and so they all run.

>

Will run exclusively the tests for module1.d and ignore module2.d , which is considered an argument to be passed to the main that don't exist and is never run.

This is complete nonsense (and means that I simply run a fraction of my unitests and have no idea how to fix my build to runt hem all).

-i is going to run all unittests. How else would it interpret the command line? If you want to build some modules differently than others
(i.e. some with unittests and some without), you can't use -i.

> >

But my point is, the reason it's done this way is because D uses the build system that C uses -- which has a compiler and a linker as separate steps.

I don't think this is a good reason. There is nothing in the C style build.link model that prevent us from doing the right thing.

What is the "right thing"? Reading what you expect in your mind is not what a compiler can do. Define how it will work. I think unittests work acceptably the way they are now, but I'm sure others would be keen to have some more bells and whistles. Just make a proposal and get it merged in.

Start by saying "when I type dmd -m64 -Isrc -w -debug -g -main -unittest -i -run src/somemodule.d, here is what I expect to happen: ...", and then define rules that will make that happen.

-Steve

September 02, 2021

On Thursday, 2 September 2021 at 23:00:06 UTC, Steven Schveighoffer wrote:

>

When you use -i, it means ALL MODULES AND IMPORTS are built with the -unittest flag, and so they all run.

I know. That's dumb.

>

-i is going to run all unittests. How else would it interpret the command line? If you want to build some modules differently than others
(i.e. some with unittests and some without), you can't use -i.

Is this groundhog day? There are no combination of flags that do the sensible thing. I can't use -i, no problem. I can't use anything else either, big problem.

The proof is in the pudding, you just told me that I need a full build infra to run unittests for something that use anything else than phobos.

>

What is the "right thing"? Reading what you expect in your mind is not what a compiler can do. Define how it will work. I think unittests work acceptably the way they are now, but I'm sure others would be keen to have some more bells and whistles. Just make a proposal and get it merged in.

The right thing is being able to run the unitests of a god damn module easily. not the unit tests of that module and all of its dependencies. Not using a complex test framework. Just running the unit tests of a module.

This is the sensible thing. This is the simplest thing. This is the "right thing".

It doesn't matter if the module has a main or not. It doesn't matter if the module depends on phobos or half the solar system.

>

Start by saying "when I type dmd -m64 -Isrc -w -debug -g -main -unittest -i -run src/somemodule.d, here is what I expect to happen: ...", and then define rules that will make that happen.

Here is what I expect.

$ dmd --run-the-god-damn-unittest mymodule.d

And it run the unit tests of mymodule.d . Replace --run-the-god-damn-unittest by any set of flags that pleases you, for as long as there is one.

September 02, 2021

The -unittest flag should just accept a pattern, same as -i, so you can explicitly add or remove things that get the unittest build.

Then you can be like dmd -unittest=foo.bar -i main.d and it will build foo.bar with unitest and skip the rest while still auto-following imports.

September 02, 2021
On Thu, Sep 02, 2021 at 11:22:57PM +0000, deadalnix via Digitalmars-d wrote: [...]
> Here is what I expect.
> 
> $ dmd --run-the-god-damn-unittest mymodule.d
> 
> And it run the unit tests of mymodule.d . Replace `--run-the-god-damn-unittest` by any set of flags that pleases you, for as long as there is one.

I propose to extend the -unittest flag to take an optional list of identifiers:

	-unittest=ident1,ident2,...

Each identifier is either a module or package, in which case it means compile unittests for the listed module(s) or all modules whose FQN has a prefix matching the identifier; or one of these special identifiers:

	.		Compile unittests only for modules whose source
			files are found in the current working directory
			or one of its descendents;

	default		Compile *all* unittests in all modules being
			compiled (the current default behaviour).

	module		Compile unittests for all modules explicitly
			specified on the command-line.

(I deliberately picked reserved keywords and symbols which cannot be
confused with D module names.)

So what Amaury wants would be accomplished by:

	dmd -unittest=module -main -i -run mymodule.d

To compile and run local unittests (i.e., everything contained in the current directory or one of its recursive subdirectories, excluding things outside like Phobos or 3rd party dub dependencies):

	dmd -unittest=. -main -i -run myprogram.d

To compile and run unittests for a specific packages/modules (including a 3rd party library if for whatever strange reason you need to):

	dmd -unittest=path.to.package -i -run myprogram.d

To compile and run unittests for multiple packages/modules:

	dmd -unittest=std,thirdparty.pkg,mysubproject -i -run myprogram.d

Finally, if no argument is given to -unittest, then `-unittest=default` is assumed, which behaves like things do today.

Notes: The above specified filters on modules only apply to the set of modules currently being compiled; that's why -i is necessary if your module imports anything else.

Would this satisfy everybody?


T

-- 
"Hi." "'Lo."
September 02, 2021
On Thu, Sep 02, 2021 at 11:48:25PM +0000, Adam Ruppe via Digitalmars-d wrote:
> The -unittest flag should just accept a pattern, same as -i, so you can explicitly add or remove things that get the unittest build.
> 
> Then you can be like dmd -unittest=foo.bar -i main.d and it will build foo.bar with unitest and skip the rest while still auto-following imports.

Haha, I just wrote a post describing pretty much the same thing.  Great minds think alike. ;-)


T

-- 
You are only young once, but you can stay immature indefinitely. -- azephrahel
September 03, 2021

On Thursday, 2 September 2021 at 23:22:57 UTC, deadalnix wrote:

>

The right thing is being able to run the unitests of a god damn module easily.

A patch for silly.d that boils down to

string targetmodule;
// add "test a single module" to existing getopt flags
if (targetmodule && moduleName!module_ != targetmodule) continue;

permits this usage:

$ time dub -q test -- --module=testme
 ✓ testme __unittest_L1_C1

Summary: 1 passed, 0 failed in 0 ms

real    0m0.190s
user    0m0.129s
sys     0m0.059s

Which tests that single module and ignores the others. This still compiles in all the other modules of your project, still compiles in their unittest blocks, still runs their module initialization, still might rebuild a dub dependency, but in the end it runs only the unittest blocks of the chosen module.

Anything short of that is going to be a hacky once-off solution that relies on package-specific knowledge that a module's unittests don't really depend on that other stuff happening. At that level you may as well run 'dmd -main -unittest -run module'.

I think this is the best you're going to get. You can try this now by cloning the silly repo, patching it, running dub add-override silly 1.1.1 . in the repo, and trying out the usage above in your dub package that's already set up to use silly.
There's really nothing to the patch but it's here: https://run.dlang.io/is/smXgof

>

Is this groundhog day?

Well, there's someone in the thread who keeps complaining about random dmd flags, which both draws defenses of those flags and proposals to change them that won't actually give you the workflow you want (like the -unittest= proposal, that still requires you to tell dmd about where all your modules are, which would still be irritating for dub dependencies).

September 03, 2021

On Friday, 3 September 2021 at 00:34:01 UTC, jfondren wrote:

>

Well, there's someone in the thread who keeps complaining about random dmd flags, which both draws defenses of those flags and proposals to change them that won't actually give you the workflow you want (like the -unittest= proposal, that still requires you to tell dmd about where all your modules are, which would still be irritating for dub dependencies).

I'll be blunt, but this is needed because this whole thread is retarded.

The current flag's behavior make no sense. They are not useful. They don't so something sensible. They don't serve typical use cases. The whole thing is completely retarded.

Yes, improving unittest as some suggest would be an improvement. But it doesn't address the core problem. The -main situation remains retarded. It is still not possible to run the unittest of several modules this way, etc...

And here is the root problem: something is complete trash and yet, not only I'm told this is normal and expected, but I'm supposed to be happy with it. By yourself, by Walter, by Steven. You guys are obviously smart, but you aren't looking at this straight or even at all. Or you are drowning in so much trash you don't even see it anymore, like a fish in water. In don't know. But this is alarming.

In fact, people went through the length of migrating the whole standard library to use the StdUnittest version to work around the problem I'm pointing. Think about it. people would rather change how all the tests of the standard lib work rather than fix this shit. This is insane. Literally.

WAKE UP!

This is bad. This is really bad. Stop making excuses. It's time to ask, how did this get this way and what can be done so that this never ever happens again.

Consider the following. You work in a car company. The eng team just came up with this new design with the engine bolted on the roof of the car. You tell them "Guys, this does not make sense, nobody is going to want a car with the engine on the roof." and they respond to you "Well, this is how it is, you can get better cooling this way and yada yada yada...", what would you think? That these people need a technical solution? No, these people need an intervention. They are building a car for people to use, right?

Well, jfondren, you need an intervention. Stop. Take a break and think. You need to look at this with a fresh eye. You have been in this crap for too long and can't see straight anymore.

The set of flags the compiler propose is complete nonsense that do not serve users, it has cause major rewrite in the standard library, and motivated the creating of a new test framework per large project. This needs to stop.

September 03, 2021
On Friday, 3 September 2021 at 00:09:37 UTC, H. S. Teoh wrote:
> Would this satisfy everybody?
>

1/ make module the default. This is really the sensible behavior. Changing imports really change the list of test that are run, especially not recursively.
2/ the `-main` problem remains.
3/ it still isn't possible to run the unit tests of several modules in one go by passing a list of modules to the compiler (in the same way you can compile several modules in one go and generate an object file for all of them at once).
September 03, 2021

On Friday, 3 September 2021 at 01:08:25 UTC, deadalnix wrote:

>

you are drowning in so much trash you don't even see it anymore
...
WAKE UP!
...
This is bad. This is really bad. Stop making excuses. It's time to ask, how did this get this way and what can be done so that this never ever happens again.

Consider the following.

Nah.