diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/cache.scm | 15 | ||||
-rw-r--r-- | tests/guix-shell-export-manifest.sh | 5 | ||||
-rw-r--r-- | tests/hackage.scm | 215 | ||||
-rw-r--r-- | tests/home-import.scm | 13 | ||||
-rw-r--r-- | tests/home-services.scm | 46 |
5 files changed, 285 insertions, 9 deletions
diff --git a/tests/cache.scm b/tests/cache.scm index 80b44d69aa..d495ace2bd 100644 --- a/tests/cache.scm +++ b/tests/cache.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2017, 2020 Ludovic Courtès <[email protected]> +;;; Copyright © 2022 Simon Tournier <[email protected]> ;;; ;;; This file is part of GNU Guix. ;;; @@ -74,6 +75,20 @@ (lambda (port) (display 0 port))))) +(test-equal "maybe-remove-expired-cache-entries, empty cache" + '("a" "b" "c") + (test-cache-cleanup cache + (call-with-output-file (string-append cache "/last-expiry-cleanup") + (lambda (port) + (display "" port))))) + +(test-equal "maybe-remove-expired-cache-entries, corrupted cache" + '("a" "b" "c") + (test-cache-cleanup cache + (call-with-output-file (string-append cache "/last-expiry-cleanup") + (lambda (port) + (display "1\"34657890" port))))) + (test-end "cache") ;;; Local Variables: diff --git a/tests/guix-shell-export-manifest.sh b/tests/guix-shell-export-manifest.sh index f83904deb4..05429955b9 100644 --- a/tests/guix-shell-export-manifest.sh +++ b/tests/guix-shell-export-manifest.sh @@ -69,6 +69,11 @@ guix build -m "$manifest" -d | \ guix build -m "$manifest" -d | \ grep "$(guix build git -d)" +guix shell --export-manifest -D guile -D python-itsdangerous > "$manifest" +guix build -m "$manifest" -d | grep "$(guix build libffi -d)" +guix build -m "$manifest" -d | \ + grep "$(guix build -e '(@ (gnu packages python) python)' -d)" + # Test various combinations to make sure generated code uses interfaces # correctly. for options in \ diff --git a/tests/hackage.scm b/tests/hackage.scm index 189b9af173..ad2ee4b7f9 100644 --- a/tests/hackage.scm +++ b/tests/hackage.scm @@ -156,6 +156,31 @@ library Exposed-Modules: Test.QuickCheck.Exception") +(define test-read-cabal-2 + "name: test-me +common defaults + if os(foobar) { cc-options: -DBARBAZ } +") ; Intentional newline. + +;; Test opening bracket on new line. +(define test-read-cabal-brackets-newline + "name: test-me +common defaults + build-depends: + { foobar + , barbaz + } +") + +;; Test library with (since Cabal 2.0) and without names. +(define test-read-cabal-library-name + "name: test-me +library foobar + build-depends: foo, bar +library + build-depends: bar, baz +") + (test-begin "hackage") (define-syntax-rule (define-package-matcher name pattern) @@ -309,6 +334,165 @@ executable cabal (test-assert "hackage->guix-package test flag executable" (eval-test-with-cabal test-cabal-flag-executable match-ghc-foo)) +;; There is no mandatory space between property name and value. +(define test-cabal-property-no-space + "name:foo +version:1.0.0 +homepage:http://test.org +synopsis:synopsis +description:description +license:BSD3 +common bench-defaults + ghc-options:-Wall +executable cabal + build-depends: + HTTP >= 4000.2.5 && < 4000.3, + mtl >= 2.0 && < 3 +") + +(test-assert "hackage->guix-package test properties without space" + (eval-test-with-cabal test-cabal-property-no-space match-ghc-foo)) + +;; There may be no final newline terminating a property. +(define test-cabal-no-final-newline +"name: foo +version: 1.0.0 +homepage: http://test.org +synopsis: synopsis +description: description +license: BSD3 +executable cabal + build-depends: HTTP >= 4000.2.5 && < 4000.3, mtl >= 2.0 && < 3") + +(test-expect-fail 1) +(test-assert "hackage->guix-package test without final newline" + (eval-test-with-cabal test-cabal-no-final-newline match-ghc-foo)) + +;; Make sure internal libraries will not be part of the dependencies, +;; ignore case. +(define test-cabal-internal-library-ignored + "name: foo +version: 1.0.0 +homepage: http://test.org +synopsis: synopsis +description: description +license: BSD3 +executable cabal + build-depends: + HTTP >= 4000.2.5 && < 4000.3, + internAl +library internaL + build-depends: mtl >= 2.0 && < 3 +") + +(test-assert "hackage->guix-package test internal libraries are ignored" + (eval-test-with-cabal test-cabal-internal-library-ignored match-ghc-foo)) + +;; Check if-elif-else statements +(define test-cabal-if + "name: foo +version: 1.0.0 +homepage: http://test.org +synopsis: synopsis +description: description +license: BSD3 +library + if os(first) + Build-depends: ghc-c +") + +(define test-cabal-else + "name: foo +version: 1.0.0 +homepage: http://test.org +synopsis: synopsis +description: description +license: BSD3 +library + if os(first) + Build-depends: ghc-a + else + Build-depends: ghc-c +") + +(define test-cabal-elif + "name: foo +version: 1.0.0 +homepage: http://test.org +synopsis: synopsis +description: description +license: BSD3 +library + if os(first) + Build-depends: ghc-a + elif os(second) + Build-depends: ghc-b + elif os(guix) + Build-depends: ghc-c + elif os(third) + Build-depends: ghc-d + else + Build-depends: ghc-e +") + +;; Try the same with different bracket styles +(define test-cabal-elif-brackets + "name: foo +version: 1.0.0 +homepage: http://test.org +synopsis: synopsis +description: description +license: BSD3 +library + if os(first) { + Build-depends: ghc-a + } + elif os(second) + Build-depends: ghc-b + elif os(guix) { Build-depends: ghc-c } + elif os(third) { + Build-depends: ghc-d } + elif os(fourth) + { + Build-depends: ghc-d + } else + Build-depends: ghc-e +") + +(define-package-matcher match-ghc-elif + ('package + ('name "ghc-foo") + ('version "1.0.0") + ('source + ('origin + ('method 'url-fetch) + ('uri ('hackage-uri "foo" 'version)) + ('sha256 + ('base32 + (? string? hash))))) + ('build-system 'haskell-build-system) + ('inputs ('list 'ghc-c)) + ('home-page "http://test.org") + ('synopsis (? string?)) + ('description (? string?)) + ('license 'license:bsd-3))) + +(test-assert "hackage->guix-package test lonely if statement" + (eval-test-with-cabal test-cabal-else match-ghc-elif + #:cabal-environment '(("os" . "guix")))) + +(test-assert "hackage->guix-package test else statement" + (eval-test-with-cabal test-cabal-else match-ghc-elif + #:cabal-environment '(("os" . "guix")))) + +(test-assert "hackage->guix-package test elif statement" + (eval-test-with-cabal test-cabal-elif match-ghc-elif + #:cabal-environment '(("os" . "guix")))) + +(test-assert "hackage->guix-package test elif statement with brackets" + (eval-test-with-cabal test-cabal-elif-brackets match-ghc-elif + #:cabal-environment '(("os" . "guix")))) + ;; Check Hackage Cabal revisions. (define test-cabal-revision "name: foo @@ -352,7 +536,7 @@ executable cabal (test-assert "read-cabal test 1" (match (call-with-input-string test-read-cabal-1 read-cabal) ((("name" ("test-me")) - ('section 'library + ('section 'library #f (('if ('flag "base4point8") (("build-depends" ("base >= 4.8 && < 5"))) (('if ('flag "base4") @@ -369,6 +553,35 @@ executable cabal #t) (x (pk 'fail x #f)))) +(test-assert "read-cabal test: if brackets on the same line" + (match (call-with-input-string test-read-cabal-2 read-cabal) + ((("name" ("test-me")) + ('section 'common "defaults" + (('if ('os "foobar") + (("cc-options" ("-DBARBAZ "))) + ())))) + #t) + (x (pk 'fail x #f)))) + +(test-expect-fail 1) +(test-assert "read-cabal test: property brackets on new line" + (match (call-with-input-string test-read-cabal-brackets-newline read-cabal) + ((("name" ("test-me")) + ('section 'common "defaults" + (("build-depends" ("foobar , barbaz"))))) + #t) + (x (pk 'fail x #f)))) + +(test-assert "read-cabal test: library name" + (match (call-with-input-string test-read-cabal-library-name read-cabal) + ((("name" ("test-me")) + ('section 'library "foobar" + (("build-depends" ("foo, bar")))) + ('section 'library #f + (("build-depends" ("bar, baz"))))) + #t) + (x (pk 'fail x #f)))) + (define test-cabal-import "name: foo version: 1.0.0 diff --git a/tests/home-import.scm b/tests/home-import.scm index ca8aa95431..d62a6de648 100644 --- a/tests/home-import.scm +++ b/tests/home-import.scm @@ -103,8 +103,8 @@ corresponding file." ('gnu 'services)) ('home-environment ('packages - ('map ('compose 'list 'specification->package+output) - ('list "[email protected]" "gcc:lib" "[email protected]"))) + ('specifications->packages + ('list "[email protected]" "gcc:lib" "[email protected]"))) ('services ('list))))) @@ -132,8 +132,7 @@ corresponding file." ('gnu 'services)) ('home-environment ('packages - ('map ('compose 'list 'specification->package+output) - ('list))) + ('specifications->packages ('list))) ('services ('list))))) @@ -147,8 +146,7 @@ corresponding file." ('gnu 'home 'services 'shells)) ('home-environment ('packages - ('map ('compose 'list 'specification->package+output) - ('list))) + ('specifications->packages ('list))) ('services ('list ('service 'home-bash-service-type @@ -168,8 +166,7 @@ corresponding file." ('gnu 'home 'services 'shells)) ('home-environment ('packages - ('map ('compose 'list 'specification->package+output) - ('list))) + ('specifications->packages ('list))) ('services ('list ('service 'home-bash-service-type diff --git a/tests/home-services.scm b/tests/home-services.scm new file mode 100644 index 0000000000..e13733cabd --- /dev/null +++ b/tests/home-services.scm @@ -0,0 +1,46 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2022 Ludovic Courtès <[email protected]> +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. + +(define-module (test-home-services) + #:use-module (gnu services) + #:use-module (gnu home services) + #:use-module (guix diagnostics) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-64) + #:use-module (ice-9 match)) + +(test-begin "home-services") + +(test-assert "fold-home-service-types" + (match (fold-home-service-types cons '()) + (() #f) + (lst (and (every service-type? lst) + (every (lambda (type) + (let ((location (service-type-location type))) + (string-contains (location-file location) + "gnu/home"))) + lst))))) + +(test-eq "lookup-service-types" + home-files-service-type + (and (null? (lookup-home-service-types 'does-not-exist-at-all)) + (match (lookup-home-service-types 'home-files) + ((one) one) + (x x)))) + +(test-end) |