How can one reliably run unittests
H. S. Teoh
hsteoh at quickfur.ath.cx
Fri Sep 3 00:09:37 UTC 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."
More information about the Digitalmars-d
mailing list