-
Notifications
You must be signed in to change notification settings - Fork 14
/
json-test-suite-runner.lisp
65 lines (60 loc) · 2.63 KB
/
json-test-suite-runner.lisp
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
(defpackage #:com.inuoe.json-test-suite-runner
(:use #:cl)
(:import-from #:uiop)
(:export #:main))
(in-package #:com.inuoe.json-test-suite-runner)
(defun test-file (tester file rest-args timeout)
(let ((p (uiop:launch-program (list* tester (uiop:native-namestring file) rest-args) :error-output *error-output*))
(start (get-internal-real-time)))
(loop
(cond
((not (uiop:process-alive-p p))
(return (uiop:wait-process p)))
((>= (- (get-internal-real-time) start) timeout)
(uiop:terminate-process p :urgent t)
(uiop:wait-process p)
(return nil))
(t
(sleep 0.05))))))
(defun test-files (tester test-dir rest-args)
(let ((json-files (uiop:merge-pathnames* (make-pathname :name :wild :type "json") test-dir))
(any-failed nil))
(dolist (file (directory json-files))
(format t "~A.~A ... " (pathname-name file) (pathname-type file))
(finish-output)
(let ((result (test-file tester file rest-args (* 2 internal-time-units-per-second))))
(case (char (pathname-name file) 0)
(#\y
(case result
(0 (format t "OK~%"))
(1 (format t "ERROR - FAILED~%") (setf any-failed t))
((nil) (format t "ERROR - TIMEOUT~%") (setf any-failed t))
(t (format t "ERROR - OTHER (0x~4,'0X)~%" result) (setf any-failed t))))
(#\n
(case result
(0 (format t "ERROR - SUCCEEDED~%") (setf any-failed t))
(1 (format t "OK~%"))
((nil) (format t "ERROR - TIMEOUT~%") (setf any-failed t))
(t (format t "ERROR - OTHER (0x~4,'0X)~%" result) (setf any-failed t))))
(#\i
(case result
(0 (format t "OK~%"))
(1 (format t "FAILED~%"))
((nil) (format t "TIMEOUT~%"))
(t (format t "OTHER (0x~4,'0X)~%" result))))))
(finish-output))
(not any-failed)))
(defun main (&rest argv)
(prog ((tester (second argv))
(test-dir (third argv))
(rest-args (cdddr argv)))
(unless (and tester (ignore-errors (uiop:run-program (list tester "--help"))
t))
(format *error-output* "First argument must be a program to test with.")
(return 2))
(unless (and test-dir (probe-file test-dir))
(format *error-output* "Second argument must be a directory of files to test.")
(return 2))
(return (if (test-files (uiop:parse-native-namestring tester) (uiop:parse-native-namestring test-dir :ensure-directory t) rest-args)
0
1))))