How can one reliably run unittests

jfondren julian.fondren at gmail.com
Sun Sep 5 16:38:01 UTC 2021


On Sunday, 5 September 2021 at 16:12:26 UTC, H. S. Teoh wrote:
> This is seriously a wrong conflation of the program arguments 
> with a program module.  If the whole point is to support 
> specifying the command-line to the program, then the argument 
> list should appear immediately after -run; the first argument 
> after -run should not be conflated with argv[0]. (For example, 
> what if I'm writing an analogue of busybox, and need to specify 
> a different argv[0] from the name of the executable?)
>
> The current behaviour is counterintuitive, doesn't cover all 
> use cases, and has inconsistencies that lead to confusion.  
> It's poor design.

The current behavior is entirely intuitive, it covers all cases, 
it's consistent, it's fine. The only difference from it and a 
lazy getopt solution is lacking a -- before the arguments. The 
only difference between it and your proposed solution is that 
-run would no longer require an argument.

Listen to yourself:

```
$ dmd -run mod1.d  # UNCLEAN, UNCLEAN, UNCLEAN!

$ dmd mod1.d -run  # this is completely fine <3
```

It is absolutely not the case that one of these is wretched bad 
design and the other is pure and great design. These are 
completely identical designs. From the perspective of someone 
who's never seen -run used, it's a coinflip whether they'll guess 
it works one way or another, and it's no longer a coinflip after 
they read the manpage or have seen it used--it's just memory at 
that point, and either design is justifiable and easy to remember.

If the current design were counterintuitive, then people would 
occasionally screw it up even after learning it. I use -run all 
the time, almost more often than rdmd --eval, and I've never once 
had a problem. "I want to -run this" even follows SVO grammar.

I don't think I'd even be bothered--or notice--if a PR went 
through that made -run nonpositional, but you obviously don't use 
this feature all the time, what's with the ludicrously 
over-the-top vitriol about it?

> the first argument after -run should not be conflated with 
> argv[0]. (For example, what if I'm writing an analogue of 
> busybox, and need to specify a different argv[0] from the name 
> of the executable?)

argv[0] is provided by the kernel, not userspace. `man execve` 
and `man posix_spawn` and such will have an argv parameter, but 
that's for subsequent arguments. The most busybox can do is tell 
the kernel what to run with one path or another, in the extreme 
by creating a temporary symlink.


More information about the Digitalmars-d mailing list