forked from alex-eg/sex
share reading a test source and catching its error
encapsulation.scm had copies of both from codegen.scm.
This commit is contained in:
@@ -15,12 +15,15 @@
|
||||
semen
|
||||
utils)
|
||||
|
||||
(define (read-source source)
|
||||
(with-input-from-string source
|
||||
(lambda ()
|
||||
(parameterize ((current-source-file "codegen.sex"))
|
||||
(parse-all (current-input-port))))))
|
||||
|
||||
(define (sex->c source)
|
||||
"Compile SOURCE, a string of Sex, and return the generated C."
|
||||
(let ((forms (with-input-from-string source
|
||||
(lambda ()
|
||||
(parameterize ((current-source-file "codegen.sex"))
|
||||
(parse-all (current-input-port)))))))
|
||||
(let ((forms (read-source source)))
|
||||
(with-output-to-string
|
||||
(lambda ()
|
||||
(parameterize ((sex-line-directives 'none))
|
||||
@@ -37,17 +40,20 @@
|
||||
(define (emits? source fragment)
|
||||
(and (string-contains (silently (lambda () (sex->c source))) fragment) #t))
|
||||
|
||||
(define (error-message source)
|
||||
"Compile SOURCE and return the error text as the user sees it --
|
||||
message plus arguments, the way CHICKEN prints it -- or #f if SOURCE
|
||||
compiles."
|
||||
(define (failure-message thunk)
|
||||
"The error THUNK raises as the user sees it -- message plus arguments,
|
||||
the way CHICKEN prints it -- or #f if it raises none."
|
||||
(handle-exceptions e
|
||||
(with-output-to-string
|
||||
(lambda ()
|
||||
(display ((condition-property-accessor 'exn 'message) e))
|
||||
(for-each (lambda (a) (display " ") (write a))
|
||||
((condition-property-accessor 'exn 'arguments) e))))
|
||||
(begin (sex->c source) #f)))
|
||||
(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 (reports? source fragment)
|
||||
(let ((m (error-message source)))
|
||||
|
||||
@@ -5,23 +5,18 @@
|
||||
;;; is checked here is what the compiler refuses, and that it refuses
|
||||
;;; it with the name of whatever is wrong.
|
||||
;;;
|
||||
;;; `sex->c', `emits?', `reports?' and `in-fn' come from codegen.scm,
|
||||
;;; which run.scm includes first.
|
||||
;;; `sex->c', `read-source', `failure-message', `emits?', `reports?'
|
||||
;;; and `in-fn' come from codegen.scm, which run.scm includes first.
|
||||
|
||||
(import sex-modules)
|
||||
|
||||
(define (interface-of source)
|
||||
"The declarations SOURCE, compiled as a module, hands its importers
|
||||
ahead of its pub forms."
|
||||
(check-public-interface
|
||||
(with-input-from-string source
|
||||
(lambda ()
|
||||
(parameterize ((current-source-file "codegen.sex"))
|
||||
(parse-all (current-input-port)))))))
|
||||
(check-public-interface (read-source source)))
|
||||
|
||||
(define (interface-reports? source fragment)
|
||||
(let ((m (handle-exceptions e ((condition-property-accessor 'exn 'message) e)
|
||||
(begin (interface-of source) #f))))
|
||||
(let ((m (failure-message (lambda () (interface-of source)))))
|
||||
(and m (string-contains m fragment) #t)))
|
||||
|
||||
(define (ops-src . body)
|
||||
|
||||
Reference in New Issue
Block a user