shouldThrow

Used for asserting that a delegate will throw an exception.

  1. void shouldThrow(void delegate() cb, string file, size_t line)
  2. void shouldThrow(string message, void delegate() cb, string file, size_t line)
    void
    shouldThrow
    (
    string message
    ,
    void delegate
    ()
    cb
    ,
    string file = __FILE__
    ,
    size_t line = __LINE__
    )

Parameters

cb void delegate
()

The delegate that is expected to throw the exception.

message string

The message that is expected to be in the exception. Will not be tested, if it is null.

file string

The file name that the assert failed in. Should be left as default.

line size_t

The file line that the assert failed in. Should be left as default.

Throws

If delegate does NOT throw, will throw an AssertError.

Examples

// Makes sure it throws with the message "boom!"
shouldThrow("boom!", delegate() {
	throw new Exception("boom!");
});

// Will throw an exception like "AssertError@test/example.d(7): Exception was not thrown. Expected: boom!"
shouldThrow("boom!", delegate() {

});

Meta