2017-08-21 15:45:23 +05:30
|
|
|
#! /usr/bin/scheme-script
|
|
|
|
|
2017-08-21 15:23:23 +05:30
|
|
|
(import (rnrs)
|
2017-09-07 20:10:25 +05:30
|
|
|
(only (chezscheme) load-shared-object)
|
2017-08-21 15:23:23 +05:30
|
|
|
(fmt fmt)
|
2017-08-22 14:18:20 +05:30
|
|
|
(list-utils)
|
2017-08-15 20:37:45 +05:30
|
|
|
(functional-tests)
|
2017-09-07 20:10:25 +05:30
|
|
|
(bcache bcache-tests)
|
2017-08-17 20:54:10 +05:30
|
|
|
(cache-functional-tests)
|
2017-08-30 18:59:36 +05:30
|
|
|
(era-functional-tests)
|
2017-08-22 14:18:20 +05:30
|
|
|
(parser-combinators)
|
2017-08-21 15:23:23 +05:30
|
|
|
(only (srfi s1 lists) break)
|
2017-08-23 14:34:00 +05:30
|
|
|
(regex)
|
2017-08-21 15:23:23 +05:30
|
|
|
(srfi s8 receive)
|
2017-08-24 18:33:07 +05:30
|
|
|
(temp-file)
|
2017-08-15 20:37:45 +05:30
|
|
|
(thin-functional-tests))
|
|
|
|
|
2017-08-21 15:23:23 +05:30
|
|
|
;;------------------------------------------------
|
|
|
|
|
2017-08-23 14:48:09 +05:30
|
|
|
;; Returns #t if the xs list matches prefix
|
2017-08-21 15:23:23 +05:30
|
|
|
(define (begins-with prefix xs)
|
|
|
|
(cond
|
|
|
|
((null? prefix) #t)
|
|
|
|
((null? xs) #f)
|
|
|
|
((eq? (car prefix) (car xs))
|
|
|
|
(begins-with (cdr prefix) (cdr xs)))
|
|
|
|
(else #f)))
|
|
|
|
|
|
|
|
(define (split-list xs sep)
|
|
|
|
(define (safe-cdr xs)
|
|
|
|
(if (null? xs) '() (cdr xs)))
|
|
|
|
|
|
|
|
(if (null? xs)
|
|
|
|
'()
|
|
|
|
(receive (p r) (break (lambda (c)
|
|
|
|
(eq? c sep))
|
|
|
|
xs)
|
|
|
|
(cons p (split-list (safe-cdr r) sep)))))
|
|
|
|
|
|
|
|
(define (string->syms str sep)
|
|
|
|
(map (lambda (cs)
|
|
|
|
(string->symbol
|
|
|
|
(list->string cs)))
|
|
|
|
(split-list (string->list str) sep)))
|
|
|
|
|
2017-08-23 14:34:00 +05:30
|
|
|
(define (mk-string-matcher pattern)
|
2017-08-21 15:23:23 +05:30
|
|
|
(let ((prefix (string->syms pattern #\/)))
|
|
|
|
(lambda (keys)
|
|
|
|
(begins-with prefix keys))))
|
|
|
|
|
2017-08-23 14:34:00 +05:30
|
|
|
(define (mk-regex-matcher pattern)
|
|
|
|
(let ((rx (regex pattern)))
|
|
|
|
(lambda (keys)
|
|
|
|
(rx (apply string-append
|
|
|
|
(intersperse "/"
|
|
|
|
(map symbol->string keys)))))))
|
|
|
|
|
|
|
|
;; If the filter begins with 're:' then we make a regex matcher, otherwise
|
|
|
|
;; we use a simple string matcher.
|
|
|
|
(define (mk-single-matcher pattern)
|
|
|
|
(if (string=? (substring pattern 0 3) "re:")
|
|
|
|
(mk-regex-matcher (substring pattern 3 (string-length pattern)))
|
|
|
|
(mk-string-matcher pattern)))
|
|
|
|
|
2017-08-21 16:03:44 +05:30
|
|
|
(define (mk-filter patterns)
|
|
|
|
(if (null? patterns)
|
|
|
|
; accept everything if no patterns
|
|
|
|
(lambda (_) #t)
|
|
|
|
|
|
|
|
; Otherwise accept tests that pass a pattern
|
2017-08-23 14:34:00 +05:30
|
|
|
(let ((filters (map mk-single-matcher patterns)))
|
2017-08-21 16:03:44 +05:30
|
|
|
(fold-left (lambda (fn-a fn-b)
|
|
|
|
(lambda (keys)
|
|
|
|
(or (fn-a keys)
|
|
|
|
(fn-b keys))))
|
|
|
|
(car filters)
|
|
|
|
(cdr filters)))))
|
|
|
|
|
2017-08-22 14:18:20 +05:30
|
|
|
(define (exec-help)
|
|
|
|
(fmt (current-error-port)
|
2017-08-31 14:07:21 +05:30
|
|
|
"Usage:" nl
|
|
|
|
" run-tests help" nl
|
|
|
|
" run-tests list <pattern>*" nl
|
|
|
|
" run-tests run [--disable-unlink] <pattern>*" nl nl
|
|
|
|
(justify
|
|
|
|
(string-append
|
|
|
|
"Patterns are used to select tests. There are two forms a pattern can take; "
|
|
|
|
"either a literal such as 'cache-check/bad-option', or a regular expression (prefix with 're:')."))
|
|
|
|
nl
|
|
|
|
"eg," nl
|
|
|
|
" run-tests run cache-check/bad-option" nl
|
|
|
|
" run-tests run re:help" nl
|
|
|
|
" run-tests run cache-check thin-check re:.*missing.*file" nl
|
|
|
|
))
|
2017-08-22 14:18:20 +05:30
|
|
|
|
|
|
|
(define (exec-run args)
|
|
|
|
(let ((pred (mk-filter args)))
|
|
|
|
(if (run-scenarios (filter pred (list-scenarios)))
|
|
|
|
(exit)
|
|
|
|
(exit #f))))
|
|
|
|
|
2017-08-29 14:58:56 +05:30
|
|
|
(define (exec-list args)
|
|
|
|
(let ((pred (mk-filter args)))
|
|
|
|
(describe-scenarios (filter pred (list-scenarios)))))
|
|
|
|
|
2017-08-22 14:18:20 +05:30
|
|
|
;;------------------------------------------------
|
|
|
|
;; Command line parser
|
|
|
|
|
|
|
|
(define whitespace
|
|
|
|
(many+ (charset " \t\n")))
|
|
|
|
|
|
|
|
(define (whitespace-delim ma)
|
|
|
|
(>> (opt whitespace)
|
|
|
|
(<* ma (opt whitespace))))
|
|
|
|
|
2017-08-29 14:58:56 +05:30
|
|
|
(define (cmd-word str)
|
|
|
|
(whitespace-delim (lit str)))
|
|
|
|
|
2017-08-24 18:33:07 +05:30
|
|
|
(define (switch str)
|
|
|
|
(whitespace-delim (>> (lit "--") (lit str))))
|
|
|
|
|
2017-08-22 14:18:20 +05:30
|
|
|
(define not-switch
|
2017-08-24 18:33:07 +05:30
|
|
|
(whitespace-delim
|
|
|
|
(parse-m (<- c (neg-charset "- \t"))
|
|
|
|
(<- cs (many* (neg-charset " \t")))
|
|
|
|
(pure (list->string (cons c cs))))))
|
|
|
|
|
|
|
|
(define (maybe ma)
|
|
|
|
(alt (>> ma (pure #t))
|
|
|
|
(pure #f)))
|
|
|
|
|
|
|
|
(define help-command-line
|
2017-08-29 14:58:56 +05:30
|
|
|
(>> (cmd-word "help") (pure exec-help)))
|
2017-08-24 18:33:07 +05:30
|
|
|
|
|
|
|
(define run-command-line
|
|
|
|
(parse-m
|
2017-08-29 14:58:56 +05:30
|
|
|
(cmd-word "run")
|
2017-08-24 18:33:07 +05:30
|
|
|
(<- dunlink (maybe (switch "disable-unlink")))
|
|
|
|
(<- args (many* not-switch))
|
|
|
|
(pure (lambda ()
|
|
|
|
(if dunlink
|
|
|
|
(disable-unlink (exec-run args))
|
|
|
|
(exec-run args))))))
|
2017-08-22 14:18:20 +05:30
|
|
|
|
2017-08-29 14:58:56 +05:30
|
|
|
(define list-command-line
|
|
|
|
(parse-m
|
|
|
|
(cmd-word "list")
|
|
|
|
(<- args (many* not-switch))
|
|
|
|
(pure (lambda () (exec-list args)))))
|
|
|
|
|
2017-08-22 14:18:20 +05:30
|
|
|
(define command-line-parser
|
2017-08-29 14:58:56 +05:30
|
|
|
(one-of help-command-line
|
|
|
|
run-command-line
|
|
|
|
list-command-line))
|
2017-08-22 14:18:20 +05:30
|
|
|
|
|
|
|
(define (bad-command-line)
|
2017-08-31 16:52:42 +05:30
|
|
|
(fmt (current-error-port) (dsp "bad command line\n"))
|
|
|
|
(exec-help)
|
|
|
|
(exit 1))
|
2017-08-22 14:18:20 +05:30
|
|
|
|
|
|
|
;; (<string>) -> thunk
|
|
|
|
(define (parse-command-line)
|
|
|
|
(let ((args (cdr (command-line))))
|
|
|
|
(receive (v st)
|
|
|
|
(parse command-line-parser
|
|
|
|
(apply string-append
|
2017-08-24 18:33:07 +05:30
|
|
|
(intersperse " " (cdr (command-line)))))
|
2017-08-22 14:18:20 +05:30
|
|
|
(if (success? st)
|
|
|
|
v
|
|
|
|
bad-command-line))))
|
|
|
|
|
2017-08-21 15:23:23 +05:30
|
|
|
;;------------------------------------------------
|
|
|
|
|
2017-08-15 20:37:45 +05:30
|
|
|
(register-thin-tests)
|
2017-08-17 20:54:10 +05:30
|
|
|
(register-cache-tests)
|
2017-08-30 18:59:36 +05:30
|
|
|
(register-era-tests)
|
2017-09-07 20:10:25 +05:30
|
|
|
(register-bcache-tests)
|
2017-08-30 18:59:36 +05:30
|
|
|
|
2017-08-24 18:33:07 +05:30
|
|
|
(with-dir "test-output"
|
|
|
|
((parse-command-line)))
|
2017-08-15 20:37:45 +05:30
|
|
|
|