Skip to content

Commit

Permalink
Merge pull request #45 from nomennescio/master
Browse files Browse the repository at this point in the history
On compiler errors prevent running tests and report errors
  • Loading branch information
nomennescio authored Jan 21, 2024
2 parents c64f35f + b78ae13 commit adb8f2a
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 8 deletions.
29 changes: 29 additions & 0 deletions test/test-compilation-error.expected
Original file line number Diff line number Diff line change
@@ -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
]
17 changes: 17 additions & 0 deletions test/test-compilation-error.factor
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions test/test-effect-error.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

<DESCRIBE::>Compilation error

<IT::>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 ( -- )

<COMPLETEDIN::>0.345100 ms

<COMPLETEDIN::>0.516400 ms
17 changes: 17 additions & 0 deletions test/test-effect-error.factor
Original file line number Diff line number Diff line change
@@ -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
24 changes: 16 additions & 8 deletions tools/testest/testest.factor
Original file line number Diff line number Diff line change
@@ -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 "<DESCRIBE::>%s" printf nl flush nano-count ;
Expand Down Expand Up @@ -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>

Expand Down Expand Up @@ -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* ;
Expand Down

0 comments on commit adb8f2a

Please sign in to comment.