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 v3] Add tests for warning locations.
Date: Thu, 13 Oct 2022 13:12:08 +1000	[thread overview]
Message-ID: <20221013031207.12583-1-whatson@gmail.com> (raw)
In-Reply-To: <875ygovkqt.fsf@gnu.org>

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

* test-suite/tests/tree-il.test ("warnings")("location")["unused
variable", "unbound variable (spaces)", "unbound variable (tabs)"]: New
tests.
---
 test-suite/tests/tree-il.test | 48 ++++++++++++++++++++++++++++++++++-
 1 file changed, 47 insertions(+), 1 deletion(-)

diff --git a/test-suite/tests/tree-il.test b/test-suite/tests/tree-il.test
index 686eab9d2..b296be336 100644
--- a/test-suite/tests/tree-il.test
+++ b/test-suite/tests/tree-il.test
@@ -1519,7 +1519,53 @@
                              #:to 'cps)))))
          (and (= (length w) 1)
               (number? (string-contains (car w)
-                                        "cannot be meaningfully compared")))))))
+                                        "cannot be meaningfully compared"))))))
+
+   (with-test-prefix "location"
+     (define (call-with-fake-input-file filename contents thunk)
+       (call-with-input-string contents
+         (lambda (port)
+           (set-port-filename! port filename)
+           (thunk port))))
+
+     (pass-if "unused variable"
+       (let ((w (call-with-warnings
+                 (lambda ()
+                   (call-with-fake-input-file
+                    "unused-variable.scm"
+                    "\
+(lambda (x)
+  (let ((y (+ x 2)))
+    x))"
+                    (lambda (port)
+                      (read-and-compile port #:opts %opts-w-unused #:to 'cps)))))))
+         (and (= (length w) 1)
+              (number? (string-contains (car w) "unused variable `y'"))
+              (number? (string-contains (car w) "unused-variable.scm:2:2")))))
+
+     (pass-if "unbound variable (spaces)"
+       (let ((w (call-with-warnings
+                 (lambda ()
+                   (call-with-fake-input-file
+                    "unbound-spaces.scm"
+                    "  (foo)"
+                    (lambda (port)
+                      (read-and-compile port #:opts %opts-w-unbound #:to 'cps)))))))
+         (and (= (length w) 1)
+              (number? (string-contains (car w) "unbound variable `foo'"))
+              (number? (string-contains (car w) "unbound-spaces.scm:1:3")))))
+
+     (pass-if "unbound variable (tabs)"
+       (let ((w (call-with-warnings
+                 (lambda ()
+                   (call-with-fake-input-file
+                    "unbound-tabs.scm"
+                    "\t\t(foo)"
+                    (lambda (port)
+                      (read-and-compile port #:opts %opts-w-unbound #:to 'cps)))))))
+         (and (= (length w) 1)
+              (number? (string-contains (car w) "unbound variable `foo'"))
+              (number? (string-contains (car w) "unbound-tabs.scm:1:17")))))))
 
 ;; Local Variables:
 ;; eval: (put 'pass-if-primitives-resolved 'scheme-indent-function 1)
-- 
2.38.0




  reply	other threads:[~2022-10-13  3:12 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 ` [PATCH v2] " Andrew Whatson
2022-10-12 20:40   ` Ludovic Courtès
2022-10-13  3:12     ` Andrew Whatson [this message]
2022-10-13  3:18     ` 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=20221013031207.12583-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).