We already have --DRT-run-unittests. It's -unittest -main. Simple!

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun May 19 13:31:12 UTC 2019


Just realized... this.

Today if you build with -main a program that has a main() function, you get:

__main.d(1): Error: only one main allowed, -main switch added another 
main(). Previously found main at xyz.d(42)

But it makes sense to allow (and ignore) main if -unittest is also 
provided. Essentially -unittest -main means "build for unittesting and a 
no-op main".

This should be easy to implement and a simple step to take toward better 
unittesting.

Again, the overarching belief is that unit testing is part of the build 
process. The way it should go is that compile/run/unittest is part of 
the build cycle. Integration testing is somewhere in between and not 
easy to automate generically. Then of course running would be the last step.

Once with have -unittest -main going, we can write a script a la rdmd 
called e.g. dmd-build that does (stylized):

1. Start dmd compile/link in background (no unittest), output to 
${thebinary}.tmp, output to ${thebinary}.log
2. Build ${thebinary}.unittest with -main -unittest
3. If errors => abort
4. Run ${thebinary}.unittest
5. If errors => abort
6. Fetch the exit code of the background process
7. If errors => output ${thebinary}.log to stderr, abort
8. Delete ${thebinary}.log
9. Rename ${thebinary}.tmp to ${thebinary}
10. Success!


More information about the Digitalmars-d mailing list