Replaced version (unittest) with version (StdUnittest) to avoid unnecessary overhead when compiling with -unittest

This commit is contained in:
Alexandru Militaru 2020-01-08 17:49:47 +02:00
parent e373b4e774
commit bb62aaca3d
44 changed files with 200 additions and 202 deletions

View file

@ -150,7 +150,7 @@ ifdef ENABLE_COVERAGE
override DFLAGS += -cov override DFLAGS += -cov
endif endif
UDFLAGS=-unittest UDFLAGS=-unittest -version=StdUnittest -version=CoreUnittest
# Set DOTOBJ and DOTEXE # Set DOTOBJ and DOTEXE
ifeq (,$(findstring win,$(OS))) ifeq (,$(findstring win,$(OS)))

View file

@ -14,7 +14,7 @@ package template algoFormat()
} }
// Internal random array generators // Internal random array generators
version (unittest) version (StdUnittest)
{ {
package enum size_t maxArraySize = 50; package enum size_t maxArraySize = 50;
package enum size_t minArraySize = maxArraySize - 1; package enum size_t minArraySize = maxArraySize - 1;

View file

@ -642,7 +642,7 @@ if (isRandomAccessRange!Range && hasLength!Range && hasSlicing!Range && hasAssig
for (;;) for (;;)
{ {
// Loop invariant // Loop invariant
version (unittest) version (StdUnittest)
{ {
// this used to import std.algorithm.all, but we want to save // this used to import std.algorithm.all, but we want to save
// imports when unittests are enabled if possible. // imports when unittests are enabled if possible.
@ -4082,7 +4082,7 @@ if (isRandomAccessRange!Range && hasLength!Range &&
else static if (k == 5) else static if (k == 5)
{ {
// Credit: Teppo Niinimäki // Credit: Teppo Niinimäki
version (unittest) scope(success) version (StdUnittest) scope(success)
{ {
assert(!lt(r[c], r[a]), "less than check failed"); assert(!lt(r[c], r[a]), "less than check failed");
assert(!lt(r[c], r[b]), "less than check failed"); assert(!lt(r[c], r[b]), "less than check failed");

View file

@ -222,7 +222,7 @@ if (isPointer!Range && isIterable!(PointerTarget!Range) && !isNarrowString!Range
assert(a.length == 5); assert(a.length == 5);
} }
version (unittest) version (StdUnittest)
private extern(C) void _d_delarray_t(void[] *p, TypeInfo_Struct ti); private extern(C) void _d_delarray_t(void[] *p, TypeInfo_Struct ti);
@system unittest @system unittest
@ -553,7 +553,7 @@ if (isInputRange!Values && isInputRange!Keys)
assert(c == expected); assert(c == expected);
} }
// @@@11053@@@ - Cannot be version (unittest) - recursive instantiation error // @@@11053@@@ - Cannot be version (StdUnittest) - recursive instantiation error
@safe unittest @safe unittest
{ {
import std.typecons; import std.typecons;
@ -4624,7 +4624,7 @@ nothrow pure @safe unittest
staticArray!(long, 2.iota).checkStaticArray!long([0, 1]); staticArray!(long, 2.iota).checkStaticArray!long([0, 1]);
} }
version (unittest) private void checkStaticArray(T, T1, T2)(T1 a, T2 b) nothrow @safe pure @nogc version (StdUnittest) private void checkStaticArray(T, T1, T2)(T1 a, T2 b) nothrow @safe pure @nogc
{ {
static assert(is(T1 == T[T1.length])); static assert(is(T1 == T[T1.length]));
assert(a == b, "a must be equal to b"); assert(a == b, "a must be equal to b");

View file

@ -363,7 +363,7 @@ template Base64Impl(char Map62th, char Map63th, char Padding = '=')
} }
// @@@BUG@@@ Workaround for DbC problem. See comment on 'out'. // @@@BUG@@@ Workaround for DbC problem. See comment on 'out'.
version (unittest) version (StdUnittest)
assert( assert(
bufptr - buffer.ptr == encodeLength(srcLen), bufptr - buffer.ptr == encodeLength(srcLen),
"The length of result is different from Base64" "The length of result is different from Base64"
@ -541,7 +541,7 @@ template Base64Impl(char Map62th, char Map63th, char Padding = '=')
} }
// @@@BUG@@@ Workaround for DbC problem. // @@@BUG@@@ Workaround for DbC problem.
version (unittest) version (StdUnittest)
assert( assert(
pcount == encodeLength(srcLen), pcount == encodeLength(srcLen),
"The number of put is different from the length of Base64" "The number of put is different from the length of Base64"
@ -1136,7 +1136,7 @@ template Base64Impl(char Map62th, char Map63th, char Padding = '=')
} }
// @@@BUG@@@ Workaround for DbC problem. // @@@BUG@@@ Workaround for DbC problem.
version (unittest) version (StdUnittest)
assert( assert(
(bufptr - buffer.ptr) >= (decodeLength(srcLen) - 2), (bufptr - buffer.ptr) >= (decodeLength(srcLen) - 2),
"The length of result is smaller than expected length" "The length of result is smaller than expected length"
@ -1321,7 +1321,7 @@ template Base64Impl(char Map62th, char Map63th, char Padding = '=')
} }
// @@@BUG@@@ Workaround for DbC problem. // @@@BUG@@@ Workaround for DbC problem.
version (unittest) version (StdUnittest)
assert( assert(
pcount >= (decodeLength(srcLen) - 2), pcount >= (decodeLength(srcLen) - 2),
"The length of result is smaller than expected length" "The length of result is smaller than expected length"

View file

@ -747,7 +747,7 @@ do
} }
// Make sure receive() works with free functions as well. // Make sure receive() works with free functions as well.
version (unittest) version (StdUnittest)
{ {
private void receiveFunction(int x) {} private void receiveFunction(int x) {}
} }

View file

@ -61,7 +61,7 @@ import std.functional : binaryFun;
public import std.container.util; public import std.container.util;
version (unittest) debug = RBDoChecks; version (StdUnittest) debug = RBDoChecks;
//debug = RBDoChecks; //debug = RBDoChecks;
@ -745,7 +745,7 @@ if (is(typeof(binaryFun!less(T.init, T.init))))
alias _less = binaryFun!less; alias _less = binaryFun!less;
version (unittest) version (StdUnittest)
{ {
static if (is(typeof(less) == string)) static if (is(typeof(less) == string))
{ {

View file

@ -1700,77 +1700,74 @@ if (!isImplicitlyConvertible!(S, T) && isAssociativeArray!S &&
assert(a.to!(const(int)[int]).byPair.equal(a.byPair)); assert(a.to!(const(int)[int]).byPair.equal(a.byPair));
} }
version (unittest)
private void testIntegralToFloating(Integral, Floating)()
{
Integral a = 42;
auto b = to!Floating(a);
assert(a == b);
assert(a == to!Integral(b));
}
version (unittest)
private void testFloatingToIntegral(Floating, Integral)()
{
bool convFails(Source, Target, E)(Source src)
{
try
cast(void) to!Target(src);
catch (E)
return true;
return false;
}
// convert some value
Floating a = 4.2e1;
auto b = to!Integral(a);
assert(is(typeof(b) == Integral) && b == 42);
// convert some negative value (if applicable)
a = -4.2e1;
static if (Integral.min < 0)
{
b = to!Integral(a);
assert(is(typeof(b) == Integral) && b == -42);
}
else
{
// no go for unsigned types
assert(convFails!(Floating, Integral, ConvOverflowException)(a));
}
// convert to the smallest integral value
a = 0.0 + Integral.min;
static if (Integral.min < 0)
{
a = -a; // -Integral.min not representable as an Integral
assert(convFails!(Floating, Integral, ConvOverflowException)(a)
|| Floating.sizeof <= Integral.sizeof);
}
a = 0.0 + Integral.min;
assert(to!Integral(a) == Integral.min);
--a; // no more representable as an Integral
assert(convFails!(Floating, Integral, ConvOverflowException)(a)
|| Floating.sizeof <= Integral.sizeof);
a = 0.0 + Integral.max;
assert(to!Integral(a) == Integral.max || Floating.sizeof <= Integral.sizeof);
++a; // no more representable as an Integral
assert(convFails!(Floating, Integral, ConvOverflowException)(a)
|| Floating.sizeof <= Integral.sizeof);
// convert a value with a fractional part
a = 3.14;
assert(to!Integral(a) == 3);
a = 3.99;
assert(to!Integral(a) == 3);
static if (Integral.min < 0)
{
a = -3.14;
assert(to!Integral(a) == -3);
a = -3.99;
assert(to!Integral(a) == -3);
}
}
@safe pure unittest @safe pure unittest
{ {
static void testIntegralToFloating(Integral, Floating)()
{
Integral a = 42;
auto b = to!Floating(a);
assert(a == b);
assert(a == to!Integral(b));
}
static void testFloatingToIntegral(Floating, Integral)()
{
bool convFails(Source, Target, E)(Source src)
{
try
cast(void) to!Target(src);
catch (E)
return true;
return false;
}
// convert some value
Floating a = 4.2e1;
auto b = to!Integral(a);
assert(is(typeof(b) == Integral) && b == 42);
// convert some negative value (if applicable)
a = -4.2e1;
static if (Integral.min < 0)
{
b = to!Integral(a);
assert(is(typeof(b) == Integral) && b == -42);
}
else
{
// no go for unsigned types
assert(convFails!(Floating, Integral, ConvOverflowException)(a));
}
// convert to the smallest integral value
a = 0.0 + Integral.min;
static if (Integral.min < 0)
{
a = -a; // -Integral.min not representable as an Integral
assert(convFails!(Floating, Integral, ConvOverflowException)(a)
|| Floating.sizeof <= Integral.sizeof);
}
a = 0.0 + Integral.min;
assert(to!Integral(a) == Integral.min);
--a; // no more representable as an Integral
assert(convFails!(Floating, Integral, ConvOverflowException)(a)
|| Floating.sizeof <= Integral.sizeof);
a = 0.0 + Integral.max;
assert(to!Integral(a) == Integral.max || Floating.sizeof <= Integral.sizeof);
++a; // no more representable as an Integral
assert(convFails!(Floating, Integral, ConvOverflowException)(a)
|| Floating.sizeof <= Integral.sizeof);
// convert a value with a fractional part
a = 3.14;
assert(to!Integral(a) == 3);
a = 3.99;
assert(to!Integral(a) == 3);
static if (Integral.min < 0)
{
a = -3.14;
assert(to!Integral(a) == -3);
a = -3.99;
assert(to!Integral(a) == -3);
}
}
alias AllInts = AliasSeq!(byte, ubyte, short, ushort, int, uint, long, ulong); alias AllInts = AliasSeq!(byte, ubyte, short, ushort, int, uint, long, ulong);
alias AllFloats = AliasSeq!(float, double, real); alias AllFloats = AliasSeq!(float, double, real);
alias AllNumerics = AliasSeq!(AllInts, AllFloats); alias AllNumerics = AliasSeq!(AllInts, AllFloats);
@ -4760,6 +4757,22 @@ if (is(T == class))
@nogc pure nothrow @safe unittest @nogc pure nothrow @safe unittest
{ {
static class __conv_EmplaceTestClass
{
int i = 3;
this(int i) @nogc @safe pure nothrow
{
assert(this.i == 3 && i == 5);
this.i = i;
}
this(int i, ref int j) @nogc @safe pure nothrow
{
assert(i == 5 && j == 6);
this.i = i;
++j;
}
}
int var = 6; int var = 6;
align(__conv_EmplaceTestClass.alignof) ubyte[__traits(classInstanceSize, __conv_EmplaceTestClass)] buf; align(__conv_EmplaceTestClass.alignof) ubyte[__traits(classInstanceSize, __conv_EmplaceTestClass)] buf;
auto support = (() @trusted => cast(__conv_EmplaceTestClass)(buf.ptr))(); auto support = (() @trusted => cast(__conv_EmplaceTestClass)(buf.ptr))();
@ -4827,42 +4840,7 @@ if (!is(T == class))
assert(u1.a == "hello"); assert(u1.a == "hello");
} }
version (unittest) private struct __conv_EmplaceTest
{
int i = 3;
this(int i)
{
assert(this.i == 3 && i == 5);
this.i = i;
}
this(int i, ref int j)
{
assert(i == 5 && j == 6);
this.i = i;
++j;
}
@disable:
this();
this(this);
void opAssign();
}
version (unittest) private class __conv_EmplaceTestClass
{
int i = 3;
this(int i) @nogc @safe pure nothrow
{
assert(this.i == 3 && i == 5);
this.i = i;
}
this(int i, ref int j) @nogc @safe pure nothrow
{
assert(i == 5 && j == 6);
this.i = i;
++j;
}
}
@system unittest // bugzilla 15772 @system unittest // bugzilla 15772
{ {
@ -4997,17 +4975,40 @@ version (unittest) private class __conv_EmplaceTestClass
@system unittest @system unittest
{ {
static struct __conv_EmplaceTest
{
int i = 3;
this(int i)
{
assert(this.i == 3 && i == 5);
this.i = i;
}
this(int i, ref int j)
{
assert(i == 5 && j == 6);
this.i = i;
++j;
}
@disable:
this();
this(this);
void opAssign();
}
__conv_EmplaceTest k = void; __conv_EmplaceTest k = void;
emplace(&k, 5); emplace(&k, 5);
assert(k.i == 5); assert(k.i == 5);
}
@system unittest
{
int var = 6; int var = 6;
__conv_EmplaceTest k = void; __conv_EmplaceTest x = void;
emplace(&k, 5, var); emplace(&x, 5, var);
assert(k.i == 5); assert(x.i == 5);
assert(var == 7);
var = 6;
auto z = emplace!__conv_EmplaceTest(new void[__conv_EmplaceTest.sizeof], 5, var);
assert(z.i == 5);
assert(var == 7); assert(var == 7);
} }
@ -5269,7 +5270,7 @@ version (unittest) private class __conv_EmplaceTestClass
} }
} }
version (unittest) version (StdUnittest)
{ {
//Ambiguity //Ambiguity
private struct __std_conv_S private struct __std_conv_S
@ -5687,10 +5688,6 @@ pure nothrow @safe /* @nogc */ unittest
@system unittest @system unittest
{ {
int var = 6;
auto k = emplace!__conv_EmplaceTest(new void[__conv_EmplaceTest.sizeof], 5, var);
assert(k.i == 5);
assert(var == 7);
} }
@system unittest @system unittest

View file

@ -45,7 +45,7 @@ import std.traits : isSomeString, Unqual;
import std.typecons : Flag; import std.typecons : Flag;
import std.range.primitives : isOutputRange; import std.range.primitives : isOutputRange;
version (unittest) import std.exception : assertThrown; version (StdUnittest) import std.exception : assertThrown;
@safe unittest @safe unittest
{ {
@ -10438,7 +10438,7 @@ if (isSomeString!T)
// NOTE: all the non-simple array literals are wrapped in functions, because // NOTE: all the non-simple array literals are wrapped in functions, because
// otherwise importing causes re-evaluation of the static initializers using // otherwise importing causes re-evaluation of the static initializers using
// CTFE with unittests enabled // CTFE with unittests enabled
version (unittest) version (StdUnittest)
{ {
private @safe: private @safe:
// All of these helper arrays are sorted in ascending order. // All of these helper arrays are sorted in ascending order.

View file

@ -41,7 +41,7 @@ import std.range.primitives : isOutputRange;
import std.traits : isIntegral, Unqual; import std.traits : isIntegral, Unqual;
import std.typecons : Flag; import std.typecons : Flag;
version (unittest) import std.exception : assertThrown; version (StdUnittest) import std.exception : assertThrown;
/++ /++

View file

@ -91,7 +91,7 @@ else version (Posix)
import core.sys.posix.sys.types : time_t; import core.sys.posix.sys.types : time_t;
} }
version (unittest) version (StdUnittest)
{ {
import core.exception : AssertError; import core.exception : AssertError;
import std.exception : assertThrown; import std.exception : assertThrown;
@ -10454,7 +10454,7 @@ afterMon: stripAndCheckLen(value[3 .. value.length], "1200:00A".length);
assertThrown!DateTimeException(parseRFC822DateTime(badStr)); assertThrown!DateTimeException(parseRFC822DateTime(badStr));
} }
version (unittest) private void testParse822(alias cr)(string str, SysTime expected, size_t line = __LINE__) version (StdUnittest) private void testParse822(alias cr)(string str, SysTime expected, size_t line = __LINE__)
{ {
import std.format : format; import std.format : format;
auto value = cr(str); auto value = cr(str);
@ -10463,7 +10463,7 @@ version (unittest) private void testParse822(alias cr)(string str, SysTime expec
throw new AssertError(format("wrong result. expected [%s], actual[%s]", expected, result), __FILE__, line); throw new AssertError(format("wrong result. expected [%s], actual[%s]", expected, result), __FILE__, line);
} }
version (unittest) private void testBadParse822(alias cr)(string str, size_t line = __LINE__) version (StdUnittest) private void testBadParse822(alias cr)(string str, size_t line = __LINE__)
{ {
try try
parseRFC822DateTime(cr(str)); parseRFC822DateTime(cr(str));
@ -11403,7 +11403,7 @@ if (isIntegral!T && isSigned!T) // The constraints on R were already covered by
// NOTE: all the non-simple array literals are wrapped in functions, because // NOTE: all the non-simple array literals are wrapped in functions, because
// otherwise importing causes re-evaluation of the static initializers using // otherwise importing causes re-evaluation of the static initializers using
// CTFE with unittests enabled // CTFE with unittests enabled
version (unittest) version (StdUnittest)
{ {
private @safe: private @safe:
// Variables to help in testing. // Variables to help in testing.

View file

@ -51,7 +51,7 @@ else version (Posix)
import core.sys.posix.sys.types : time_t; import core.sys.posix.sys.types : time_t;
} }
version (unittest) import std.exception : assertThrown; version (StdUnittest) import std.exception : assertThrown;
/++ /++

View file

@ -321,7 +321,7 @@ unittest
import std.digest.sha : SHA1, SHA256; import std.digest.sha : SHA1, SHA256;
// Note, can't be UFCS because we don't want to import inside // Note, can't be UFCS because we don't want to import inside
// version (unittest). // version (StdUnittest).
import std.digest : toHexString, LetterCase; import std.digest : toHexString, LetterCase;
alias hex = toHexString!(LetterCase.lower); alias hex = toHexString!(LetterCase.lower);

View file

@ -685,7 +685,7 @@ the 'put' method.
assert(hashed == [181, 151, 88, 252]); assert(hashed == [181, 151, 88, 252]);
} }
version (unittest) version (StdUnittest)
{ {
private auto hash(H, Element = H.Element)(string data) private auto hash(H, Element = H.Element)(string data)
{ {

View file

@ -1309,7 +1309,7 @@ bool mayPointTo(S, T)(auto ref const shared S source, ref const shared T target)
} }
version (unittest) version (StdUnittest)
{ {
// 17084 : the bug doesn't happen if these declarations are // 17084 : the bug doesn't happen if these declarations are
// in the unittest block (static or not). // in the unittest block (static or not).
@ -1851,7 +1851,7 @@ expression.
static assert(!__traits(compiles, (new Object()).ifThrown(e=>1))); static assert(!__traits(compiles, (new Object()).ifThrown(e=>1)));
} }
version (unittest) package version (StdUnittest) package
void assertCTFEable(alias dg)() void assertCTFEable(alias dg)()
{ {
static assert({ cast(void) dg(); return true; }()); static assert({ cast(void) dg(); return true; }());

View file

@ -566,7 +566,7 @@ shared struct SharedAlignedBlockList(Allocator, ParentAllocator, ulong theAlignm
tg.joinAll(); tg.joinAll();
} }
version (unittest) version (StdUnittest)
{ {
static void testrw(void[] b) static void testrw(void[] b)
{ {

View file

@ -663,7 +663,7 @@ public:
tg.joinAll(); tg.joinAll();
} }
version (unittest) version (StdUnittest)
{ {
private static void testrw(void[] b) @nogc nothrow private static void testrw(void[] b) @nogc nothrow
{ {

View file

@ -1640,7 +1640,7 @@ shared struct SharedBitmappedBlock(size_t theBlockSize, uint theAlignment = plat
} }
else else
{ {
version (unittest) version (StdUnittest)
@system unittest @system unittest
{ {
import std.algorithm.comparison : max; import std.algorithm.comparison : max;

View file

@ -482,7 +482,7 @@ Forwards each of the methods in `funs` (if defined) to `member`.
return result; return result;
} }
version (unittest) version (StdUnittest)
{ {
package void testAllocator(alias make)() package void testAllocator(alias make)()

View file

@ -2076,7 +2076,7 @@ if (isInputRange!R && !isInfinite!R)
assert(arr2.map!`a.val`.equal(iota(32, 204, 2))); assert(arr2.map!`a.val`.equal(iota(32, 204, 2)));
} }
version (unittest) version (StdUnittest)
{ {
private struct ForcedInputRange private struct ForcedInputRange
{ {

View file

@ -2709,7 +2709,7 @@ if (isIntegral!T && T.sizeof >= 4)
testPow!ulong(3, 41); testPow!ulong(3, 41);
} }
version (unittest) private struct CountOverflows version (StdUnittest) private struct CountOverflows
{ {
uint calls; uint calls;
auto onOverflow(string op, Lhs)(Lhs lhs) auto onOverflow(string op, Lhs)(Lhs lhs)
@ -2734,19 +2734,18 @@ version (unittest) private struct CountOverflows
} }
} }
version (unittest) private struct CountOpBinary
{
uint calls;
auto hookOpBinary(string op, Lhs, Rhs)(Lhs lhs, Rhs rhs)
{
++calls;
return mixin("lhs" ~ op ~ "rhs");
}
}
// opBinary // opBinary
@nogc nothrow pure @safe unittest @nogc nothrow pure @safe unittest
{ {
static struct CountOpBinary
{
uint calls;
auto hookOpBinary(string op, Lhs, Rhs)(Lhs lhs, Rhs rhs)
{
++calls;
return mixin("lhs" ~ op ~ "rhs");
}
}
auto x = Checked!(const int, void)(42), y = Checked!(immutable int, void)(142); auto x = Checked!(const int, void)(42), y = Checked!(immutable int, void)(142);
assert(x + y == 184); assert(x + y == 184);
assert(x + 100 == 142); assert(x + 100 == 142);

View file

@ -1846,7 +1846,7 @@ package class TestLogger : Logger
} }
} }
version (unittest) private void testFuncNames(Logger logger) @safe version (StdUnittest) private void testFuncNames(Logger logger) @safe
{ {
string s = "I'm here"; string s = "I'm here";
logger.log(s); logger.log(s);

View file

@ -131,7 +131,7 @@ else
return fileName; return fileName;
} }
version (unittest) private struct TestAliasedString version (StdUnittest) private struct TestAliasedString
{ {
string get() @safe @nogc pure nothrow { return _s; } string get() @safe @nogc pure nothrow { return _s; }
alias get this; alias get this;
@ -3396,7 +3396,7 @@ version (Windows) string getcwd() @trusted
3. the buffer (lpBuffer) is not large enough: the required size of 3. the buffer (lpBuffer) is not large enough: the required size of
the buffer, in characters, including the null-terminating character. the buffer, in characters, including the null-terminating character.
*/ */
version (unittest) version (StdUnittest)
enum BUF_SIZE = 10; // trigger reallocation code enum BUF_SIZE = 10; // trigger reallocation code
else else
enum BUF_SIZE = 4096; // enough for most common case enum BUF_SIZE = 4096; // enough for most common case

View file

@ -4241,7 +4241,7 @@ if (is(T == class) && !is(T == enum))
// outside the unittest block, otherwise the FQN of the // outside the unittest block, otherwise the FQN of the
// class contains the line number of the unittest // class contains the line number of the unittest
version (unittest) version (StdUnittest)
{ {
private class C {} private class C {}
} }
@ -4866,7 +4866,7 @@ private T getNth(string kind, alias Condition, T, A...)(uint index, A args)
/* ======================== Unit Tests ====================================== */ /* ======================== Unit Tests ====================================== */
version (unittest) version (StdUnittest)
private void formatTest(T)(T val, string expected, size_t ln = __LINE__, string fn = __FILE__) private void formatTest(T)(T val, string expected, size_t ln = __LINE__, string fn = __FILE__)
{ {
import core.exception : AssertError; import core.exception : AssertError;
@ -4880,7 +4880,7 @@ private void formatTest(T)(T val, string expected, size_t ln = __LINE__, string
text("expected = `", expected, "`, result = `", w.data, "`"), fn, ln); text("expected = `", expected, "`, result = `", w.data, "`"), fn, ln);
} }
version (unittest) version (StdUnittest)
private void formatTest(T)(string fmt, T val, string expected, size_t ln = __LINE__, string fn = __FILE__) @safe private void formatTest(T)(string fmt, T val, string expected, size_t ln = __LINE__, string fn = __FILE__) @safe
{ {
import core.exception : AssertError; import core.exception : AssertError;
@ -4893,7 +4893,7 @@ private void formatTest(T)(string fmt, T val, string expected, size_t ln = __LIN
text("expected = `", expected, "`, result = `", w.data, "`"), fn, ln); text("expected = `", expected, "`, result = `", w.data, "`"), fn, ln);
} }
version (unittest) version (StdUnittest)
private void formatTest(T)(T val, string[] expected, size_t ln = __LINE__, string fn = __FILE__) private void formatTest(T)(T val, string[] expected, size_t ln = __LINE__, string fn = __FILE__)
{ {
import core.exception : AssertError; import core.exception : AssertError;
@ -4911,7 +4911,7 @@ private void formatTest(T)(T val, string[] expected, size_t ln = __LINE__, strin
text("expected one of `", expected, "`, result = `", w.data, "`"), fn, ln); text("expected one of `", expected, "`, result = `", w.data, "`"), fn, ln);
} }
version (unittest) version (StdUnittest)
private void formatTest(T)(string fmt, T val, string[] expected, size_t ln = __LINE__, string fn = __FILE__) @safe private void formatTest(T)(string fmt, T val, string[] expected, size_t ln = __LINE__, string fn = __FILE__) @safe
{ {
import core.exception : AssertError; import core.exception : AssertError;
@ -5359,7 +5359,7 @@ here:
assert(a == "hello" && b == 124 && c == 34.5); assert(a == "hello" && b == 124 && c == 34.5);
} }
version (unittest) version (StdUnittest)
private void formatReflectTest(T)(ref T val, string fmt, string formatted, string fn = __FILE__, size_t ln = __LINE__) private void formatReflectTest(T)(ref T val, string fmt, string formatted, string fn = __FILE__, size_t ln = __LINE__)
{ {
import core.exception : AssertError; import core.exception : AssertError;
@ -5401,7 +5401,7 @@ private void formatReflectTest(T)(ref T val, string fmt, string formatted, strin
input, fn, ln); input, fn, ln);
} }
version (unittest) version (StdUnittest)
private void formatReflectTest(T)(ref T val, string fmt, string[] formatted, string fn = __FILE__, size_t ln = __LINE__) private void formatReflectTest(T)(ref T val, string fmt, string[] formatted, string fn = __FILE__, size_t ln = __LINE__)
{ {
import core.exception : AssertError; import core.exception : AssertError;

View file

@ -252,7 +252,7 @@ private:
To* _ptr; To* _ptr;
size_t _length; // length of the string size_t _length; // length of the string
version (unittest) version (StdUnittest)
// the 'small string optimization' // the 'small string optimization'
{ {
// smaller size to trigger reallocations. Padding is to account for // smaller size to trigger reallocations. Padding is to account for

View file

@ -1355,7 +1355,7 @@ int highestPowerBelowUlongMax(uint x) pure nothrow @safe
return 2; return 2;
} }
version (unittest) version (StdUnittest)
{ {
private int slowHighestPowerBelowUintMax(uint x) pure nothrow @safe private int slowHighestPowerBelowUintMax(uint x) pure nothrow @safe

View file

@ -186,7 +186,7 @@ else version (X86)
private alias haveSSE = core.cpuid.sse; private alias haveSSE = core.cpuid.sse;
} }
version (unittest) private version (StdUnittest) private
{ {
static if (real.sizeof > double.sizeof) static if (real.sizeof > double.sizeof)
enum uint useDigits = 16; enum uint useDigits = 16;

View file

@ -921,7 +921,7 @@ template Filter(alias pred, TList...)
// Used in template predicate unit tests below. // Used in template predicate unit tests below.
private version (unittest) private version (StdUnittest)
{ {
template testAlways(T...) template testAlways(T...)
{ {

View file

@ -164,7 +164,7 @@ import std.encoding : EncodingScheme;
import std.traits : isSomeChar; import std.traits : isSomeChar;
import std.typecons : Flag, Yes, No, Tuple; import std.typecons : Flag, Yes, No, Tuple;
version (unittest) version (StdUnittest)
{ {
import std.socket : Socket, SocketShutdown; import std.socket : Socket, SocketShutdown;
@ -222,7 +222,9 @@ version (unittest)
return TestServer(addr, tid, sock); return TestServer(addr, tid, sock);
} }
/** Test server */
__gshared TestServer server; __gshared TestServer server;
/** Thread-local storage init */
bool tlsInit; bool tlsInit;
private ref TestServer testServer() private ref TestServer testServer()

View file

@ -251,7 +251,7 @@ class OutBuffer
import core.stdc.stdlib : alloca; import core.stdc.stdlib : alloca;
import std.string : toStringz; import std.string : toStringz;
version (unittest) version (StdUnittest)
char[3] buffer = void; // trigger reallocation char[3] buffer = void; // trigger reallocation
else else
char[128] buffer = void; char[128] buffer = void;

View file

@ -4132,7 +4132,7 @@ private struct RoundRobinBuffer(C1, C2)
} }
} }
version (unittest) version (StdUnittest)
{ {
// This was the only way I could get nested maps to work. // This was the only way I could get nested maps to work.
private __gshared TaskPool poolInstance; private __gshared TaskPool poolInstance;

View file

@ -101,7 +101,7 @@ static import std.meta;
import std.range.primitives; import std.range.primitives;
import std.traits; import std.traits;
version (unittest) version (StdUnittest)
{ {
private: private:
struct TestAliasedString struct TestAliasedString
@ -4031,7 +4031,7 @@ string expandTilde(string inputPath) @safe nothrow
assert(last_char > 1); assert(last_char > 1);
// Reserve C memory for the getpwnam_r() function. // Reserve C memory for the getpwnam_r() function.
version (unittest) version (StdUnittest)
uint extra_memory_size = 2; uint extra_memory_size = 2;
else else
uint extra_memory_size = 5 * 1024; uint extra_memory_size = 5 * 1024;
@ -4152,7 +4152,7 @@ string expandTilde(string inputPath) @safe nothrow
} }
} }
version (unittest) version (StdUnittest)
{ {
private: private:
/* Define a mock RandomAccessRange to use for unittesting. /* Define a mock RandomAccessRange to use for unittesting.

View file

@ -2753,7 +2753,7 @@ version (Windows) private immutable string shellSwitch = "/C";
// file. On Windows the file name gets a .cmd extension, while on // file. On Windows the file name gets a .cmd extension, while on
// POSIX its executable permission bit is set. The file is // POSIX its executable permission bit is set. The file is
// automatically deleted when the object goes out of scope. // automatically deleted when the object goes out of scope.
version (unittest) version (StdUnittest)
private struct TestScript private struct TestScript
{ {
this(string code) @system this(string code) @system
@ -2797,7 +2797,7 @@ private struct TestScript
string path; string path;
} }
version (unittest) version (StdUnittest)
private string uniqueTempPath() @safe private string uniqueTempPath() @safe
{ {
import std.file : tempDir; import std.file : tempDir;
@ -3096,7 +3096,7 @@ if (is(typeof(allocator(size_t.init)[0] = char.init)))
return buf; return buf;
} }
version (Windows) version (unittest) version (Windows) version (StdUnittest)
{ {
private: private:
import core.stdc.stddef; import core.stdc.stddef;

View file

@ -161,7 +161,7 @@ import std.traits;
assert([0, 1, 2, 4, 5].randomShuffle(rnd2).equal([2, 0, 4, 5, 1])); assert([0, 1, 2, 4, 5].randomShuffle(rnd2).equal([2, 0, 4, 5, 1]));
} }
version (unittest) version (StdUnittest)
{ {
static import std.meta; static import std.meta;
package alias Xorshift64_64 = XorshiftEngine!(ulong, 64, -12, 25, -27); package alias Xorshift64_64 = XorshiftEngine!(ulong, 64, -12, 25, -27);

View file

@ -120,7 +120,7 @@ else
static assert(0, "No socket support for this platform yet."); static assert(0, "No socket support for this platform yet.");
} }
version (unittest) version (StdUnittest)
{ {
// Print a message on exception instead of failing the unittest. // Print a message on exception instead of failing the unittest.
private void softUnittest(void delegate() @safe test, int line = __LINE__) @trusted private void softUnittest(void delegate() @safe test, int line = __LINE__) @trusted

View file

@ -5501,7 +5501,7 @@ version (linux)
} }
} }
version (unittest) private string testFilename(string file = __FILE__, size_t line = __LINE__) @safe version (StdUnittest) private string testFilename(string file = __FILE__, size_t line = __LINE__) @safe
{ {
import std.conv : text; import std.conv : text;
import std.file : deleteme; import std.file : deleteme;

View file

@ -143,7 +143,7 @@ Source: $(PHOBOSSRC std/string.d)
*/ */
module std.string; module std.string;
version (unittest) version (StdUnittest)
{ {
private: private:
struct TestAliasedString struct TestAliasedString

View file

@ -470,7 +470,7 @@ template QualifierOf(T)
alias Qual7 = QualifierOf!( immutable int); static assert(is(Qual7!long == immutable long)); alias Qual7 = QualifierOf!( immutable int); static assert(is(Qual7!long == immutable long));
} }
version (unittest) version (StdUnittest)
{ {
alias TypeQualifierList = AliasSeq!(MutableOf, ConstOf, SharedOf, SharedConstOf, ImmutableOf); alias TypeQualifierList = AliasSeq!(MutableOf, ConstOf, SharedOf, SharedConstOf, ImmutableOf);
@ -653,7 +653,7 @@ if (T.length == 1)
static assert(fullyQualifiedName!fullyQualifiedName == "std.traits.fullyQualifiedName"); static assert(fullyQualifiedName!fullyQualifiedName == "std.traits.fullyQualifiedName");
} }
version (unittest) version (StdUnittest)
{ {
// Used for both fqnType and fqnSym unittests // Used for both fqnType and fqnSym unittests
private struct QualifiedNameTests private struct QualifiedNameTests
@ -2463,7 +2463,7 @@ if (is(T == function))
assert(g() > 0); assert(g() > 0);
} }
version (unittest) version (StdUnittest)
{ {
private: private:
// Some function types to test. // Some function types to test.
@ -8064,7 +8064,7 @@ if (sth.length == 1)
static assert(TL == AliasSeq!("i", "xi", "yi")); static assert(TL == AliasSeq!("i", "xi", "yi"));
} }
version (unittest) private void freeFunc(string); version (StdUnittest) private void freeFunc(string);
@safe unittest @safe unittest
{ {
@ -8601,7 +8601,7 @@ template getSymbolsByUDA(alias symbol, alias attribute)
} }
// Issue 20054: getSymbolsByUDA no longer works on modules // Issue 20054: getSymbolsByUDA no longer works on modules
version (unittest) version (StdUnittest)
{ {
@("Issue20054") @("Issue20054")
void issue20054() {} void issue20054() {}

View file

@ -4957,7 +4957,7 @@ private static:
alias Implementation = AutoImplement!(Issue17177, how, templateNot!isFinalFunction); alias Implementation = AutoImplement!(Issue17177, how, templateNot!isFinalFunction);
} }
version (unittest) version (StdUnittest)
{ {
// Issue 10647 // Issue 10647
// Add prefix "issue10647_" as a workaround for issue 1238 // Add prefix "issue10647_" as a workaround for issue 1238

View file

@ -7219,7 +7219,7 @@ if (isInputRange!Range && is(Unqual!(ElementType!Range) == dchar))
} }
// For testing non-forward-range input ranges // For testing non-forward-range input ranges
version (unittest) version (StdUnittest)
private static struct InputRangeString private static struct InputRangeString
{ {
private string s; private string s;

View file

@ -1858,7 +1858,7 @@ unittest
} }
version (unittest) private void testDecode(R)(R range, version (StdUnittest) private void testDecode(R)(R range,
size_t index, size_t index,
dchar expectedChar, dchar expectedChar,
size_t expectedIndex, size_t expectedIndex,
@ -1888,7 +1888,7 @@ version (unittest) private void testDecode(R)(R range,
} }
} }
version (unittest) private void testDecodeFront(R)(ref R range, version (StdUnittest) private void testDecodeFront(R)(ref R range,
dchar expectedChar, dchar expectedChar,
size_t expectedNumCodeUnits, size_t expectedNumCodeUnits,
size_t line = __LINE__) size_t line = __LINE__)
@ -1914,7 +1914,7 @@ version (unittest) private void testDecodeFront(R)(ref R range,
} }
} }
version (unittest) private void testDecodeBack(R)(ref R range, version (StdUnittest) private void testDecodeBack(R)(ref R range,
dchar expectedChar, dchar expectedChar,
size_t expectedNumCodeUnits, size_t expectedNumCodeUnits,
size_t line = __LINE__) size_t line = __LINE__)
@ -1946,7 +1946,7 @@ version (unittest) private void testDecodeBack(R)(ref R range,
} }
} }
version (unittest) private void testAllDecode(R)(R range, version (StdUnittest) private void testAllDecode(R)(R range,
dchar expectedChar, dchar expectedChar,
size_t expectedIndex, size_t expectedIndex,
size_t line = __LINE__) size_t line = __LINE__)
@ -1960,7 +1960,7 @@ version (unittest) private void testAllDecode(R)(R range,
testDecodeFront(range, expectedChar, expectedIndex, line); testDecodeFront(range, expectedChar, expectedIndex, line);
} }
version (unittest) private void testBadDecode(R)(R range, size_t index, size_t line = __LINE__) version (StdUnittest) private void testBadDecode(R)(R range, size_t index, size_t line = __LINE__)
{ {
import core.exception : AssertError; import core.exception : AssertError;
import std.exception : assertThrown, enforce; import std.exception : assertThrown, enforce;
@ -1987,7 +1987,7 @@ version (unittest) private void testBadDecode(R)(R range, size_t index, size_t l
assertThrown!UTFException(decodeFront(range, index), null, __FILE__, line); assertThrown!UTFException(decodeFront(range, index), null, __FILE__, line);
} }
version (unittest) private void testBadDecodeBack(R)(R range, size_t line = __LINE__) version (StdUnittest) private void testBadDecodeBack(R)(R range, size_t line = __LINE__)
{ {
// This condition is to allow unit testing all `decode` functions together // This condition is to allow unit testing all `decode` functions together
static if (!isBidirectionalRange!R) static if (!isBidirectionalRange!R)
@ -3391,7 +3391,7 @@ if (isSomeChar!C)
// Ranges of code units for testing. // Ranges of code units for testing.
version (unittest) version (StdUnittest)
{ {
private: private:
struct InputCU(C) struct InputCU(C)
@ -4148,7 +4148,7 @@ pure @safe nothrow @nogc unittest
foreach (c; s[].byDchar()) { } foreach (c; s[].byDchar()) { }
} }
version (unittest) version (StdUnittest)
private int impureVariable; private int impureVariable;
@system unittest @system unittest

View file

@ -81,7 +81,7 @@ class Win32Exception : WindowsException
@property int error() { return super.code; } @property int error() { return super.code; }
} }
version (unittest) import std.string : startsWith, endsWith; version (StdUnittest) import std.string : startsWith, endsWith;
@safe unittest @safe unittest
{ {

View file

@ -47,7 +47,7 @@ DFLAGS=-conf= -O -release -w -de -preview=dip1000 -transition=complex -I$(DRUNTI
## Flags for compiling unittests ## Flags for compiling unittests
UDFLAGS=-unittest -conf= -O -w -preview=dip1000 -transition=complex -I$(DRUNTIME)\import UDFLAGS=-unittest -version=StdUnittest -version=CoreUnittest -conf= -O -w -preview=dip1000 -transition=complex -I$(DRUNTIME)\import
## C compiler ## C compiler

View file

@ -50,7 +50,7 @@ DFLAGS=-conf= -m$(MODEL) -O -release -w -de -preview=dip1000 -transition=complex
## Flags for compiling unittests ## Flags for compiling unittests
UDFLAGS=-conf= -g -m$(MODEL) -O -w -preview=dip1000 -transition=complex -I$(DRUNTIME)\import -unittest UDFLAGS=-conf= -g -m$(MODEL) -O -w -preview=dip1000 -transition=complex -I$(DRUNTIME)\import -unittest -version=StdUnittest -version=CoreUnittest
## C compiler, linker, librarian ## C compiler, linker, librarian