diff --git a/README.md b/README.md index 658a809..889078d 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ # Crispy -Version 1.5.2 +Version 1.6.0 Unit testing framework built in GML for GameMaker Studio 2.3.6+ diff --git a/objects/obj_test/Create_0.gml b/objects/obj_test/Create_0.gml index 30c2011..0a86d38 100644 --- a/objects/obj_test/Create_0.gml +++ b/objects/obj_test/Create_0.gml @@ -64,9 +64,8 @@ results_max = 255; results_box = new gui_box(info_box.x1, info_box.y2 + 3, info_box.x2, room_height - 2); -// Defining Dracula Theme colors -// https://github.com/dracula/dracula-theme#color-palette -dracula_theme = { +// Defining colors +colors = { background: make_color_rgb(40, 42, 54), current_line: make_color_rgb(68, 71, 90), selection: make_color_rgb(68, 71, 90), @@ -80,4 +79,3 @@ dracula_theme = { red: make_color_rgb(255, 85, 85), yellow: make_color_rgb(241, 250, 140), } -colors = dracula_theme; diff --git a/scripts/TestCase/TestCase.gml b/scripts/TestCase/TestCase.gml index f70b385..1e912fb 100644 --- a/scripts/TestCase/TestCase.gml +++ b/scripts/TestCase/TestCase.gml @@ -84,7 +84,7 @@ function TestCase(_name, _func) : BaseTestClass(_name) constructor { addLog(new CrispyLog(self, { pass: false, msg: _message, - helper_text: "first and second are not equal: " + string(_first) + ", " + string(_second) + helper_text: "first and second are not equal: " + string(_first) + ", " + string(_second), })); } } @@ -155,7 +155,7 @@ function TestCase(_name, _func) : BaseTestClass(_name) constructor { addLog(new CrispyLog(self, { pass: false, msg: _message, - helper_text: "Expression is not true." + helper_text: "Expression is not true.", })); } } @@ -282,7 +282,7 @@ function TestCase(_name, _func) : BaseTestClass(_name) constructor { addLog(new CrispyLog(self, { pass: false, msg: _message, - helper_text: "Expression is not undefined." + helper_text: "Expression is not undefined.", })); } } @@ -316,6 +316,85 @@ function TestCase(_name, _func) : BaseTestClass(_name) constructor { } } + /** + * Test whether the provided function will throw an error message + * @function assertRaises + * @param {method} function - Function to check whether it throws an error message + * @param [string|undefined] message - Custom message to output on failure + */ + static assertRaises = function(_func, _message) { + // Check supplied arguments + if argument_count < 1 { + show_error(instanceof(self) + ".assertRaises() expected 1 argument, recieved " + string(argument_count) + ".", true); + } + if !is_method(_func) { + throw(instanceof(self) + ".assertRaises() \"func\" expected a method, received " + typeof(_func) + "."); + } + if !is_string(_message) && !is_undefined(_message) { + throw(instanceof(self) + ".assertRaises() \"message\" expected either a string or undefined, received " + typeof(_message) + "."); + } + try { + _func(); + addLog(new CrispyLog(self, { + pass: false, + msg: _message, + helper_text: "Error message was not thrown.", + })); + } + catch(err) { + addLog(new CrispyLog(self, { + pass: true, + })); + } + } + + /** + * Test the value of the error message thrown in the provided function + * @function assertRaiseErrorValue + * @param {method} function - Function ran to throw an error message + * @param {string} value - Value of error message to check + * @param [string|undefined] message - Custom message to output on failure + */ + static assertRaiseErrorValue = function(_func, _value, _message) { + // Check supplied arguments + if argument_count < 2 { + show_error(instanceof(self) + ".assertRaiseErrorValue() expected 2 arguments, recieved " + string(argument_count) + ".", true); + } + if !is_method(_func) { + throw(instanceof(self) + ".assertRaiseErrorValue() \"func\" expected a method, received " + typeof(_func) + "."); + } + if !is_string(_value) { + throw(instanceof(self) + ".assertRaiseErrorValue() \"value\" expected a string, received " + typeof(_value) + "."); + } + if !is_string(_message) && !is_undefined(_message) { + throw(instanceof(self) + ".assertRaiseErrorValue() \"message\" expected either a string or undefined, received " + typeof(_message) + "."); + } + try { + _func(); + addLog(new CrispyLog(self, { + pass: false, + helper_text: "Error message was not thrown.", + })); + } + catch(err) { + // If the error message was thrown using show_error, use the + // message value from the exception struct for the assertion + if is_struct(err) && variable_struct_exists(err, "message") && is_string(err.message) { + err = err.message; + } + if err == _value { + addLog(new CrispyLog(self), { + pass: true, + }); + } else { + addLog(new CrispyLog(self, { + pass: false, + msg: _message, + helper_text: "Error message is not equal to value: \"" + err + "\" != \"" + _value + "\"", + })); + } + } + } /** * Function ran before test, used to set up test diff --git a/scripts/__crispy_config_macros/__crispy_config_macros.gml b/scripts/__crispy_config_macros/__crispy_config_macros.gml index e6753b7..4e55612 100644 --- a/scripts/__crispy_config_macros/__crispy_config_macros.gml +++ b/scripts/__crispy_config_macros/__crispy_config_macros.gml @@ -1,7 +1,8 @@ #macro CRISPY_NAME "Crispy" #macro CRISPY_AUTHOR "Brent Frymire" -#macro CRISPY_VERSION "1.5.2" -#macro CRISPY_DATE "2022-7-21" +#macro CRISPY_REPO "https://github.com/bfrymire/crispy" +#macro CRISPY_VERSION "1.6.0" +#macro CRISPY_DATE "2022-8-26" #macro CRISPY_RUN true // Boolean flag that can be used to automatically run tests #macro CRISPY_DEBUG false // Enables outputting extra context on some silent functions