guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2] Add tests for warning locations.


From: Andrew Whatson
Subject: [PATCH v2] Add tests for warning locations.
Date: Sun, 25 Sep 2022 08:34:27 +1000

These would have caught <https://bugs.gnu.org/56493>.

* test-suite/Makefile.am (SCM_TESTS): Add sample code files.
* test-suite/tests/tree-il.test ("warnings"): New tests.
* test-suite/tests/tree-il/unbound-spaces.scm:
* test-suite/tests/tree-il/unbound-tabs.scm:
* test-suite/tests/tree-il/unused-variable.scm: Sample code for
compilation warning tests.
---
 test-suite/Makefile.am                       |  3 ++
 test-suite/tests/tree-il.test                | 37 +++++++++++++++++++-
 test-suite/tests/tree-il/unbound-spaces.scm  |  1 +
 test-suite/tests/tree-il/unbound-tabs.scm    |  1 +
 test-suite/tests/tree-il/unused-variable.scm |  3 ++
 5 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 test-suite/tests/tree-il/unbound-spaces.scm
 create mode 100644 test-suite/tests/tree-il/unbound-tabs.scm
 create mode 100644 test-suite/tests/tree-il/unused-variable.scm

diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am
index 16fa2e952..35f264195 100644
--- a/test-suite/Makefile.am
+++ b/test-suite/Makefile.am
@@ -187,6 +187,9 @@ SCM_TESTS = tests/00-initial-env.test               \
            tests/threads.test                  \
            tests/time.test                     \
            tests/tree-il.test                  \
+           tests/tree-il/unbound-spaces.scm    \
+           tests/tree-il/unbound-tabs.scm      \
+           tests/tree-il/unused-variable.scm   \
            tests/types.test                    \
            tests/unicode.test                  \
            tests/version.test                  \
diff --git a/test-suite/tests/tree-il.test b/test-suite/tests/tree-il.test
index 686eab9d2..1f66ecccf 100644
--- a/test-suite/tests/tree-il.test
+++ b/test-suite/tests/tree-il.test
@@ -1519,7 +1519,42 @@
                              #:to 'cps)))))
          (and (= (length w) 1)
               (number? (string-contains (car w)
-                                        "cannot be meaningfully 
compared")))))))
+                                        "cannot be meaningfully compared"))))))
+
+   (with-test-prefix "location"
+     (define (test-file filename)
+       (string-append
+        (dirname (current-filename)) "/" filename))
+
+     (pass-if "unused variable"
+       (let ((w (call-with-warnings
+                 (lambda ()
+                   (compile-file (test-file "tree-il/unused-variable.scm")
+                                 #:opts %opts-w-unused
+                                 #:to 'cps)))))
+         (and (= (length w) 1)
+              (number? (string-contains (car w) "unused variable `y'"))
+              (number? (string-contains (car w) 
"tree-il/unused-variable.scm:2:2")))))
+
+     (pass-if "unbound variable (spaces)"
+       (let ((w (call-with-warnings
+                 (lambda ()
+                   (compile-file (test-file "tree-il/unbound-spaces.scm")
+                                 #:opts %opts-w-unbound
+                                 #:to 'cps)))))
+         (and (= (length w) 1)
+              (number? (string-contains (car w) "unbound variable `foo'"))
+              (number? (string-contains (car w) 
"tree-il/unbound-spaces.scm:1:3")))))
+
+     (pass-if "unbound variable (tabs)"
+       (let ((w (call-with-warnings
+                 (lambda ()
+                   (compile-file (test-file "tree-il/unbound-tabs.scm")
+                                 #:opts %opts-w-unbound
+                                 #:to 'cps)))))
+         (and (= (length w) 1)
+              (number? (string-contains (car w) "unbound variable `foo'"))
+              (number? (string-contains (car w) 
"tree-il/unbound-tabs.scm:1:17")))))))
 
 ;; Local Variables:
 ;; eval: (put 'pass-if-primitives-resolved 'scheme-indent-function 1)
diff --git a/test-suite/tests/tree-il/unbound-spaces.scm 
b/test-suite/tests/tree-il/unbound-spaces.scm
new file mode 100644
index 000000000..9de3b9861
--- /dev/null
+++ b/test-suite/tests/tree-il/unbound-spaces.scm
@@ -0,0 +1 @@
+  (foo)
diff --git a/test-suite/tests/tree-il/unbound-tabs.scm 
b/test-suite/tests/tree-il/unbound-tabs.scm
new file mode 100644
index 000000000..b8c7ae23d
--- /dev/null
+++ b/test-suite/tests/tree-il/unbound-tabs.scm
@@ -0,0 +1 @@
+               (foo)
diff --git a/test-suite/tests/tree-il/unused-variable.scm 
b/test-suite/tests/tree-il/unused-variable.scm
new file mode 100644
index 000000000..73dcd3585
--- /dev/null
+++ b/test-suite/tests/tree-il/unused-variable.scm
@@ -0,0 +1,3 @@
+(lambda (x)
+  (let ((y (+ x 2)))
+    x))
-- 
2.37.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]