unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* [PATCH] Add tests for warning locations.
@ 2022-09-24 13:46 Andrew Whatson
  2022-09-24 21:15 ` Maxime Devos
  2022-09-24 22:34 ` [PATCH v2] " Andrew Whatson
  0 siblings, 2 replies; 7+ messages in thread
From: Andrew Whatson @ 2022-09-24 13:46 UTC (permalink / raw)
  To: guile-devel; +Cc: Andrew Whatson

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

* 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/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 ++
 4 files changed, 41 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/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




^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-11-29 18:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-24 13:46 [PATCH] Add tests for warning locations Andrew Whatson
2022-09-24 21:15 ` Maxime Devos
2022-09-24 22:34 ` [PATCH v2] " Andrew Whatson
2022-10-12 20:40   ` Ludovic Courtès
2022-10-13  3:12     ` [PATCH v3] " Andrew Whatson
2022-10-13  3:18     ` [PATCH v2] " Andrew Whatson
2022-11-29 18:11   ` [PATCH v3] " lloda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).