diff --git a/test/test-compilation-error.expected b/test/test-compilation-error.expected new file mode 100644 index 0000000..4bb3e6e --- /dev/null +++ b/test/test-compilation-error.expected @@ -0,0 +1,29 @@ +test-compilation-error.factor + +6: : wont-compile ; + ^ +Expected ( but got ; +(U) Quotation: [ c-to-factor => ] + Word: c-to-factor +(U) Quotation: [ [ (get-catchstack) push ] dip call => (get-catchstack) pop* ] +(O) Word: command-line-startup +(O) Word: run-script +(O) Word: run-file +(O) Word: parse-file +(O) Word: parse-stream +(O) Word: parse-fresh +(O) Word: (parse-lines) +(O) Word: (parse-until) +(O) Word: parse-until-step +(O) Word: execute-parsing +(O) Word: POSTPONE: : +(O) Word: (:) +(O) Word: scan-effect +(O) Word: expect +(O) Word: unexpected +(O) Method: M\ object throw +(U) Quotation: [ + OBJ-CURRENT-THREAD special-object error-thread set-global + current-continuation => error-continuation set-global + [ original-error set-global ] [ rethrow ] bi + ] diff --git a/test/test-compilation-error.factor b/test/test-compilation-error.factor new file mode 100644 index 0000000..7771841 --- /dev/null +++ b/test/test-compilation-error.factor @@ -0,0 +1,17 @@ +! Copyright 2024 nomennescio + +USING: tools.testest kernel math ; +IN: tests + +: wont-compile ; + +: run-tests ( -- ) + +"Compilation error" describe#{ + "Compilation error in user code" it#{ + <{ wont-compile -> }> + }# +}# +; + +MAIN: run-tests \ No newline at end of file diff --git a/test/test-effect-error.expected b/test/test-effect-error.expected new file mode 100644 index 0000000..8758286 --- /dev/null +++ b/test/test-effect-error.expected @@ -0,0 +1,18 @@ + +Compilation error + +Compilation error in user code + +==== test-effect-error.factor + +test-effect-error.factor: 6 + +Asset: wont-infer + +Stack effect declaration is wrong +inferred ( -- x ) +declared ( -- ) + +0.345100 ms + +0.516400 ms diff --git a/test/test-effect-error.factor b/test/test-effect-error.factor new file mode 100644 index 0000000..dbb04dd --- /dev/null +++ b/test/test-effect-error.factor @@ -0,0 +1,17 @@ +! Copyright 2024 nomennescio + +USING: tools.testest kernel math ; +IN: tests + +: wont-infer ( -- ) 0 ; + +: run-tests ( -- ) + +"Compilation error" describe#{ + "Compilation error in user code" it#{ + <{ wont-infer -> }> + }# +}# +; + +MAIN: run-tests \ No newline at end of file diff --git a/tools/testest/testest.factor b/tools/testest/testest.factor index 83fbd1f..45ae295 100644 --- a/tools/testest/testest.factor +++ b/tools/testest/testest.factor @@ -1,8 +1,9 @@ -! Copyright 2019-2022 nomennescio +! Copyright 2019-2024 nomennescio -USING: accessors arrays classes classes.error continuations debugger formatting fry inspector +USING: accessors arrays assocs classes classes.error compiler.errors continuations debugger formatting fry inspector io io.streams.string io.styles kernel locals math namespaces parser prettyprint prettyprint.backend -prettyprint.config prettyprint.custom prettyprint.sections quotations sequences splitting system ; +prettyprint.config prettyprint.custom prettyprint.sections quotations sequences splitting +stack-checker.errors summary system tools.errors ; IN: tools.testest : describe#{ ( description -- starttime ) nl "%s" printf nl flush nano-count ; @@ -39,10 +40,17 @@ ERROR: thrown error ; : unexpected-error? ( got expected -- ? ) [ ?first thrown? ] bi@ not and ; -: (unit-test) ( test-quot expected-quot -- ) - swap [ { } swap catch-all ] bi@ swap 2dup unexpected-error? [ drop first error# (error.) ] - [ '[ _ _ assert-sequence= passed# passed. ] [ failed# failed. ] recover ] if nl -; +SYMBOL: once +: only-once ( ..a quot: ( ..a -- ... ) -- ... ) once get [ 2drop ] [ call once on ] if ; inline + +SYMBOL: no-compiler-errors +: without-compiler-errors ( ..a b quot: ( ..a b -- ... ) -- ... ) + no-compiler-errors compiler-errors get values [ on call ] [ [ off ] dip [ errors. ] only-once 3drop ] if-empty ; inline + +: (unit-test) ( test-quot: ( -- ... ) expected-quot: ( -- ... ) -- ) + [ swap [ { } swap catch-all ] bi@ swap 2dup unexpected-error? [ drop first error# (error.) ] + [ '[ _ _ assert-sequence= passed# passed. ] [ failed# failed. ] recover ] if nl + ] without-compiler-errors ; PRIVATE> @@ -77,7 +85,7 @@ SYMBOL: ERROR:{ ! 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 ; +M: tuple error. dup class-of error-class? no-compiler-errors get and [ pprint-short ] [ describe ] if ; SYMBOL: THROWN: M: thrown pprint* THROWN: pprint-word error>> pprint* ;