]> git.donarmstrong.com Git - lilypond.git/blob - guile18/test-suite/standalone/test-bad-identifiers
Import guile-1.8 as multiple upstream tarball component
[lilypond.git] / guile18 / test-suite / standalone / test-bad-identifiers
1 #!/bin/sh
2 exec guile -q -s "$0" "$@"
3 !#
4
5 ;; The use of certain identifiers as variable or parameter names has
6 ;; been found to cause build problems on particular platforms.  The
7 ;; aim of this test is to cause "make check" to fail (on GNU/Linux,
8 ;; which most Guile developers use) if we accidentally add new code
9 ;; that uses those identifiers.
10
11 (define bad-identifiers
12   '(
13     ;; On AIX 5.2 and 5.3, /usr/include/sys/timer.h includes:
14     ;;   #ifndef  _LINUX_SOURCE_COMPAT
15     ;;   #define func_data       t_union.data
16     ;;   #endif
17     ;; So we want to avoid using func_data in Guile source code.
18     "func_data"
19
20     ;; More troublesome identifiers can be added into the list here.
21     ))
22
23 (use-modules (ice-9 regex) (ice-9 rdelim))
24
25 (define bad-id-regexp
26   (make-regexp (string-append "\\<("
27                               (string-join (map regexp-quote bad-identifiers) "|")
28                               ")\\>")))
29
30 (define exit-status 0)
31
32 ;; Non-exported code from (ice-9 ftw).
33 (define (directory-files dir)
34   (let ((dir-stream (opendir dir)))
35     (let loop ((new (readdir dir-stream))
36                (acc '()))
37       (if (eof-object? new)
38           (begin
39             (closedir dir-stream)
40             acc)
41           (loop (readdir dir-stream)
42                 (if (or (string=? "."  new)             ;;; ignore
43                         (string=? ".." new))            ;;; ignore
44                     acc
45                     (cons (in-vicinity dir new) acc)))))))
46
47 (define (directory-files-matching dir pattern)
48   (let ((file-name-regexp (make-regexp pattern)))
49     (filter (lambda (fn)
50               (regexp-exec file-name-regexp fn))
51             (directory-files dir))))
52
53 (let loop ((file-names (directory-files-matching "../../libguile"
54                                                  "\\.[ch]$")))
55   (or (null? file-names)
56       (begin
57         (with-input-from-file (car file-names)
58           (lambda ()
59             (let loop ((linenum 1) (line (read-line)))
60               (or (eof-object? line)
61                   (begin
62                     (if (regexp-exec bad-id-regexp line)
63                         (begin
64                           (set! exit-status 1)
65                           (format (current-error-port)
66                                   "~a:~a: ~a\n"
67                                   (car file-names)
68                                   linenum
69                                   line)))
70                     (loop (+ linenum 1) (read-line)))))))
71         (loop (cdr file-names)))))
72      
73 (exit exit-status)
74
75 ;; Local Variables:
76 ;; mode: scheme
77 ;; End: