-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.rkt
131 lines (119 loc) · 4.5 KB
/
tests.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#lang racket
;; Testing apparatus for assignment 5
(require "desugar.rkt")
(require "cps.rkt")
(require "utils.rkt")
(require "top-level.rkt")
(require "closure-convert.rkt")
(define ((make-test path) exp ext)
(lambda ()
(test-full top-level desugar simplify-ir assignment-convert alphatize anf-convert cps-convert closure-convert proc->llvm exp)))
(define (tests-list dir)
(map
(lambda (path)
(string->path
(string-append "tests/" dir "/"
(path->string path))))
(filter (lambda (path)
(define p (path->string path))
(member (last (string-split p ".")) '("scm")))
(directory-list (string-append "tests/" dir "/")))))
(define ((path->test type) p)
(define filename (last (string-split (path->string p) "/")))
`(,(string-append (last (string-split (string-join (drop-right (string-split (path->string p) ".") 1) ".") "/")))
,type
,((make-test p)
(with-input-from-file p read-begin #:mode 'text)
(last (string-split (path->string p) ".")))))
(define tests
`(,@(map (path->test 'public) (tests-list "public"))
,@(map (path->test 'release) (tests-list "release"))
,@(map (path->test 'secret) (tests-list "secret"))))
(define (run-test/internal is-repl . args)
;; Run all tests, a specific test, or print the available tests
(match args
[(list "all")
(define correct-count
(foldl (lambda (testcase count)
(match testcase
[(list test-name _ exec)
(define exec-result
(with-handlers ([exn:fail? identity])
(exec)))
(if (eq? exec-result #t)
(begin
;; (display "Test ")
;; (display test-name)
;; (display " passed.")
;; (newline)
(+ count 1))
(begin
(display "Test ")
(display test-name)
(display " failed!")
(newline)
count))]))
0
tests))
(display "Score on available tests (may not include release tests or private tests): ")
(display (/ (round (/ (* 10000 correct-count) (length tests))) 100.0))
(display "%")
(newline)]
[(list "mk-test-props")
(define groupped-tests
;; key: group (symbol)
;; value: reversed list of testcases
(foldl
(lambda (testcase h)
(match testcase
[(list _ grp _)
(define cur-group
(hash-ref h grp '()))
(hash-set h grp (cons testcase cur-group))]))
(hash)
tests))
(for-each
displayln
'("build.language=c"
"build.make.file=Makefile"
"test.exec=timeout -s KILL 55s /usr/local/bin/racket ./tests.rkt &"))
(for-each
(lambda (kv)
(match kv
[(cons grp ts)
(define testnames
(reverse (map car ts)))
(printf
"test.cases.~a=~a~n"
grp
(string-join
testnames
","))]))
(hash->list
groupped-tests))]
[(list test-name)
#:when (assoc test-name tests)
(match (assoc test-name tests)
[(list _ _ exec)
(define exec-result
(with-handlers ([exn:fail? identity])
(exec)))
(define passed (eq? exec-result #t))
(displayln (if passed "Test passed!" "Test failed!"))
(unless is-repl
(exit (if (eq? exec-result #t) 0 1)))])]
[else
(display "Available tests: ")
(newline)
(display
(string-join
(map car tests)
", "))
(newline)]))
(define run-test
(curry run-test/internal #t))
(apply
run-test/internal
(cons
#f
(vector->list (current-command-line-arguments))))