D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20526 - Compiling a program without unit tests with "-unittest" prints "1 unittests passed"
Summary: Compiling a program without unit tests with "-unittest" prints "1 unittests p...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: druntime (show other issues)
Version: D2
Hardware: All All
: P1 regression
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-01-23 11:02 UTC by ZombineDev
Modified: 2022-03-24 10:41 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description ZombineDev 2020-01-23 11:02:33 UTC
$ 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 ZombineDev 2020-01-23 11:09:09 UTC
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 moonlightsentinel 2022-03-24 10:41:17 UTC
DMD (1c609085a8b94b97658d8ca3e07b6ca2e9c3d383) now excludes unittests from non-root modules