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
[-- Attachment #1.1.1: Type: text/plain, Size: 1138 bytes --] On 24-09-2022 15:46, Andrew Whatson wrote: > 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 I would expect they need to be registered in some Makefile.am (as dist_noinst_... or was it noinst_dinst?) such that they are included in the tarball generated by "make dist", but otherwise these seem a nice set of tests to me. Greetings, Maxime. [-- Attachment #1.1.2: OpenPGP public key --] [-- Type: application/pgp-keys, Size: 929 bytes --] [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 236 bytes --]
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
Hi, Andrew Whatson <whatson@gmail.com> skribis: > 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. The test looks great, thanks a lot! One minor nitpick and then we’re ready to go: > + (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"))))) Can we avoid the separate files and instead do something like: (call-with-input-string " (foo)" (lambda (port) (set-port-filename! port "test-error-location.scm") (read-and-compile port #:opts … #:to 'cps))) ? Thanks, Ludo’.
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
Ludovic Courtès <ludo@gnu.org> wrote:
>
> One minor nitpick and then we’re ready to go:
>
> > + (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")))))
>
> Can we avoid the separate files and instead do something like:
>
> (call-with-input-string " (foo)"
> (lambda (port)
> (set-port-filename! port "test-error-location.scm")
> (read-and-compile port #:opts … #:to 'cps)))
>
> ?
That cleans things up nicely! I've sent v3 of the patch incorporating
this change.
Thanks for the review!
Cheers,
Andrew
Pushed to 02f69c1d84126c35900c5743a712b1e7d07e449d. Thank you!