mirror of
https://github.com/dlang/phobos.git
synced 2025-05-01 15:40:36 +03:00
Merge pull request #8060 from atilaneves/std-file-safe-ut
Make unittests in std.file @safe
This commit is contained in:
commit
33b19c7cc1
1 changed files with 19 additions and 15 deletions
34
std/file.d
34
std/file.d
|
@ -629,7 +629,7 @@ if (isSomeString!S && (isInputRange!R && !isInfinite!R && isSomeChar!(ElementTyp
|
||||||
static assert(__traits(compiles, readText(TestAliasedString(null))));
|
static assert(__traits(compiles, readText(TestAliasedString(null))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@system unittest
|
@safe unittest
|
||||||
{
|
{
|
||||||
import std.array : appender;
|
import std.array : appender;
|
||||||
import std.bitmanip : append, Endian;
|
import std.bitmanip : append, Endian;
|
||||||
|
@ -748,7 +748,7 @@ if ((isInputRange!R && !isInfinite!R && isSomeChar!(ElementEncodingType!R) || is
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
@system unittest
|
@safe unittest
|
||||||
{
|
{
|
||||||
scope(exit)
|
scope(exit)
|
||||||
{
|
{
|
||||||
|
@ -758,7 +758,9 @@ if ((isInputRange!R && !isInfinite!R && isSomeChar!(ElementEncodingType!R) || is
|
||||||
|
|
||||||
int[] a = [ 0, 1, 1, 2, 3, 5, 8 ];
|
int[] a = [ 0, 1, 1, 2, 3, 5, 8 ];
|
||||||
write(deleteme, a); // deleteme is the name of a temporary file
|
write(deleteme, a); // deleteme is the name of a temporary file
|
||||||
assert(cast(int[]) read(deleteme) == a);
|
const bytes = read(deleteme);
|
||||||
|
const fileInts = () @trusted { return cast(int[]) bytes; }();
|
||||||
|
assert(fileInts == a);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ditto
|
/// ditto
|
||||||
|
@ -795,7 +797,7 @@ if ((isInputRange!R && !isInfinite!R && isSomeChar!(ElementEncodingType!R) || is
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
@system unittest
|
@safe unittest
|
||||||
{
|
{
|
||||||
scope(exit)
|
scope(exit)
|
||||||
{
|
{
|
||||||
|
@ -807,7 +809,9 @@ if ((isInputRange!R && !isInfinite!R && isSomeChar!(ElementEncodingType!R) || is
|
||||||
write(deleteme, a); // deleteme is the name of a temporary file
|
write(deleteme, a); // deleteme is the name of a temporary file
|
||||||
int[] b = [ 13, 21 ];
|
int[] b = [ 13, 21 ];
|
||||||
append(deleteme, b);
|
append(deleteme, b);
|
||||||
assert(cast(int[]) read(deleteme) == a ~ b);
|
const bytes = read(deleteme);
|
||||||
|
const fileInts = () @trusted { return cast(int[]) bytes; }();
|
||||||
|
assert(fileInts == a ~ b);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ditto
|
/// ditto
|
||||||
|
@ -1303,7 +1307,7 @@ if (isConvertibleToString!R)
|
||||||
static assert(__traits(compiles, getTimes(TestAliasedString("foo"), atime, mtime)));
|
static assert(__traits(compiles, getTimes(TestAliasedString("foo"), atime, mtime)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@system unittest
|
@safe unittest
|
||||||
{
|
{
|
||||||
import std.stdio : writefln;
|
import std.stdio : writefln;
|
||||||
|
|
||||||
|
@ -1312,8 +1316,8 @@ if (isConvertibleToString!R)
|
||||||
write(deleteme, "a");
|
write(deleteme, "a");
|
||||||
scope(exit) assert(deleteme.exists), deleteme.remove;
|
scope(exit) assert(deleteme.exists), deleteme.remove;
|
||||||
|
|
||||||
SysTime accessTime1 = void;
|
SysTime accessTime1;
|
||||||
SysTime modificationTime1 = void;
|
SysTime modificationTime1;
|
||||||
|
|
||||||
getTimes(deleteme, accessTime1, modificationTime1);
|
getTimes(deleteme, accessTime1, modificationTime1);
|
||||||
|
|
||||||
|
@ -1616,7 +1620,7 @@ private void setTimesImpl(scope const(char)[] names, scope const(FSChar)* namez,
|
||||||
setTimes(TestAliasedString("foo"), SysTime.init, SysTime.init);
|
setTimes(TestAliasedString("foo"), SysTime.init, SysTime.init);
|
||||||
}
|
}
|
||||||
|
|
||||||
@system unittest
|
@safe unittest
|
||||||
{
|
{
|
||||||
import std.stdio : File;
|
import std.stdio : File;
|
||||||
string newdir = deleteme ~ r".dir";
|
string newdir = deleteme ~ r".dir";
|
||||||
|
@ -1885,7 +1889,7 @@ else version (Posix)
|
||||||
version (FreeBSD) {} else
|
version (FreeBSD) {} else
|
||||||
version (DragonFlyBSD) {} else
|
version (DragonFlyBSD) {} else
|
||||||
version (OSX) {} else
|
version (OSX) {} else
|
||||||
@system unittest
|
@safe unittest
|
||||||
{
|
{
|
||||||
import core.thread;
|
import core.thread;
|
||||||
|
|
||||||
|
@ -1900,7 +1904,7 @@ version (OSX) {} else
|
||||||
remove(deleteme);
|
remove(deleteme);
|
||||||
assert(time != lastTime);
|
assert(time != lastTime);
|
||||||
lastTime = time;
|
lastTime = time;
|
||||||
Thread.sleep(20.msecs);
|
() @trusted { Thread.sleep(20.msecs); }();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2403,7 +2407,7 @@ if (isConvertibleToString!R)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@system unittest
|
@safe unittest
|
||||||
{
|
{
|
||||||
version (Windows)
|
version (Windows)
|
||||||
enum dir = "C:\\Program Files\\";
|
enum dir = "C:\\Program Files\\";
|
||||||
|
@ -2554,7 +2558,7 @@ if (isConvertibleToString!R)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://issues.dlang.org/show_bug.cgi?id=15658
|
// https://issues.dlang.org/show_bug.cgi?id=15658
|
||||||
@system unittest
|
@safe unittest
|
||||||
{
|
{
|
||||||
DirEntry e = DirEntry(".");
|
DirEntry e = DirEntry(".");
|
||||||
static assert(is(typeof(isFile(e))));
|
static assert(is(typeof(isFile(e))));
|
||||||
|
@ -3063,7 +3067,7 @@ void mkdirRecurse(scope const(char)[] pathname) @safe
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
@system unittest
|
@safe unittest
|
||||||
{
|
{
|
||||||
import std.path : buildPath;
|
import std.path : buildPath;
|
||||||
|
|
||||||
|
@ -3188,7 +3192,7 @@ if (isConvertibleToString!R)
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
@system unittest
|
@safe unittest
|
||||||
{
|
{
|
||||||
auto dir = deleteme ~ "dir";
|
auto dir = deleteme ~ "dir";
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue