-
Notifications
You must be signed in to change notification settings - Fork 9
/
run-tests.scm
48 lines (43 loc) · 1.53 KB
/
run-tests.scm
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
(import
(elegant-weapons print-c)
(elegant-weapons parse-c)
(elegant-weapons tester)
(elegant-weapons helpers-tests)
(elegant-weapons sets-tests)
(elegant-weapons record-case-tests))
(define (print-parse-roundtrip e)
(display "Round trip testing for...\n")
(display e)(newline)(newline)
(let ((s (format-c e)))
(display "Formatted C...\n")
(display s)(newline)(newline)
(let ((tokens (tokenize-string s)))
(display "Tokens...\n")
(display tokens)(newline)(newline)
(let ((parsed (parse-c tokens)))
(display "Parsed...\n")
(display parsed)(newline)(newline)
(if (equal? e parsed)
(display "Success!\n")
(error 'print-parse-roundtrip
"Parser round trip test failed."))))))
(define (parse-roundtrip e error)
(let ((s (format-c e)))
(let ((tokens (tokenize-string s)))
(let ((parsed (parse-c tokens)))
(unless (equal? e parsed)
(error))))))
(define-test-suite
basic
(simple (lambda (error) #t))
(parser-roundtrip-1 (lambda (error)
(parse-roundtrip '((func int main ()
(return (int 0))))
error)))
(parser-roundtrip-2 (lambda (error)
(parse-roundtrip
'((func int main ()
(let x int (int 0))
(return (var x))))
error))))
(run-tests basic helpers sets record-case-tests)