Tests: print expected return value and real return value. Also allow printing this only for failed tests (preventing more output to console)

This commit is contained in:
2025-07-21 16:04:25 +02:00
parent ad559062ef
commit 34de8f351d

View File

@@ -20,16 +20,24 @@
%macro assert 3
inc r13
mov rsi, %1
mov rdx, %1
mov rcx, rax
cmp rax, %1
%2 %%true
lea rdx, [rel testMsg_False]
lea r8, [rel testMsg_False]
jmp %%cnt
%%true:
inc r14
lea rdx, [rel testMsg_True]
%if TESTS_PRINT_ALL_OUTPUTS
lea r8, [rel testMsg_True]
%else
jmp %%end
%endif
%%cnt:
lea rdi, [rel %3]
call printf
%%end:
nop
%endmacro
;core.asm
@@ -63,6 +71,8 @@ section .rodata
;;;
;;; enable/disable tests
;;;
TESTS_PRINT_ALL_OUTPUTS equ 1 ;If set to 0, only print expected/got and FAIL if failed. Otherwise always print outputs.
;Note: when set to 0, tests are silent (ie it prints the current test and does not print any output, not even OK)
;core.asm
TEST_islower equ 1
TEST_isupper equ 1
@@ -92,20 +102,20 @@ section .rodata
;;;
;;; Global test messages
;;;
testMsg_assertIEqual db "\t\tassert(output == %d): %s",NL,EOS
testMsg_assertINEqual db "\t\tassert(output != %d): %s",NL,EOS
testMsg_assertILess db "\t\tassert(output < %d): %s",NL,EOS
testMsg_assertILessE db "\t\tassert(output <= %d): %s",NL,EOS
testMsg_assertIMore db "\t\tassert(output > %d): %s",NL,EOS
testMsg_assertIMoreE db "\t\tassert(output >= %d): %s",NL,EOS
testMsg_assertUEqual db "\t\tassert(output == %u): %s",NL,EOS
testMsg_assertUNEqual db "\t\tassert(output != %u): %s",NL,EOS
testMsg_assertULess db "\t\tassert(output < %u): %s",NL,EOS
testMsg_assertULessE db "\t\tassert(output <= %u): %s",NL,EOS
testMsg_assertUMore db "\t\tassert(output > %u): %s",NL,EOS
testMsg_assertUMoreE db "\t\tassert(output >= %u): %s",NL,EOS
testMsg_False db "FALSE",EOS
testMsg_True db "true",EOS
testMsg_assertIEqual db "\t\tassert(output == %d):\n\t\t\tExpected:\t%d\n\t\t\tGot:\t\t%d\n\t\t\t%s",NL,EOS
testMsg_assertINEqual db "\t\tassert(output != %d):\n\t\t\tExpected:\t%d\n\t\t\tGot:\t\t%d\n\t\t\t%s",NL,EOS
testMsg_assertILess db "\t\tassert(output < %d):\n\t\t\tExpected:\t%d\n\t\t\tGot:\t\t%d\n\t\t\t%s",NL,EOS
testMsg_assertILessE db "\t\tassert(output <= %d):\n\t\t\tExpected:\t%d\n\t\t\tGot:\t\t%d\n\t\t\t%s",NL,EOS
testMsg_assertIMore db "\t\tassert(output > %d):\n\t\t\tExpected:\t%d\n\t\t\tGot:\t\t%d\n\t\t\t%s",NL,EOS
testMsg_assertIMoreE db "\t\tassert(output >= %d):\n\t\t\tExpected:\t%d\n\t\t\tGot:\t\t%d\n\t\t\t%s",NL,EOS
testMsg_assertUEqual db "\t\tassert(output == %u):\n\t\t\tExpected:\t%d\n\t\t\tGot:\t\t%d\n\t\t\t%s",NL,EOS
testMsg_assertUNEqual db "\t\tassert(output != %u):\n\t\t\tExpected:\t%d\n\t\t\tGot:\t\t%d\n\t\t\t%s",NL,EOS
testMsg_assertULess db "\t\tassert(output < %u):\n\t\t\tExpected:\t%d\n\t\t\tGot:\t\t%d\n\t\t\t%s",NL,EOS
testMsg_assertULessE db "\t\tassert(output <= %u):\n\t\t\tExpected:\t%d\n\t\t\tGot:\t\t%d\n\t\t\t%s",NL,EOS
testMsg_assertUMore db "\t\tassert(output > %u):\n\t\t\tExpected:\t%d\n\t\t\tGot:\t\t%d\n\t\t\t%s",NL,EOS
testMsg_assertUMoreE db "\t\tassert(output >= %u):\n\t\t\tExpected:\t%d\n\t\t\tGot:\t\t%d\n\t\t\t%s",NL,EOS
testMsg_False db "<!> FAIL",EOS
testMsg_True db "< > OK",EOS
testMsg_Results db "\n*** Test Results ***\n* Total tests:\t\t%d\n* Succeeded tests:\t%d\n* Failed tests:\t\t%d\n",EOS
;;;