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,11 +90,11 @@
(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
(fn (fn
@@ -155,53 +152,27 @@
#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 (getopt-long (command-line-arguments) (let ((args (command-line-arguments)))
opts-grammar))) (if (not (= 1 (length args)))
(when (assoc 'help args) (print-help)
(print-help) (let ((settings-and-src
(exit 0)) (process-file (first args))))
(when (null? (cdr (assoc '@ args))) (let ((settings (car settings-and-src))
(fmt #t "Missing target file" nl) (src (cdr settings-and-src)))
(print-help) (let ((compiled-file (compile src (assoc 'compile settings))))
(exit 1)) (unless compiled-file
(unless (fmt #t "Compilation failed." nl)
(foldl and (exit 1))
#t (if (run-and-check
(map (fn (process-test-file (assoc 'sexc args) x)) compiled-file
(cdr (assoc '@ args)))) (assoc 'input settings)
;; TODO: add more verbose and human readable output and reporting (assoc 'output settings)
(fmt #t nl) (assoc 'return settings))
(exit 2)) (fmt #t "PASS" nl)
(fmt #t nl) (begin
(exit 0))) (fmt #t "FAIL" nl)
(exit 2)))
(exit 0)))))))
(main) (main)