forked from alex-eg/sex
read the unit tests' sources from a file, the way sexc does
The reader exported parse-all only so the tests could give a source the file name its locations carry; read-from-file gives it one, through the reader's own interface. The pipeline helpers move out of codegen.scm for every suite to use.
This commit is contained in:
@@ -17,14 +17,13 @@
|
||||
;;; get the true source line) and in the C output (to get the line the
|
||||
;;; directives claim). The two must agree.
|
||||
|
||||
(import (chicken port)
|
||||
(import (chicken pathname)
|
||||
(chicken port)
|
||||
(chicken string)
|
||||
srfi-1
|
||||
srfi-13
|
||||
fmt-c-writer
|
||||
reader
|
||||
semen
|
||||
utils)
|
||||
semen)
|
||||
|
||||
;;; ------------------------------------------------------------------
|
||||
;;; Fixture. Line numbers are in the trailing comments; keep them
|
||||
@@ -98,15 +97,9 @@
|
||||
;;; Pipeline and #line accounting
|
||||
|
||||
(define (compile-to-c source)
|
||||
"Run reader -> semen -> writer on SOURCE, returning the generated C.
|
||||
parse-all is called directly rather than through read-raw-forms so the
|
||||
fixture can be given a file name: a location carries one, and the
|
||||
file is what makes an imported module report itself rather than the unit
|
||||
that imported it."
|
||||
(let ((forms (with-input-from-string source
|
||||
(lambda ()
|
||||
(parameterize ((current-source-file "fixture.sex"))
|
||||
(parse-all (current-input-port)))))))
|
||||
"Run reader -> semen -> writer on SOURCE, read from fixture.sex,
|
||||
returning the generated C."
|
||||
(let ((forms (read-source source "fixture.sex")))
|
||||
(with-output-to-string
|
||||
(lambda () (emit-c (semen-process forms))))))
|
||||
|
||||
@@ -247,6 +240,8 @@ after that is one more. Lines before the first directive get #f."
|
||||
;; form was read from.
|
||||
(test-group "file name"
|
||||
(test "every directive names the fixture"
|
||||
(list "\"fixture.sex\"")
|
||||
(list "fixture.sex")
|
||||
(delete-duplicates
|
||||
(filter values (map directive-file (split-lines c-out)))))))
|
||||
(map (lambda (quoted)
|
||||
(pathname-strip-directory (string-trim-both quoted #\")))
|
||||
(filter values (map directive-file (split-lines c-out))))))))
|
||||
|
||||
Reference in New Issue
Block a user