1 module dmocks.util;
2 
3 import std.conv;
4 import std.utf;
5 import std..string;
6 public import dmocks.interval;
7 
8 
9 string test(string name)() {
10     return `std.stdio.writefln(__FILE__~" line: %d"~": ` ~ name ~ ` test", __LINE__);
11             scope(failure) std.stdio.writeln("failed");
12             scope(success) std.stdio.writeln("success");`;
13 }
14 
15 string nullableToString(T)(T obj)
16 {
17     if (obj is null)
18         return "<null>";
19     return obj.to!string;
20 }
21 
22 void debugLog(T...)(lazy T args) @trusted nothrow
23 {
24     version (DMocksDebug) {
25         try {
26             std.stdio.writefln(args);
27         }
28         catch (Exception ex) {
29             assert (false, "Could not write to error log");
30         }
31     }
32 }
33 
34 template IsConcreteClass(T)
35 {
36     static if ((is (T == class)) && (!__traits(isAbstractClass, T)))
37     {
38         const bool IsConcreteClass = true;
39     }
40     else 
41     {
42         const bool IsConcreteClass = false;
43     }
44 }
45 
46 class InvalidOperationException : Exception 
47 {
48     this () { super(typeof(this).stringof ~ "The requested operation is not valid."); }
49     this (string msg) { super(typeof(this).stringof ~ msg); }
50 }
51 
52 
53 
54 public class ExpectationViolationException : Exception 
55 {
56     this (string msg, string file = __FILE__, size_t line = __LINE__) 
57     { 
58         super(msg);
59     }
60 }
61 
62 public class MocksSetupException : Exception {
63     this (string msg, string file = __FILE__, size_t line = __LINE__) {
64         super (typeof(this).stringof ~ ": " ~ msg);
65     }
66 }
67