diff --git a/test/test-error-handling.expected b/test/test-error-handling.expected index 8a42894..4c7bc09 100644 --- a/test/test-error-handling.expected +++ b/test/test-error-handling.expected @@ -3,26 +3,38 @@ Unexpected system error in user code -ERROR:{ division-by-zero { x 1 } } +Thrown: ERROR:{ division-by-zero { x 1 } } -0.382253 ms +0.274156 ms Unexpected custom error in user code -ERROR:{ custom-error { error-message "thrown custom error" } {... +Thrown: ERROR:{ custom-error { error-message "thrown custom error" } {... -0.110253 ms +0.179815 ms Expected custom error Test Passed -0.089989 ms +0.059046 ms Missing expected custom error -Test Failed : Expected :<:LF:>ERROR:{ custom-error<:LF:> { error-message "thrown custom error" }<:LF:> { integer-argument 1 }<:LF:>}<:LF:>but got :<:LF:>1 +Test Failed : Expected :<:LF:>THROWN: ERROR:{ custom-error<:LF:> { error-message "thrown custom error" }<:LF:> { integer-argument 1 }<:LF:>}<:LF:>but got :<:LF:>1 -0.239820 ms +0.166183 ms -1.043601 ms +Missing expected thrown error + +Test Failed : Expected :<:LF:>THROWN: "thrown error"<:LF:>but got :<:LF:>"thrown error" + +0.028068 ms + +Missing expected thrown custom error + +Test Failed : Expected :<:LF:>THROWN: ERROR:{ custom-error<:LF:> { error-message "thrown custom error" }<:LF:> { integer-argument 1 }<:LF:>}<:LF:>but got :<:LF:>ERROR:{ custom-error<:LF:> { error-message "thrown custom error" }<:LF:> { integer-argument 1 }<:LF:>} + +0.056286 ms + +0.952354 ms diff --git a/test/test-error-handling.factor b/test/test-error-handling.factor index d1a94ae..99bb298 100644 --- a/test/test-error-handling.factor +++ b/test/test-error-handling.factor @@ -1,9 +1,10 @@ ! Copyright 2022 nomennescio -USING: tools.testest math ; +USING: tools.testest kernel math ; IN: tests ERROR: custom-error error-message integer-argument ; +C: custom-error : run-tests ( -- ) @@ -20,6 +21,12 @@ ERROR: custom-error error-message integer-argument ; "Missing expected custom error" it#{ <{ 1 -> "thrown custom error" 1 custom-error }> }# + "Missing expected thrown error" it#{ + <{ "thrown error" -> "thrown error" throw }> + }# + "Missing expected thrown custom error" it#{ + <{ "thrown custom error" 1 -> "thrown custom error" 1 custom-error }> + }# }# ; diff --git a/test/test-stack-underflow.expected b/test/test-stack-underflow.expected index b4ff06a..586e758 100644 --- a/test/test-stack-underflow.expected +++ b/test/test-stack-underflow.expected @@ -3,39 +3,39 @@ single test -Data stack underflow +Thrown: Data stack underflow -0.052173 ms +0.143086 ms double test -Data stack underflow +Thrown: Data stack underflow -Data stack underflow +Thrown: Data stack underflow -0.020681 ms +0.019864 ms double test -Data stack underflow +Thrown: Data stack underflow -Data stack underflow +Thrown: Data stack underflow -0.013233 ms +0.015669 ms double test -Data stack underflow +Thrown: Data stack underflow -Data stack underflow +Thrown: Data stack underflow -0.012404 ms +0.015315 ms -0.314743 ms +0.341698 ms diff --git a/tools/testest/testest.factor b/tools/testest/testest.factor index 36bede4..2fc4d7e 100644 --- a/tools/testest/testest.factor +++ b/tools/testest/testest.factor @@ -23,7 +23,7 @@ SYMBOL: test-failed. " replace ] dip suffix write ; inline +: with-message ( quot -- ) with-string-writer unclip-last [ "\n" "<:LF:>" replace ] dip suffix write ; inline : passed. ( -- ) [ test-passed. get call( -- ) ] with-message ; inline : failed. ( error -- ) [ test-failed. get call( error -- ) ] with-message ; inline @@ -32,10 +32,15 @@ SYMBOL: test-failed. : failed# ( -- ) nl "" write ; : error# ( -- ) nl "" write ; -: catch-all ( stack quot -- stack' throwed? ) '[ _ _ with-datastack f ] [ 1array t ] recover ; inline +ERROR: thrown error ; + +: catch-all ( stack quot -- stack' ) '[ _ _ with-datastack ] [ \ thrown boa 1array ] recover ; inline + +: unexpected-error? ( obj1 obj2 -- ? ) ?first thrown? not swap ?first thrown? and ; : (unit-test) ( test-quot expected-quot -- ) - [ { } swap catch-all ] bi@ not rot and [ drop first error# [ print-error ] with-message nl ] + [ { } swap catch-all ] bi@ 2dup unexpected-error? + [ drop first error# [ print-error ] with-message nl ] [ '[ _ _ assert-sequence= passed# passed. nl ] [ failed# failed. nl ] recover ] if ; @@ -66,12 +71,17 @@ SYMBOL: ERROR:{ : pprint-error ( error-tuple -- ) [ ERROR:{ ] dip [ class-of ] [ tuple>assoc ] bi \ } (pprint-tuple) ; ! print errors differently from tuples + M: tuple pprint* dup class-of error-class? [ pprint-error ] [ pprint-tuple ] if ; M: tuple error. dup class-of error-class? [ pprint-short ] [ describe ] if ; +SYMBOL: THROWN: +M: thrown pprint* \ THROWN: pprint-word error>> pprint* ; +M: thrown error. "Thrown: " write error>> error. ; + M: assert-sequence error. [ "Expected :" write expected>> seq. ] [ nl "but got :" write got>> seq. ] bi ; -PRIVATE> +PRIVATE> \ No newline at end of file