unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Andrew Whatson <whatson@gmail.com>
To: guile-devel@gnu.org
Cc: Andrew Whatson <whatson@gmail.com>
Subject: [PATCH v2] Add tests for warning locations.
Date: Sun, 25 Sep 2022 08:34:27 +1000	[thread overview]
Message-ID: <20220924223426.30825-1-whatson@gmail.com> (raw)
In-Reply-To: <20220924134608.20312-1-whatson@gmail.com>

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




  parent reply	other threads:[~2022-09-24 22:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Andrew Whatson [this message]
2022-10-12 20:40   ` [PATCH v2] " 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220924223426.30825-1-whatson@gmail.com \
    --to=whatson@gmail.com \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).