diff --git a/std/digest/murmurhash.d b/std/digest/murmurhash.d index 89ac40de55e..ede3b9094a2 100644 --- a/std/digest/murmurhash.d +++ b/std/digest/murmurhash.d @@ -687,8 +687,6 @@ the 'put' method. version(unittest) { - import std.string : representation; - private auto hash(H, Element = H.Element)(string data) { H hasher; diff --git a/std/internal/cstring.d b/std/internal/cstring.d index 620cb2665b9..b79f380ede3 100644 --- a/std/internal/cstring.d +++ b/std/internal/cstring.d @@ -41,18 +41,6 @@ module std.internal.cstring; import std.range; import std.traits; -version(unittest) -@property inout(C)[] asArray(C)(inout C* cstr) pure nothrow @nogc @trusted -if (isSomeChar!C) -in { assert(cstr); } -do -{ - size_t length = 0; - while (cstr[length]) - ++length; - return cstr[0 .. length]; -} - /** Creates temporary 0-terminated $(I C string) with copy of passed text. @@ -157,14 +145,23 @@ nothrow @nogc @system unittest @safe pure nothrow @nogc unittest { - assert("abc".tempCString().asArray == "abc"); - assert("abc"d.tempCString().ptr.asArray == "abc"); - assert("abc".tempCString!wchar().buffPtr.asArray == "abc"w); + static inout(C)[] arrayFor(C)(inout(C)* cstr) pure nothrow @nogc @trusted + { + assert(cstr); + size_t length = 0; + while (cstr[length]) + ++length; + return cstr[0 .. length]; + } + + assert(arrayFor("abc".tempCString()) == "abc"); + assert(arrayFor("abc"d.tempCString().ptr) == "abc"); + assert(arrayFor("abc".tempCString!wchar().buffPtr) == "abc"w); import std.utf : byChar, byWchar; char[300] abc = 'a'; - assert(tempCString(abc[].byChar).buffPtr.asArray == abc); - assert(tempCString(abc[].byWchar).buffPtr.asArray == abc); + assert(arrayFor(tempCString(abc[].byChar).buffPtr) == abc); + assert(arrayFor(tempCString(abc[].byWchar).buffPtr) == abc); assert(tempCString(abc[].byChar)[] == abc); } diff --git a/std/math.d b/std/math.d index eb44edad8e8..098cced45b7 100644 --- a/std/math.d +++ b/std/math.d @@ -171,10 +171,8 @@ else version (X86) private alias haveSSE = core.cpuid.sse; } -version(unittest) +version(unittest) private { - import core.stdc.stdio; // : sprintf; - static if (real.sizeof > double.sizeof) enum uint useDigits = 16; else @@ -189,6 +187,8 @@ version(unittest) private bool equalsDigit(real x, real y, uint ndigits) @safe nothrow @nogc { + import core.stdc.stdio : sprintf; + if (signbit(x) != signbit(y)) return 0; diff --git a/std/net/isemail.d b/std/net/isemail.d index a6b8de98dc1..4c8a3334813 100644 --- a/std/net/isemail.d +++ b/std/net/isemail.d @@ -1875,7 +1875,7 @@ bool isUpToFourHexChars(Char)(scope const(Char)[] s) return true; } -version(unittest) @nogc nothrow pure @safe unittest +@nogc nothrow pure @safe unittest { assert(!isUpToFourHexChars("12345")); assert(!isUpToFourHexChars("defg")); @@ -1945,7 +1945,7 @@ const(Char)[] matchIPSuffix(Char)(return const(Char)[] s) @nogc nothrow pure @sa return s[start .. $]; } -version(unittest) @nogc nothrow pure @safe unittest +@nogc nothrow pure @safe unittest { assert(matchIPSuffix("255.255.255.255") == "255.255.255.255"); assert(matchIPSuffix("babaev 176.16.0.1") == "176.16.0.1"); diff --git a/std/numeric.d b/std/numeric.d index e891529f1d4..822c4ce4a5e 100644 --- a/std/numeric.d +++ b/std/numeric.d @@ -26,10 +26,6 @@ import std.range.primitives; import std.traits; import std.typecons; -version(unittest) -{ - import std.stdio; -} /// Format flags for CustomFloat. public enum CustomFloatFlags { @@ -751,6 +747,7 @@ template secantMethod(alias fun) @system unittest { // @system because of __gshared stderr + import std.stdio; scope(failure) stderr.writeln("Failure testing secantMethod"); float f(float x) { diff --git a/std/parallelism.d b/std/parallelism.d index 2b0e463c395..9013137cfa6 100644 --- a/std/parallelism.d +++ b/std/parallelism.d @@ -4107,8 +4107,6 @@ version(unittest) { // This was the only way I could get nested maps to work. __gshared TaskPool poolInstance; - - import std.stdio; } // These test basic functionality but don't stress test for threading bugs. @@ -4123,6 +4121,7 @@ version(unittest) import std.math : approxEqual, sqrt, log; import std.range : indexed, iota, join; import std.typecons : Tuple, tuple; + import std.stdio; poolInstance = new TaskPool(2); scope(exit) poolInstance.stop(); @@ -4770,9 +4769,9 @@ version(parallelismStressTest) } } -version(unittest) +@system unittest { - struct __S_12733 + static struct __S_12733 { invariant() { assert(checksum == 1_234_567_890); } this(ulong u){n = u;} @@ -4782,10 +4781,6 @@ version(unittest) } static auto __genPair_12733(ulong n) { return __S_12733(n); } -} - -@system unittest -{ immutable ulong[] data = [ 2UL^^59-1, 2UL^^59-1, 2UL^^59-1, 112_272_537_195_293UL ]; auto result = taskPool.amap!__genPair_12733(data); diff --git a/std/path.d b/std/path.d index ab80cee5573..ef094d8a870 100644 --- a/std/path.d +++ b/std/path.d @@ -4144,11 +4144,6 @@ version(unittest) C[] array; } - static assert( isRandomAccessRange!(MockRange!(const(char))) ); -} - -version(unittest) -{ /* Define a mock BidirectionalRange to use for unittesting. */ @@ -4169,6 +4164,11 @@ version(unittest) const(C)[] array; } +} + +@safe unittest +{ + static assert( isRandomAccessRange!(MockRange!(const(char))) ); static assert( isBidirectionalRange!(MockBiRange!(const(char))) ); } diff --git a/std/range/primitives.d b/std/range/primitives.d index 820ef5a414d..e0e0cea2b57 100644 --- a/std/range/primitives.d +++ b/std/range/primitives.d @@ -2134,7 +2134,7 @@ if (!isNarrowString!(T[]) && !is(T[] == void[])) assert(a == [ 2, 3 ]); } -version(unittest) +@safe unittest { static assert(!is(typeof({ int[4] a; popFront(a); }))); static assert(!is(typeof({ immutable int[] a; popFront(a); }))); @@ -2255,7 +2255,7 @@ if (!isNarrowString!(T[]) && !is(T[] == void[])) assert(a == [ 1, 2 ]); } -version(unittest) +@safe unittest { static assert(!is(typeof({ immutable int[] a; popBack(a); }))); static assert(!is(typeof({ int[4] a; popBack(a); }))); diff --git a/std/socket.d b/std/socket.d index 5301be676b8..111cd175f19 100644 --- a/std/socket.d +++ b/std/socket.d @@ -122,14 +122,10 @@ else version(unittest) { - static assert(is(uint32_t == uint)); - static assert(is(uint16_t == ushort)); - - import std.stdio : writefln; - // Print a message on exception instead of failing the unittest. private void softUnittest(void delegate() @safe test, int line = __LINE__) @trusted { + import std.stdio : writefln; try test(); catch (Throwable e) @@ -454,6 +450,7 @@ class Protocol version(CRuntime_Bionic) {} else @safe unittest { + // import std.stdio : writefln; softUnittest({ Protocol proto = new Protocol; assert(proto.getProtocolByType(ProtocolType.TCP)); @@ -555,6 +552,7 @@ class Service @safe unittest { + import std.stdio : writefln; softUnittest({ Service serv = new Service; if (serv.getServiceByName("epmap", "tcp")) diff --git a/std/traits.d b/std/traits.d index 627c4d85953..a2348e76711 100644 --- a/std/traits.d +++ b/std/traits.d @@ -527,7 +527,7 @@ template packageName(alias T) static assert(packageName!(X12287!int.i) == "std"); } -version (none) version(unittest) //Please uncomment me when changing packageName to test global imports +version (none) @safe unittest //Please uncomment me when changing packageName to test global imports { import core.sync.barrier; // global import static assert(packageName!core == "core"); @@ -582,7 +582,7 @@ template moduleName(alias T) static assert(moduleName!(X12287!int.i) == "std.traits"); } -version (none) version(unittest) //Please uncomment me when changing moduleName to test global imports +version (none) @safe unittest //Please uncomment me when changing moduleName to test global imports { import core.sync.barrier; // global import static assert(!__traits(compiles, moduleName!(core.sync)));