1 module tagion.basic.Debug;
2 
3 import std.exception : assumeWontThrow;
4 import std.format;
5 import std.stdio;
6 
7 /* 
8  * Function used information under debugging
9  * Should not be used to production code
10 * If the debug flag is enable the function can also be use in pure functions
11  * Params:
12  *   fmt = string format 
13  *   args = argument list
14  */
15 debug {
16     void __write(Args...)(string fmt, Args args) @trusted nothrow pure {
17         debug assumeWontThrow(stderr.writefln(fmt, args));
18     }
19 }
20 else {
21     void __write(Args...)(string fmt, Args args) @trusted nothrow pure {
22         pragma(msg, "Cannot call __write without debug flag");
23         // assumeWontThrow(stderr.writefln(fmt, args));
24     }
25 }
26 
27 /**
28 * This function is same as std.format made nonthow
29 * It's meant to be used in assert/pre-post
30 * Parans:
31 * fmt = string format
32 * args = argument list
33 */
34 debug {
35     string __format(Args...)(string fmt, Args args) @trusted nothrow pure {
36         string result;
37         debug {
38             result = assumeWontThrow(format(fmt, args));
39         }
40         return result;
41     }
42 }
43 else {
44     string __format(Args...)(string fmt, Args args) @trusted nothrow {
45         return assumeWontThrow(format(fmt, args));
46     }
47 }
48 
49 /* 
50  * 
51  * Params:
52  *   file = name for the test file
53  *   module_file = file path to the correct module
54  * Returns: 
55  * The absolute file path to the test-file
56  */
57 @safe
58 string testfile(string file, string module_file = __FILE__) {
59     import std.path;
60 
61     return buildPath(module_file.dirName, "unitdata", file);
62 }