1 Commits

Author SHA1 Message Date
dddc6624a5 add sextest test runner
A tool for testing Sex programs. Details in tools/sextest/README.org
2026-05-15 19:49:48 +03:00
2 changed files with 28 additions and 57 deletions

View File

@@ -1,6 +1,6 @@
(input "Sextest") (input "Sextest")
(output "Hello from Sex!" "What is your name?" "Hello, Sextest!") (output "Hello from Sex!" "What is your name?" "Hello, Sextest!")
(return 255) (return 252)
(include stdio.h) (include stdio.h)

View File

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