1 /** 2 * Module to contain the module result class. 3 * 4 * License: 5 * MIT. See LICENSE for full details. 6 */ 7 module dunit.result.moduleresult; 8 9 /** 10 * Imports. 11 */ 12 import dunit.error; 13 14 /** 15 * A class to contain the result from running a module's unit tests. 16 */ 17 class ModuleResult 18 { 19 /** 20 * The name of the module which ran the unit test. 21 */ 22 private string _source; 23 24 /** 25 * The first error that occurred. If this is null, no errors occurred when running the modules unit tests. 26 * A module stops running any remaining unit tests if one throws an error. 27 */ 28 private DUnitAssertError _error; 29 30 /** 31 * Constructor. 32 * 33 * Params: 34 * name = The name of the module who's unit tests where run. 35 * error = An error, if it occurred. 36 */ 37 this(string name, DUnitAssertError error = null) 38 { 39 this._source = name; 40 this._error = error; 41 } 42 43 /** 44 * Access the name of the module. 45 * 46 * Returns: 47 * The name of the module that produced this result. 48 */ 49 public @property string source() 50 { 51 return this._source; 52 } 53 54 /** 55 * Access the error if one occurred. 56 * 57 * Returns: 58 * The error if one occurred, null if not. 59 */ 60 public @property DUnitAssertError error() 61 { 62 return this._error; 63 } 64 } 65 66 unittest 67 { 68 import dunit.toolkit; 69 70 auto result = new ModuleResult("Module", new DUnitAssertError("Message", "file.d", 1)); 71 result.source.assertEqual("Module"); 72 result.error.msg.assertEqual("Message"); 73 result.error.file.assertEqual("file.d"); 74 result.error.line.assertEqual(1); 75 result.error.log.assertEqual([]); 76 }