From 05abc3a817fe784d80e68e487581a49fd9e16889 Mon Sep 17 00:00:00 2001 From: nomennescio Date: Sun, 17 Jul 2022 22:38:56 +0200 Subject: [PATCH 01/11] ERROR: thrown, wrapper around thrown errors --- tools/testest/testest.factor | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/testest/testest.factor b/tools/testest/testest.factor index 36bede4..4ee5532 100644 --- a/tools/testest/testest.factor +++ b/tools/testest/testest.factor @@ -32,6 +32,8 @@ SYMBOL: test-failed. : failed# ( -- ) nl "" write ; : error# ( -- ) nl "" write ; +ERROR: thrown error ; + : catch-all ( stack quot -- stack' throwed? ) '[ _ _ with-datastack f ] [ 1array t ] recover ; inline : (unit-test) ( test-quot expected-quot -- ) @@ -69,6 +71,10 @@ SYMBOL: ERROR:{ 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-error ; +M: thrown error. "Thrown " write error>> error. ; + M: assert-sequence error. [ "Expected :" write expected>> seq. ] [ nl "but got :" write got>> seq. ] bi From fd684b9fa47453aa42b5bf39cf36794087df2ff7 Mon Sep 17 00:00:00 2001 From: nomennescio Date: Sun, 17 Jul 2022 22:39:31 +0200 Subject: [PATCH 02/11] Reformatting --- tools/testest/testest.factor | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/testest/testest.factor b/tools/testest/testest.factor index 4ee5532..91f6cf2 100644 --- a/tools/testest/testest.factor +++ b/tools/testest/testest.factor @@ -68,6 +68,7 @@ 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 ; @@ -80,4 +81,4 @@ M: assert-sequence error. [ nl "but got :" write got>> seq. ] bi ; -PRIVATE> +PRIVATE> \ No newline at end of file From 649b1633940a0e5b61cce2632c287ad49563cbc7 Mon Sep 17 00:00:00 2001 From: nomennescio Date: Sun, 17 Jul 2022 22:40:21 +0200 Subject: [PATCH 03/11] Fix stack effect --- tools/testest/testest.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testest/testest.factor b/tools/testest/testest.factor index 91f6cf2..e72628f 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 From 6fd6b221e8e9be60f75b8e165ad37d9f38723390 Mon Sep 17 00:00:00 2001 From: nomennescio Date: Sun, 17 Jul 2022 22:41:11 +0200 Subject: [PATCH 04/11] Check for unexpected error --- tools/testest/testest.factor | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testest/testest.factor b/tools/testest/testest.factor index e72628f..1db3b00 100644 --- a/tools/testest/testest.factor +++ b/tools/testest/testest.factor @@ -36,6 +36,8 @@ ERROR: thrown error ; : catch-all ( stack quot -- stack' throwed? ) '[ _ _ with-datastack f ] [ 1array t ] 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 ] [ '[ _ _ assert-sequence= passed# passed. nl ] [ failed# failed. nl ] recover ] if From b6b68584803e5116c8722df374e135636b60d5f2 Mon Sep 17 00:00:00 2001 From: nomennescio Date: Sun, 17 Jul 2022 22:42:37 +0200 Subject: [PATCH 05/11] Wrap thrown errors, check for unexpected errors --- tools/testest/testest.factor | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/testest/testest.factor b/tools/testest/testest.factor index 1db3b00..e9a2e2e 100644 --- a/tools/testest/testest.factor +++ b/tools/testest/testest.factor @@ -34,12 +34,13 @@ SYMBOL: test-failed. ERROR: thrown error ; -: catch-all ( stack quot -- stack' throwed? ) '[ _ _ with-datastack f ] [ 1array t ] recover ; inline +: 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 ; From a293d77291a79aa8691dd5fff0525e21146c0e6d Mon Sep 17 00:00:00 2001 From: nomennescio Date: Sun, 17 Jul 2022 22:46:15 +0200 Subject: [PATCH 06/11] Add test to check if error was actually thrown --- test/test-error-handling.expected | 22 ++++++++++++++-------- test/test-error-handling.factor | 6 +++++- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/test/test-error-handling.expected b/test/test-error-handling.expected index 8a42894..3e578b9 100644 --- a/test/test-error-handling.expected +++ b/test/test-error-handling.expected @@ -3,26 +3,32 @@ Unexpected system error in user code -ERROR:{ division-by-zero { x 1 } } +Thrown ERROR:{ division-by-zero { x 1 } } -0.382253 ms +0.219500 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.151855 ms Expected custom error Test Passed -0.089989 ms +0.079046 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.281750 ms -1.043601 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.063074 ms + +0.959255 ms diff --git a/test/test-error-handling.factor b/test/test-error-handling.factor index d1a94ae..baf0699 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,9 @@ ERROR: custom-error error-message integer-argument ; "Missing expected custom error" it#{ <{ 1 -> "thrown custom error" 1 custom-error }> }# + "Missing expected thrown custom error" it#{ + <{ "thrown custom error" 1 -> "thrown custom error" 1 custom-error }> + }# }# ; From d9c34f0c92b1c4738e5baae70dd69582032a030a Mon Sep 17 00:00:00 2001 From: nomennescio Date: Sun, 17 Jul 2022 22:52:44 +0200 Subject: [PATCH 07/11] Reformat prettyprint output --- tools/testest/testest.factor | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/testest/testest.factor b/tools/testest/testest.factor index e9a2e2e..db6eef4 100644 --- a/tools/testest/testest.factor +++ b/tools/testest/testest.factor @@ -75,9 +75,9 @@ SYMBOL: ERROR:{ 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-error ; -M: thrown error. "Thrown " write error>> error. ; +SYMBOL: THROWN: +M: thrown pprint* \ THROWN: pprint-word error>> pprint-error ; +M: thrown error. "Thrown: " write error>> error. ; M: assert-sequence error. [ "Expected :" write expected>> seq. ] From df71123850c63d78b3e141015a2cb793c87dd987 Mon Sep 17 00:00:00 2001 From: nomennescio Date: Sun, 17 Jul 2022 22:52:58 +0200 Subject: [PATCH 08/11] Fix tests --- test/test-error-handling.expected | 20 ++++++++++---------- test/test-stack-underflow.expected | 24 ++++++++++++------------ 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/test/test-error-handling.expected b/test/test-error-handling.expected index 3e578b9..fe165b4 100644 --- a/test/test-error-handling.expected +++ b/test/test-error-handling.expected @@ -3,32 +3,32 @@ Unexpected system error in user code -Thrown ERROR:{ division-by-zero { x 1 } } +Thrown: ERROR:{ division-by-zero { x 1 } } -0.219500 ms +0.234216 ms Unexpected custom error in user code -Thrown ERROR:{ custom-error { error-message "thrown custom error" } {... +Thrown: ERROR:{ custom-error { error-message "thrown custom error" } {... -0.151855 ms +0.135980 ms Expected custom error Test Passed -0.079046 ms +0.066256 ms Missing expected 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:>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.281750 ms +0.167460 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:>} +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.063074 ms +0.061402 ms -0.959255 ms +0.819462 ms 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 From 4529479f2cdc14f1a4a3240bdebe9b073b0ad955 Mon Sep 17 00:00:00 2001 From: nomennescio Date: Sun, 17 Jul 2022 23:04:34 +0200 Subject: [PATCH 09/11] Harden against empty results --- tools/testest/testest.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testest/testest.factor b/tools/testest/testest.factor index db6eef4..0bd5309 100644 --- a/tools/testest/testest.factor +++ b/tools/testest/testest.factor @@ -36,7 +36,7 @@ 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 ; +: unexpected-error? ( obj1 obj2 -- ? ) ?first thrown? not swap ?first thrown? and ; : (unit-test) ( test-quot expected-quot -- ) [ { } swap catch-all ] bi@ 2dup unexpected-error? From c0d2ffb2345de3685ab6404f8c69641fb24d58d3 Mon Sep 17 00:00:00 2001 From: nomennescio Date: Sun, 17 Jul 2022 23:24:10 +0200 Subject: [PATCH 10/11] Prettyprint any thrown error --- tools/testest/testest.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testest/testest.factor b/tools/testest/testest.factor index 0bd5309..2fc4d7e 100644 --- a/tools/testest/testest.factor +++ b/tools/testest/testest.factor @@ -76,7 +76,7 @@ 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-error ; +M: thrown pprint* \ THROWN: pprint-word error>> pprint* ; M: thrown error. "Thrown: " write error>> error. ; M: assert-sequence error. From e50edf61686ac03245a42b07d2a1e0badcd6a876 Mon Sep 17 00:00:00 2001 From: nomennescio Date: Sun, 17 Jul 2022 23:30:12 +0200 Subject: [PATCH 11/11] Add test for non-`ERROR:` --- test/test-error-handling.expected | 18 ++++++++++++------ test/test-error-handling.factor | 3 +++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/test/test-error-handling.expected b/test/test-error-handling.expected index fe165b4..4c7bc09 100644 --- a/test/test-error-handling.expected +++ b/test/test-error-handling.expected @@ -5,30 +5,36 @@ Thrown: ERROR:{ division-by-zero { x 1 } } -0.234216 ms +0.274156 ms Unexpected custom error in user code Thrown: ERROR:{ custom-error { error-message "thrown custom error" } {... -0.135980 ms +0.179815 ms Expected custom error Test Passed -0.066256 ms +0.059046 ms Missing expected 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:>1 -0.167460 ms +0.166183 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.061402 ms +0.056286 ms -0.819462 ms +0.952354 ms diff --git a/test/test-error-handling.factor b/test/test-error-handling.factor index baf0699..99bb298 100644 --- a/test/test-error-handling.factor +++ b/test/test-error-handling.factor @@ -21,6 +21,9 @@ C: custom-error "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 }> }#