1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-09-27 12:57:41 +00:00

Improve the test suite

This commit is contained in:
Karol Stasiak 2020-04-06 13:27:39 +02:00
parent 5b3e812bb1
commit 49c916fea1
7 changed files with 103 additions and 13 deletions

1
.gitignore vendored
View File

@ -54,6 +54,7 @@ HELLOCPC
FIZZBUZZ
__hw_bbcmicro
__hw_cpc464
tests-cpc-*
#heap dumps
java_pid*

38
examples/tests/README.md Normal file
View File

@ -0,0 +1,38 @@
# The test suite
This is the semi-official test suite for Millfork standard libraries.
## Compiling
Compile the `main.mfk` file and run the resulting program.
You are advised to try various different optimization options.
millfork -t <platform> main.mfk
Supported platforms:
* Commodore 64, 128 and Plus/4, loadable program (`c64`, `c128`, `plus4`)
* ZX Spectrum (`zxspectrum`)
* NEC PC-88, bootable floppy (`pc88`)
* MSX, cartridge (`msx_crt`)
* Atari computers, loadable programs (`a8`)
* Amstrad CPC, loadable programs (`cpc464`)
Compiling with the `-D PRINT_SUCCESSES` will cause the suite to print all tests, including successful ones.
Otherwise, only failed tests will be printed.
On each failed the following message will be printed:
[FAIL] <suite name> #<assertion number>
To continue, press any key (on MSX, press RETURN).
At the end of a successful run, the test suite should print
Total failures: 0

View File

@ -1,10 +1,24 @@
import stdio
import keyboard
pointer current_suite_name
byte current_test_number
word failure_count = 0
#if ZX_SPECTRUM || CBM || NEC_PC88 || ATARI_8 || AMSTRAD_CPC
import keyboard
alias wait_after_failure = readkey
#elseif MSX
alias wait_after_failure = readline
#else
macro void wait_after_failure() { while true {} }
#endif
void start_suite(pointer suite_name) {
putstrz("Running "z)
putstrz(suite_name)
@ -14,7 +28,7 @@ void start_suite(pointer suite_name) {
}
void print_failure() {
putstrz("Test failed: "z)
putstrz("[FAIL]: "z)
putstrz(current_suite_name)
putstrz(" #"z)
putword(current_test_number)
@ -22,6 +36,14 @@ void print_failure() {
failure_count += 1
}
void print_success() {
putstrz("[ OK ]: "z)
putstrz(current_suite_name)
putstrz(" #"z)
putword(current_test_number)
new_line()
}
void assert_equal(word expected, word actual) {
current_test_number += 1
if actual != expected {
@ -31,7 +53,11 @@ void assert_equal(word expected, word actual) {
putstrz(" Actual: "z)
putword(actual)
new_line()
readkey()
wait_after_failure()
#if PRINT_SUCCESSES
} else {
print_success()
#endif
}
}
@ -40,11 +66,9 @@ void assert_true(bool result) {
if not(result) {
print_failure()
readkey()
#if PRINT_SUCCESSES
} else {
print_success()
#endif
}
}
void begin_test() {
}
void byte

View File

@ -1,15 +1,19 @@
import test_fibonacci
import test_pstring
import test_string
import test_encconv
void main() {
ensure_mixedcase()
// readkey()
test_fibonacci()
test_string()
test_pstring()
test_encconv()
new_line()
putstrz("Total failures: "z)
putword(failure_count)
}
while true {} // don't exit
}

View File

@ -0,0 +1,15 @@
import framework
import encconv
import scrstring
import string
void test_encconv() {
array buffer[256]
start_suite("encconv"z)
strzcopy(buffer, "test"z)
strz_to_screencode(buffer)
assert_equal(0, scrstrzcmp("test"scrz, buffer))
strz_from_screencode(buffer)
assert_equal(0, strzcmp("test"z, buffer))
}

View File

@ -4,6 +4,7 @@ import framework
void test_pstring() {
array buffer[256]
// #1-5
start_suite("pstring"z)
assert_equal(0, pstrcmp("a"p, "a"p))
assert_equal(-1, pstrcmp("a"p, "b"p))
@ -11,6 +12,7 @@ void test_pstring() {
assert_equal(1, pstrcmp("b"p, "a"p))
assert_equal(1, pstrcmp("ab"p, "a"p))
// #6-10
pstrcopy(buffer, "test"p)
assert_equal(4, pstrlen(buffer))
assert_equal(0, pstrcmp("test"p, buffer))
@ -19,5 +21,9 @@ void test_pstring() {
assert_equal(0, pstrcmp("testhello"p, buffer))
assert_equal(1234, pstr2word("1234"p))
// #11
pstrcopy(buffer, "test****test"p)
pstrpaste(buffer+5, "test"p)
assert_equal(0, pstrcmp("testtesttest"p, buffer))
}
}

View File

@ -19,5 +19,7 @@ void test_string() {
assert_equal(0, strzcmp("testhello"z, buffer))
assert_equal(1234, strz2word("1234"z))
}
strzcopy(buffer, "test****test"z)
strzpaste(buffer+4, "test"z)
assert_equal(0, strzcmp("testtesttest"z, buffer))
}