Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions std/digest/murmurhash.d
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,6 @@ the 'put' method.

version(unittest)
{
import std.string : representation;

private auto hash(H, Element = H.Element)(string data)
{
H hasher;
Expand Down
31 changes: 14 additions & 17 deletions std/internal/cstring.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting a trusted function like this in the global namespace is not a good idea.

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.

Expand Down Expand Up @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions std/math.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions std/net/isemail.d
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -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");
Expand Down
5 changes: 1 addition & 4 deletions std/numeric.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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)
{
Expand Down
11 changes: 3 additions & 8 deletions std/parallelism.d
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();
Expand Down Expand Up @@ -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;}
Expand All @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions std/path.d
Original file line number Diff line number Diff line change
Expand Up @@ -4144,11 +4144,6 @@ version(unittest)
C[] array;
}

static assert( isRandomAccessRange!(MockRange!(const(char))) );
}

version(unittest)
{
/* Define a mock BidirectionalRange to use for unittesting.
*/

Expand All @@ -4169,6 +4164,11 @@ version(unittest)
const(C)[] array;
}

}

@safe unittest
{
static assert( isRandomAccessRange!(MockRange!(const(char))) );
static assert( isBidirectionalRange!(MockBiRange!(const(char))) );
}

Expand Down
4 changes: 2 additions & 2 deletions std/range/primitives.d
Original file line number Diff line number Diff line change
Expand Up @@ -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); })));
Expand Down Expand Up @@ -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); })));
Expand Down
8 changes: 3 additions & 5 deletions std/socket.d
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,10 @@ else

version(unittest)
{
static assert(is(uint32_t == uint));
static assert(is(uint16_t == ushort));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, uint32_t and uint16_t are nowhere else in this file. I have no idea what these were for so I removed them. If they are critical to have, they should go somewhere else.


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)
Expand Down Expand Up @@ -454,6 +450,7 @@ class Protocol
version(CRuntime_Bionic) {} else
@safe unittest
{
// import std.stdio : writefln;
Copy link
Member Author

@schveiguy schveiguy Apr 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

writefln is used in commented out lines below. I put in this comment because before it was imported by the version(unittest) block.

softUnittest({
Protocol proto = new Protocol;
assert(proto.getProtocolByType(ProtocolType.TCP));
Expand Down Expand Up @@ -555,6 +552,7 @@ class Service

@safe unittest
{
import std.stdio : writefln;
softUnittest({
Service serv = new Service;
if (serv.getServiceByName("epmap", "tcp"))
Expand Down
4 changes: 2 additions & 2 deletions std/traits.d
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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)));
Expand Down