How can one reliably run unittests

H. S. Teoh hsteoh at quickfur.ath.cx
Sun Sep 5 16:12:26 UTC 2021


On Sun, Sep 05, 2021 at 03:52:51PM +0000, jfondren via Digitalmars-d wrote:
> On Sunday, 5 September 2021 at 15:04:58 UTC, H. S. Teoh wrote:
> > On Fri, Sep 03, 2021 at 08:39:35AM +0000, deadalnix via Digitalmars-d
> > wrote: [...]
> > > > > 	dmd -unittest=module -i -run mod1.d mod2.d mod3.d main.d
> > > >
> > > 
> > > No, this will run the code in mod1.d , passing ["mod2.d" "mod3.d"
> > > "main.d"] as command line arguments.
> > 
> > I really don't understand the logic of this: surely the compiler
> > ought to be able to know which module main() is declared in, so why
> > does it need the user to select one specific module to be run?
> 
> ```
> $ grep -H . mod?.d
> mod1.d:void main(string[] args) {
> mod1.d:    import std.stdio : writeln;
> mod1.d:    writeln(args[1 .. $]);
> mod1.d:}
> $ dmd -run mod1.d mod2.d mod3.d
> ["mod2.d", "mod3.d"]
> ```
> 
> mod1.d is a program that prints its args that I'd like to run with
> some arguments. mod2.d and mod3.d are not modules that even exist; I
> just want them printed out like that. Distinguishing between dmd and
> program arguments isn't a matter of compiler smarts.

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.


T

-- 
I am a consultant. My job is to make your job redundant. -- Mr Tom


More information about the Digitalmars-d mailing list