1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-07-10 10:28:55 +00:00
millfork/examples/tests/framework.mfk

75 lines
1.4 KiB
Plaintext
Raw Normal View History

2020-04-05 22:00:48 +00:00
import stdio
pointer current_suite_name
byte current_test_number
word failure_count = 0
#if ZX_SPECTRUM || CBM || NEC_PC88 || ATARI_8 || AMSTRAD_CPC || APPLE_2
2020-04-06 11:27:39 +00:00
import keyboard
alias wait_after_failure = readkey
#elseif MSX
alias wait_after_failure = readline
#else
macro void wait_after_failure() { while true {} }
#endif
2020-04-05 22:00:48 +00:00
void start_suite(pointer suite_name) {
putstrz("Running "z)
putstrz(suite_name)
new_line()
current_suite_name = suite_name
current_test_number = 0
}
void print_failure() {
2020-04-06 11:27:39 +00:00
putstrz("[FAIL]: "z)
2020-04-05 22:00:48 +00:00
putstrz(current_suite_name)
putstrz(" #"z)
putword(current_test_number)
new_line()
failure_count += 1
}
2020-04-06 11:27:39 +00:00
void print_success() {
putstrz("[ OK ]: "z)
putstrz(current_suite_name)
putstrz(" #"z)
putword(current_test_number)
new_line()
}
2020-04-05 22:00:48 +00:00
void assert_equal(word expected, word actual) {
2020-04-05 22:44:20 +00:00
current_test_number += 1
2020-04-05 22:00:48 +00:00
if actual != expected {
print_failure()
2020-04-05 22:44:20 +00:00
putstrz("Expected: "z)
2020-04-05 22:00:48 +00:00
putword(expected)
2020-04-05 22:44:20 +00:00
putstrz(" Actual: "z)
2020-04-05 22:00:48 +00:00
putword(actual)
new_line()
2020-04-06 11:27:39 +00:00
wait_after_failure()
#if PRINT_SUCCESSES
} else {
print_success()
#endif
2020-04-05 22:00:48 +00:00
}
}
2020-04-05 22:44:20 +00:00
void assert_true(bool result) {
current_test_number += 1
if not(result) {
print_failure()
readkey()
2020-04-06 11:27:39 +00:00
#if PRINT_SUCCESSES
} else {
print_success()
#endif
2020-04-05 22:44:20 +00:00
}
}