From 2c5d18e421e6c06f4a969f98585ec41aae8eb2e4 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Sat, 30 Apr 2022 15:38:44 +0200 Subject: import: cabal: Support elif statement. Fixes . * guix/import/cabal.scm (make-cabal-parser): Replace if-then-else grammar case with elif-else, modify if-then accordingly. (is-elif): New procedure. (lex-elif): Likewise. (is-id): Add elif keyword. (lex-word): Add test for elif. * tests/hackage.scm (test-cabal-if): New variale. (test-cabal-else): Likewise. (test-cabal-elif): Likewise. (test-cabal-elif-brackets): Likewise. (match-ghc-elif): Likewise. ("hackage->guix-package test lonely if statement", "hackage->guix-package test else statement", "hackage->guix-package test elif statement", "hackage->guix-package test elif statement with brackets"): New tests. --- tests/hackage.scm | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) (limited to 'tests/hackage.scm') diff --git a/tests/hackage.scm b/tests/hackage.scm index 189b9af173..38f75b268e 100644 --- a/tests/hackage.scm +++ b/tests/hackage.scm @@ -309,6 +309,108 @@ executable cabal (test-assert "hackage->guix-package test flag executable" (eval-test-with-cabal test-cabal-flag-executable 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 } + 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 -- cgit v1.2.3