forked from alex-eg/sex
tidy what the fixes wrote around existing helpers
written-type? matches the shapes instead of measuring them, array-form? and pub-form? replace their spelled-out copies, both test files share one fails-with?, and moved test comments are back above their groups.
This commit is contained in:
@@ -51,13 +51,12 @@ the way CHICKEN prints it -- or #f if it raises none."
|
||||
((condition-property-accessor 'exn 'arguments) e))))
|
||||
(begin (thunk) #f)))
|
||||
|
||||
(define (error-message source)
|
||||
"Compile SOURCE and return its error text, or #f if it compiles."
|
||||
(failure-message (lambda () (sex->c source))))
|
||||
(define (fails-with? thunk fragment)
|
||||
(let ((m (failure-message thunk)))
|
||||
(and m (string-contains m fragment) #t)))
|
||||
|
||||
(define (reports? source fragment)
|
||||
(let ((m (error-message source)))
|
||||
(and m (string-contains m fragment) #t)))
|
||||
(fails-with? (lambda () (sex->c source)) fragment))
|
||||
|
||||
(define (followed-by? source first then)
|
||||
"Is FIRST in the C compiled from SOURCE, and the next thing past it,
|
||||
@@ -90,9 +89,6 @@ whitespace aside, THEN?"
|
||||
|
||||
(test-group "codegen"
|
||||
|
||||
;; c-switch handed its scrutinee straight to `cat', which only works
|
||||
;; when it is an atom. Anything else was displayed as a raw
|
||||
;; s-expression: `switch ((%. e type))'.
|
||||
;; A case body shared the switch's scope, so two cases could not
|
||||
;; declare one name, and a label could not be followed by a
|
||||
;; declaration before C23. Only a body that declares needs a block
|
||||
@@ -109,6 +105,9 @@ whitespace aside, THEN?"
|
||||
(not (followed-by? (in-fn "(switch a (case 1 (do (var x int 1) (g x))))")
|
||||
"{" "{"))))
|
||||
|
||||
;; c-switch handed its scrutinee straight to `cat', which only works
|
||||
;; when it is an atom. Anything else was displayed as a raw
|
||||
;; s-expression: `switch ((%. e type))'.
|
||||
(test-group "switch scrutinee"
|
||||
(test-assert "member access"
|
||||
(emits? "(struct s ((type int))) (fn f ((e (struct s))) void (switch (. e type) (case 1 (g))))"
|
||||
@@ -336,8 +335,6 @@ whitespace aside, THEN?"
|
||||
(test-assert "pub with nothing to define"
|
||||
(reports? "(pub 1)" "codegen.sex:1:")))
|
||||
|
||||
;; A nested pointer chain used to silently lose a level:
|
||||
;; (var p (* (* char))) emitted `char *p'
|
||||
;; A grouped header, C's parens carried over, died in the writer with
|
||||
;; `(caddr) bad argument type' and no location
|
||||
(test-group "malformed for"
|
||||
@@ -357,6 +354,8 @@ whitespace aside, THEN?"
|
||||
(reports? "(fn f () void\n (for ((var i int 0) (< i 4) (++ i)) (g i)))"
|
||||
"codegen.sex:2:")))
|
||||
|
||||
;; A nested pointer chain used to silently lose a level:
|
||||
;; (var p (* (* char))) emitted `char *p'
|
||||
(test-group "malformed types are rejected"
|
||||
(test-assert "nested pointer chain"
|
||||
(reports? (in-fn "(var p (* (* char)))") "pointer chains are written flat"))
|
||||
@@ -784,7 +783,7 @@ whitespace aside, THEN?"
|
||||
(test-assert "but a qualifier alone still waits for the type"
|
||||
(emits? "(typedef mytype int) (struct s ((a [const mytype])))" "const mytype a[]")))
|
||||
|
||||
;; `sizeof' takes a type or an expression, and `(* x)' is either.
|
||||
;; `sizeof' takes a type or an expression, and `(* x)' is either.
|
||||
;; What is in scope says which: a name C alone knows is a type
|
||||
(test-group "sizeof"
|
||||
(test-assert "a pointer type"
|
||||
|
||||
Reference in New Issue
Block a user