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:
@@ -20,16 +20,24 @@
|
|||||||
%macro assert 3
|
%macro assert 3
|
||||||
inc r13
|
inc r13
|
||||||
mov rsi, %1
|
mov rsi, %1
|
||||||
|
mov rdx, %1
|
||||||
|
mov rcx, rax
|
||||||
cmp rax, %1
|
cmp rax, %1
|
||||||
%2 %%true
|
%2 %%true
|
||||||
lea rdx, [rel testMsg_False]
|
lea r8, [rel testMsg_False]
|
||||||
jmp %%cnt
|
jmp %%cnt
|
||||||
%%true:
|
%%true:
|
||||||
inc r14
|
inc r14
|
||||||
lea rdx, [rel testMsg_True]
|
%if TESTS_PRINT_ALL_OUTPUTS
|
||||||
|
lea r8, [rel testMsg_True]
|
||||||
|
%else
|
||||||
|
jmp %%end
|
||||||
|
%endif
|
||||||
%%cnt:
|
%%cnt:
|
||||||
lea rdi, [rel %3]
|
lea rdi, [rel %3]
|
||||||
call printf
|
call printf
|
||||||
|
%%end:
|
||||||
|
nop
|
||||||
%endmacro
|
%endmacro
|
||||||
|
|
||||||
;core.asm
|
;core.asm
|
||||||
@@ -63,6 +71,8 @@ section .rodata
|
|||||||
;;;
|
;;;
|
||||||
;;; enable/disable tests
|
;;; 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
|
;core.asm
|
||||||
TEST_islower equ 1
|
TEST_islower equ 1
|
||||||
TEST_isupper equ 1
|
TEST_isupper equ 1
|
||||||
@@ -92,20 +102,20 @@ section .rodata
|
|||||||
;;;
|
;;;
|
||||||
;;; Global test messages
|
;;; Global test messages
|
||||||
;;;
|
;;;
|
||||||
testMsg_assertIEqual db "\t\tassert(output == %d): %s",NL,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): %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): %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): %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): %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): %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): %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): %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): %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): %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): %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): %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 "FALSE",EOS
|
testMsg_False db "<!> FAIL",EOS
|
||||||
testMsg_True db "true",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
|
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
|
||||||
|
|
||||||
;;;
|
;;;
|
||||||
|
Reference in New Issue
Block a user