1 module exceeds_expectations.exceptions; 2 3 import exceeds_expectations.utils; 4 import std.algorithm; 5 import std.array; 6 import std.exception; 7 import std.file : readText; 8 9 10 /** 11 * Represents an assertion failure in exceeds_expectations. 12 */ 13 public class FailingExpectationException : Exception 14 { 15 /// Constructs a new FailingExpectationException 16 package this( 17 const string description, 18 const string location, 19 const string filePath = __FILE__, 20 size_t line = __LINE__, 21 Throwable next = null 22 ) 23 { 24 Appender!string message; 25 26 message.put(location); message.put('\n'); 27 28 message.put('\n'); 29 message.put(formatCode(readText(filePath), line, 2)); 30 31 if (description != "") 32 { 33 message.put('\n'); 34 message.put(description); 35 if (!description.endsWith("\n")) message.put("\n"); // Always terminate the message with at least two line breaks for readability. 36 message.put('\n'); 37 } 38 39 super(message.data, filePath, line, next); 40 } 41 } 42 43 44 /** 45 * Thrown when an expectation is used incorrectly. In other words, it indicates 46 * a problem in the test, not a problem in the implementation. 47 */ 48 public class InvalidExpectationException : Exception 49 { 50 /// Constructs a new InvalidExpectationException 51 package this(const string message, const string filePath = __FILE__, size_t line = __LINE__, Throwable next = null) 52 @safe pure nothrow 53 { 54 super(message, filePath, line, next); 55 } 56 }