Last active
June 12, 2024 12:37
-
-
Save WillSams/9e0ea2f83f184175412bc6fdfe8238e5 to your computer and use it in GitHub Desktop.
Asserts for Godot Testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Custom assertion function for equality | |
func assert_equal(actual, expected, message = 'Assertion failed: Values are not equal'): | |
if actual != expected: | |
var failure_message = 'Value did not equal: ' + message | |
push_error(failure_message) | |
else: | |
print('Pass') | |
# Custom assertion function for inequality | |
func assert_not_equal(actual, expected, message = 'Assertion failed: Values are equal'): | |
if actual == expected: | |
var failure_message = 'Values are equal: ' + message | |
push_error(failure_message) | |
else: | |
print('Pass') | |
# Custom assertion function for checking if a value is true | |
func assert_true(value, message = 'Assertion failed: Value is not true'): | |
if not value: | |
var failure_message = 'Value is not true: ' + message | |
push_error(failure_message) | |
else: | |
print('Pass') | |
# Custom assertion function for checking if a value is false | |
func assert_false(value, message = 'Assertion failed: Value is not false'): | |
if value: | |
var failure_message = 'Value is not false: ' + message | |
push_error(failure_message) | |
else: | |
print('Pass') | |
# Custom assertion function for checking if a value is not null (non-null) | |
func assert_not_null(value, message = 'Assertion failed: Value is null'): | |
if value == null: | |
var failure_message = 'Value is null: ' + message | |
push_error(failure_message) | |
else: | |
print('Pass') | |
# Custom assertion function for checking if a value is null | |
func assert_null(value, message = 'Assertion failed: Value is not null'): | |
if value != null: | |
var failure_message = 'Value is not null: ' + message | |
push_error(failure_message) | |
else: | |
print('Pass') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment