You can use built in functions such as :h assert_true() to test scripts. Every time you call an assert function, a new error message will be added to v:error if it failed, check :h assert-return. Note that assert function returns 1 if test failed, not 0.
assert families
assert_beeps
assert_equal
assert_equalfile
assert_exception
assert_fails
assert_false
assert_inrange
assert_match
assert_notequal
assert_notmatch
assert_report
assert_true
I use two styles of test:
Run all test cases, then report errors one by one:
" clear errors
let v:errors = []
call assert_true(...)
call assert_equal(...)
call assert_match(...)
...
echohl WarningMsg
for err in v:errors
echo err
endfor
echohl None
Run cases one by one, stop immediately if test failed
if(assert_true(...)) | throw v:errors[-1] | endif
if(assert_equal(...)) | throw v:errors[-1] | endif
if(assert_match(...)) | throw v:errors[-1] | endif
systemand toss the response code instead?