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