tests: Make the 'lint' tests slightly more concise.

* tests/lint.scm (with-warnings): New macro.
  Replace all uses of 'call-with-warnings' with the corresponding
  'with-warnings' form.
This commit is contained in:
Ludovic Courtès 2014-12-29 20:44:10 +01:00
parent 8b385969cf
commit 4fbf4ca552
1 changed files with 129 additions and 152 deletions

View File

@ -112,188 +112,170 @@ requests."
(thunk)) (thunk))
(get-output-string port))) (get-output-string port)))
(define-syntax-rule (with-warnings body ...)
(call-with-warnings (lambda () body ...)))
(test-assert "description: not empty" (test-assert "description: not empty"
(->bool (->bool
(string-contains (call-with-warnings (string-contains (with-warnings
(lambda ()
(let ((pkg (dummy-package "x" (let ((pkg (dummy-package "x"
(description "")))) (description ""))))
(check-description-style pkg)))) (check-description-style pkg)))
"description should not be empty"))) "description should not be empty")))
(test-assert "description: does not start with an upper-case letter" (test-assert "description: does not start with an upper-case letter"
(->bool (->bool
(string-contains (call-with-warnings (string-contains (with-warnings
(lambda ()
(let ((pkg (dummy-package "x" (let ((pkg (dummy-package "x"
(description "bad description.")))) (description "bad description."))))
(check-description-style pkg)))) (check-description-style pkg)))
"description should start with an upper-case letter"))) "description should start with an upper-case letter")))
(test-assert "description: may start with a digit" (test-assert "description: may start with a digit"
(string-null? (string-null?
(call-with-warnings (with-warnings
(lambda ()
(let ((pkg (dummy-package "x" (let ((pkg (dummy-package "x"
(description "2-component library.")))) (description "2-component library."))))
(check-description-style pkg)))))) (check-description-style pkg)))))
(test-assert "description: may start with lower-case package name" (test-assert "description: may start with lower-case package name"
(string-null? (string-null?
(call-with-warnings (with-warnings
(lambda ()
(let ((pkg (dummy-package "x" (let ((pkg (dummy-package "x"
(description "x is a dummy package.")))) (description "x is a dummy package."))))
(check-description-style pkg)))))) (check-description-style pkg)))))
(test-assert "description: two spaces after end of sentence" (test-assert "description: two spaces after end of sentence"
(->bool (->bool
(string-contains (call-with-warnings (string-contains (with-warnings
(lambda ()
(let ((pkg (dummy-package "x" (let ((pkg (dummy-package "x"
(description "Bad. Quite bad.")))) (description "Bad. Quite bad."))))
(check-description-style pkg)))) (check-description-style pkg)))
"sentences in description should be followed by two spaces"))) "sentences in description should be followed by two spaces")))
(test-assert "description: end-of-sentence detection with abbreviations" (test-assert "description: end-of-sentence detection with abbreviations"
(string-null? (string-null?
(call-with-warnings (with-warnings
(lambda ()
(let ((pkg (dummy-package "x" (let ((pkg (dummy-package "x"
(description (description
"E.g. Foo, i.e. Bar resp. Baz (a.k.a. DVD).")))) "E.g. Foo, i.e. Bar resp. Baz (a.k.a. DVD)."))))
(check-description-style pkg)))))) (check-description-style pkg)))))
(test-assert "synopsis: not empty" (test-assert "synopsis: not empty"
(->bool (->bool
(string-contains (call-with-warnings (string-contains (with-warnings
(lambda ()
(let ((pkg (dummy-package "x" (let ((pkg (dummy-package "x"
(synopsis "")))) (synopsis ""))))
(check-synopsis-style pkg)))) (check-synopsis-style pkg)))
"synopsis should not be empty"))) "synopsis should not be empty")))
(test-assert "synopsis: does not start with an upper-case letter" (test-assert "synopsis: does not start with an upper-case letter"
(->bool (->bool
(string-contains (call-with-warnings (string-contains (with-warnings
(lambda ()
(let ((pkg (dummy-package "x" (let ((pkg (dummy-package "x"
(synopsis "bad synopsis.")))) (synopsis "bad synopsis."))))
(check-synopsis-style pkg)))) (check-synopsis-style pkg)))
"synopsis should start with an upper-case letter"))) "synopsis should start with an upper-case letter")))
(test-assert "synopsis: may start with a digit" (test-assert "synopsis: may start with a digit"
(string-null? (string-null?
(call-with-warnings (with-warnings
(lambda ()
(let ((pkg (dummy-package "x" (let ((pkg (dummy-package "x"
(synopsis "5-dimensional frobnicator")))) (synopsis "5-dimensional frobnicator"))))
(check-synopsis-style pkg)))))) (check-synopsis-style pkg)))))
(test-assert "synopsis: ends with a period" (test-assert "synopsis: ends with a period"
(->bool (->bool
(string-contains (call-with-warnings (string-contains (with-warnings
(lambda ()
(let ((pkg (dummy-package "x" (let ((pkg (dummy-package "x"
(synopsis "Bad synopsis.")))) (synopsis "Bad synopsis."))))
(check-synopsis-style pkg)))) (check-synopsis-style pkg)))
"no period allowed at the end of the synopsis"))) "no period allowed at the end of the synopsis")))
(test-assert "synopsis: ends with 'etc.'" (test-assert "synopsis: ends with 'etc.'"
(string-null? (call-with-warnings (string-null? (with-warnings
(lambda ()
(let ((pkg (dummy-package "x" (let ((pkg (dummy-package "x"
(synopsis "Foo, bar, etc.")))) (synopsis "Foo, bar, etc."))))
(check-synopsis-style pkg)))))) (check-synopsis-style pkg)))))
(test-assert "synopsis: starts with 'A'" (test-assert "synopsis: starts with 'A'"
(->bool (->bool
(string-contains (call-with-warnings (string-contains (with-warnings
(lambda ()
(let ((pkg (dummy-package "x" (let ((pkg (dummy-package "x"
(synopsis "A bad synopŝis")))) (synopsis "A bad synopŝis"))))
(check-synopsis-style pkg)))) (check-synopsis-style pkg)))
"no article allowed at the beginning of the synopsis"))) "no article allowed at the beginning of the synopsis")))
(test-assert "synopsis: starts with 'An'" (test-assert "synopsis: starts with 'An'"
(->bool (->bool
(string-contains (call-with-warnings (string-contains (with-warnings
(lambda ()
(let ((pkg (dummy-package "x" (let ((pkg (dummy-package "x"
(synopsis "An awful synopsis")))) (synopsis "An awful synopsis"))))
(check-synopsis-style pkg)))) (check-synopsis-style pkg)))
"no article allowed at the beginning of the synopsis"))) "no article allowed at the beginning of the synopsis")))
(test-assert "synopsis: starts with 'a'" (test-assert "synopsis: starts with 'a'"
(->bool (->bool
(string-contains (call-with-warnings (string-contains (with-warnings
(lambda ()
(let ((pkg (dummy-package "x" (let ((pkg (dummy-package "x"
(synopsis "a bad synopsis")))) (synopsis "a bad synopsis"))))
(check-synopsis-style pkg)))) (check-synopsis-style pkg)))
"no article allowed at the beginning of the synopsis"))) "no article allowed at the beginning of the synopsis")))
(test-assert "synopsis: starts with 'an'" (test-assert "synopsis: starts with 'an'"
(->bool (->bool
(string-contains (call-with-warnings (string-contains (with-warnings
(lambda ()
(let ((pkg (dummy-package "x" (let ((pkg (dummy-package "x"
(synopsis "an awful synopsis")))) (synopsis "an awful synopsis"))))
(check-synopsis-style pkg)))) (check-synopsis-style pkg)))
"no article allowed at the beginning of the synopsis"))) "no article allowed at the beginning of the synopsis")))
(test-assert "synopsis: too long" (test-assert "synopsis: too long"
(->bool (->bool
(string-contains (call-with-warnings (string-contains (with-warnings
(lambda ()
(let ((pkg (dummy-package "x" (let ((pkg (dummy-package "x"
(synopsis (make-string 80 #\x))))) (synopsis (make-string 80 #\x)))))
(check-synopsis-style pkg)))) (check-synopsis-style pkg)))
"synopsis should be less than 80 characters long"))) "synopsis should be less than 80 characters long")))
(test-assert "synopsis: start with package name" (test-assert "synopsis: start with package name"
(->bool (->bool
(string-contains (call-with-warnings (string-contains (with-warnings
(lambda ()
(let ((pkg (dummy-package "x" (let ((pkg (dummy-package "x"
(name "foo") (name "foo")
(synopsis "foo, a nice package")))) (synopsis "foo, a nice package"))))
(check-synopsis-style pkg)))) (check-synopsis-style pkg)))
"synopsis should not start with the package name"))) "synopsis should not start with the package name")))
(test-assert "synopsis: start with package name prefix" (test-assert "synopsis: start with package name prefix"
(string-null? (string-null?
(call-with-warnings (with-warnings
(lambda ()
(let ((pkg (dummy-package "arb" (let ((pkg (dummy-package "arb"
(synopsis "Arbitrary precision")))) (synopsis "Arbitrary precision"))))
(check-synopsis-style pkg)))))) (check-synopsis-style pkg)))))
(test-assert "synopsis: start with abbreviation" (test-assert "synopsis: start with abbreviation"
(string-null? (string-null?
(call-with-warnings (with-warnings
(lambda ()
(let ((pkg (dummy-package "uucp" (let ((pkg (dummy-package "uucp"
;; Same problem with "APL interpreter", etc. ;; Same problem with "APL interpreter", etc.
(synopsis "UUCP implementation") (synopsis "UUCP implementation")
(description "Imagine this is Taylor UUCP.")))) (description "Imagine this is Taylor UUCP."))))
(check-synopsis-style pkg)))))) (check-synopsis-style pkg)))))
(test-assert "inputs: pkg-config is probably a native input" (test-assert "inputs: pkg-config is probably a native input"
(->bool (->bool
(string-contains (string-contains
(call-with-warnings (with-warnings
(lambda ()
(let ((pkg (dummy-package "x" (let ((pkg (dummy-package "x"
(inputs `(("pkg-config" ,pkg-config)))))) (inputs `(("pkg-config" ,pkg-config))))))
(check-inputs-should-be-native pkg)))) (check-inputs-should-be-native pkg)))
"pkg-config should probably be a native input"))) "pkg-config should probably be a native input")))
(test-assert "patches: file names" (test-assert "patches: file names"
(->bool (->bool
(string-contains (string-contains
(call-with-warnings (with-warnings
(lambda ()
(let ((pkg (dummy-package "x" (let ((pkg (dummy-package "x"
(source (source
(origin (origin
@ -301,76 +283,70 @@ requests."
(uri "someurl") (uri "someurl")
(sha256 "somesha") (sha256 "somesha")
(patches (list "/path/to/y.patch"))))))) (patches (list "/path/to/y.patch")))))))
(check-patches pkg)))) (check-patches pkg)))
"file names of patches should start with the package name"))) "file names of patches should start with the package name")))
(test-assert "home-page: wrong home-page" (test-assert "home-page: wrong home-page"
(->bool (->bool
(string-contains (string-contains
(call-with-warnings (with-warnings
(lambda ()
(let ((pkg (package (let ((pkg (package
(inherit (dummy-package "x")) (inherit (dummy-package "x"))
(home-page #f)))) (home-page #f))))
(check-home-page pkg)))) (check-home-page pkg)))
"invalid"))) "invalid")))
(test-assert "home-page: invalid URI" (test-assert "home-page: invalid URI"
(->bool (->bool
(string-contains (string-contains
(call-with-warnings (with-warnings
(lambda ()
(let ((pkg (package (let ((pkg (package
(inherit (dummy-package "x")) (inherit (dummy-package "x"))
(home-page "foobar")))) (home-page "foobar"))))
(check-home-page pkg)))) (check-home-page pkg)))
"invalid home page URL"))) "invalid home page URL")))
(test-assert "home-page: host not found" (test-assert "home-page: host not found"
(->bool (->bool
(string-contains (string-contains
(call-with-warnings (with-warnings
(lambda ()
(let ((pkg (package (let ((pkg (package
(inherit (dummy-package "x")) (inherit (dummy-package "x"))
(home-page "http://does-not-exist")))) (home-page "http://does-not-exist"))))
(check-home-page pkg)))) (check-home-page pkg)))
"domain not found"))) "domain not found")))
(test-skip (if %http-server-socket 0 1)) (test-skip (if %http-server-socket 0 1))
(test-assert "home-page: Connection refused" (test-assert "home-page: Connection refused"
(->bool (->bool
(string-contains (string-contains
(call-with-warnings (with-warnings
(lambda ()
(let ((pkg (package (let ((pkg (package
(inherit (dummy-package "x")) (inherit (dummy-package "x"))
(home-page %local-url)))) (home-page %local-url))))
(check-home-page pkg)))) (check-home-page pkg)))
"Connection refused"))) "Connection refused")))
(test-skip (if %http-server-socket 0 1)) (test-skip (if %http-server-socket 0 1))
(test-equal "home-page: 200" (test-equal "home-page: 200"
"" ""
(call-with-warnings (with-warnings
(lambda ()
(with-http-server 200 (with-http-server 200
(let ((pkg (package (let ((pkg (package
(inherit (dummy-package "x")) (inherit (dummy-package "x"))
(home-page %local-url)))) (home-page %local-url))))
(check-home-page pkg)))))) (check-home-page pkg)))))
(test-skip (if %http-server-socket 0 1)) (test-skip (if %http-server-socket 0 1))
(test-assert "home-page: 404" (test-assert "home-page: 404"
(->bool (->bool
(string-contains (string-contains
(call-with-warnings (with-warnings
(lambda ()
(with-http-server 404 (with-http-server 404
(let ((pkg (package (let ((pkg (package
(inherit (dummy-package "x")) (inherit (dummy-package "x"))
(home-page %local-url)))) (home-page %local-url))))
(check-home-page pkg))))) (check-home-page pkg))))
"not reachable: 404"))) "not reachable: 404")))
(test-end "lint") (test-end "lint")
@ -380,4 +356,5 @@ requests."
;; Local Variables: ;; Local Variables:
;; eval: (put 'with-http-server 'scheme-indent-function 1) ;; eval: (put 'with-http-server 'scheme-indent-function 1)
;; eval: (put 'with-warnings 'scheme-indent-function 0)
;; End: ;; End: