Bug 20526 – Compiling a program without unit tests with "-unittest" prints "1 unittests passed"
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-01-23T11:02:33Z
Last change time
2022-03-24T10:41:17Z
Assigned to
No Owner
Creator
ZombineDev
Comments
Comment #0 by petar.p.kirov — 2020-01-23T11:02:33Z
$ cat test.d
void main()
{
import std.algorithm.sorting : sort;
int[] arr1 = [5, 2, 8];
auto s = arr1.sort;
}
$ dmd -unittest test.d && ./test
1 unittests passed
The root cause is most likely a unit test nested inside a template, which gets instantiated from std.algorithm.sorting.sort.
Comment #1 by petar.p.kirov — 2020-01-23T11:09:09Z
The problem in the example snippet could be solved in phobos by guarding all nested unit tests with `version (StdUnittest)`, but I'm looking for a solution at the dmd/druntime level, as obviously this affects third-party libraries and not just phobos.
Comment #2 by moonlightsentinel — 2022-03-24T10:41:17Z
DMD (1c609085a8b94b97658d8ca3e07b6ca2e9c3d383) now excludes unittests from non-root modules