test-runner #25

Merged
alex-eg merged 2 commits from test-runner into main 2026-05-22 15:16:21 +02:00
Showing only changes of commit 878d415e22 - Show all commits

View File

@@ -10,6 +10,7 @@
(chicken read-syntax) (chicken read-syntax)
(chicken syntax) (chicken syntax)
fmt fmt
getopt-long
srfi-1) srfi-1)
(define-syntax prog1 (define-syntax prog1
@@ -73,7 +74,9 @@
(read-forms (cons r acc))))) (read-forms (cons r acc)))))
(define (print-help) (define (print-help)
(fmt #t "Usage: sextest ./path/to/test-file.sex\n")) (fmt #t "Usage: sextest [options] filename" nl
"Options:" nl
(usage opts-grammar) nl))
(define (process-file target-path) (define (process-file target-path)
(let ((contents (read-raw-forms target-path))) (let ((contents (read-raw-forms target-path)))
@@ -90,11 +93,11 @@
(cons (list) (list)) (cons (list) (list))
contents))) contents)))
(define (compile src flags) (define (compile src flags sexc)
(let ((compiler (or (get-environment-variable "SEXC") (let ((compiler (or
;; TODO: pass compiler in args (and sexc (cdr sexc))
;; (get-arg args 'sex-compiler #f) (get-environment-variable "SEXC")
"sexc")) "sexc"))
(compiled-file (create-temporary-file))) (compiled-file (create-temporary-file)))
(call-with-values (call-with-values
(fn (fn
@@ -152,27 +155,53 @@
#f) #f)
#t)))))) #t))))))
(define opts-grammar
`((sexc ,(fmt #f "Path to sexc compiler. Defaults to value of SEXC" nl
(pad 26) "environment variable, ot if it's empty, to sexc" nl )
(required #f)
(value #t))
(help "Show this help"
(required #f)
(value #f)
(single-char #\h))))
(define (process-test-file sexc path)
(let* ((settings-and-src (process-file path))
(settings (car settings-and-src))
(src (cdr settings-and-src))
(compiled-file (compile src (assoc 'compile settings) sexc)))
(if (not compiled-file)
(begin (fmt #t "Failed to compile " path nl)
#f)
(if (run-and-check
compiled-file
(assoc 'input settings)
(assoc 'output settings)
(assoc 'return settings))
(begin (fmt #t ".")
#t)
(begin (fmt #t ",")
#f)))))
(define (main) (define (main)
(let ((args (command-line-arguments))) (let ((args (getopt-long (command-line-arguments)
(if (not (= 1 (length args))) opts-grammar)))
(print-help) (when (assoc 'help args)
(let ((settings-and-src (print-help)
(process-file (first args)))) (exit 0))
(let ((settings (car settings-and-src)) (when (null? (cdr (assoc '@ args)))
(src (cdr settings-and-src))) (fmt #t "Missing target file" nl)
(let ((compiled-file (compile src (assoc 'compile settings)))) (print-help)
(unless compiled-file (exit 1))
(fmt #t "Compilation failed." nl) (unless
(exit 1)) (foldl and
(if (run-and-check #t
compiled-file (map (fn (process-test-file (assoc 'sexc args) x))
(assoc 'input settings) (cdr (assoc '@ args))))
(assoc 'output settings) ;; TODO: add more verbose and human readable output and reporting
(assoc 'return settings)) (fmt #t nl)
(fmt #t "PASS" nl) (exit 2))
(begin (fmt #t nl)
(fmt #t "FAIL" nl) (exit 0)))
(exit 2)))
(exit 0)))))))
(main) (main)