aboutsummaryrefslogtreecommitdiff
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2018 Julien Lepiller <julien@lepiller.eu>
;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
;;;
;;; 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-opam)
  #:use-module (guix import opam)
  #:use-module (guix base32)
  #:use-module (gcrypt hash)
  #:use-module (guix tests)
  #:use-module ((guix build syscalls) #:select (mkdtemp!))
  #:use-module ((guix build utils)
                #:select (delete-file-recursively mkdir-p which
                          call-with-temporary-output-file))
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-64)
  #:use-module (web uri)
  #:use-module (ice-9 match)
  #:use-module (ice-9 peg))

(define test-opam-file
"opam-version: \"2.0\"
  version: \"1.0.0\"
maintainer: \"Alice Doe\"
authors: [
  \"Alice Doe\"
  \"John Doe\"
]
homepage: \"https://example.org/\"
bug-reports: \"https://example.org/bugs\"
dev-repo: \"https://example.org/git\"
build: [
  [\"ocaml\" \"pkg/pkg.ml\" \"build\" \"--pinned\" \"%{pinned}%\"]
]
build-test: [
  [\"ocaml\" \"pkg/pkg.ml\" \"build\" \"--pinned\" \"%{pinned}%\" \"--tests\" \"true\"]
]
depends: [
  \"alcotest\" {test & >= \"0.7.2\"}
  \"ocamlbuild\" {build & >= \"0.9.2\"}
  \"zarith\" {>= \"0.7\"}
]
synopsis: \"Some example package\"
description: \"\"\"
This package is just an example.\"\"\"
license: \"BSD-3-Clause\"
url {
  src: \"https://example.org/foo-1.0.0.tar.gz\"
  checksum: \"md5=74c6e897658e820006106f45f736381f\"
}")

(define test-source-hash
  "")

(define test-repo
  (mkdtemp! "/tmp/opam-repo.XXXXXX"))

(test-begin "opam")

(test-assert "opam->guix-package"
  (mock ((guix import opam) get-opam-repository
         (const test-repo))
        (mock ((guix import utils) url-fetch
               (lambda (url file-name)
                 (match url
                   ("https://example.org/foo-1.0.0.tar.gz"
                    (begin
                      (mkdir-p "foo-1.0.0")
                      (system* "tar" "czvf" file-name "foo-1.0.0/")
                      (delete-file-recursively "foo-1.0.0")
                      (set! test-source-hash
                            (call-with-input-file file-name port-sha256))))
                   (_ (error "Unexpected URL: " url)))))
              (let ((my-package (string-append test-repo
                                               "/packages/foo/foo.1.0.0")))
                (mkdir-p my-package)
                (with-output-to-file (string-append my-package "/opam")
                  (lambda _
                    (format #t "~a" test-opam-file))))
              (match (opam->guix-package "foo" #:repo (list test-repo))
                (`(package
                    (name "ocaml-foo")
                    (version "1.0.0")
                    (source (origin
                              (method url-fetch)
                              (uri "https://example.org/foo-1.0.0.tar.gz")
                              (sha256
                               (base32 ,(? string? hash)))))
                    (build-system ocaml-build-system)
                    (propagated-inputs (list ocaml-zarith))
                    (native-inputs
                     (list ocaml-alcotest ocamlbuild))
                    (home-page "https://example.org/")
                    (synopsis "Some example package")
                    (description "This package is just an example.")
                    (license license:bsd-3))
                 (string=? (bytevector->nix-base32-string
                            test-source-hash)
                           hash))
                (x
                 (pk 'fail x #f))))))

;; Test the opam file parser
;; We fold over some test cases. Each case is a pair of the string to parse and the
;; expected result.
(define (test-opam-syntax name pattern test-cases)
  (test-assert name
    (fold (lambda (test acc)
            (display test) (newline)
            (match test
              ((str . expected)
               (and acc
                    (let ((result (peg:tree (match-pattern pattern str))))
                      (if (equal? result expected)
                          #t
                          (pk 'fail (list str result expected) #f)))))))
          #t test-cases)))

(test-opam-syntax
  "parse-strings" string-pat
  '(("" . #f)
    ("\"hello\"" . (string-pat "hello"))
    ("\"hello world\"" . (string-pat "hello world"))
    ("\"The dreaded \\\"é\\\"\"" . (string-pat "The dreaded \"é\""))
    ("\"Have some \\\\\\\\ :)\"" . (string-pat "Have some \\\\ :)"))
    ("\"今日は\"" . (string-pat "今日は"))))

(test-opam-syntax
  "parse-multiline-strings" multiline-string
  '(("" . #f)
    ("\"\"\"hello\"\"\"" . (multiline-string "hello"))
    ("\"\"\"hello \"world\"!\"\"\"" . (multiline-string "hello \"world\"!"))
    ("\"\"\"hello \"\"world\"\"!\"\"\"" . (multiline-string "hello \"\"world\"\"!"))))

(test-opam-syntax
  "parse-lists" list-pat
  '(("" . #f)
    ("[]" . list-pat)
    ("[make]" . (list-pat (var "make")))
    ("[\"make\"]" . (list-pat (string-pat "make")))
    ("[\n  a\n  b\n  c]" . (list-pat (var "a") (var "b") (var "c")))
    ("[a   b     \"c\"]" . (list-pat (var "a") (var "b") (string-pat "c")))
    ;; complex lists
    ("[(a & b)]" . (list-pat (choice-pat (group-pat (var "a") (var "b")))))
    ("[(a | b & c)]" . (list-pat (choice-pat (var "a") (group-pat (var "b") (var "c")))))
    ("[a (b | c) d]" . (list-pat (var "a") (choice-pat (var "b") (var "c")) (var "d")))))

(test-opam-syntax
  "parse-dicts" dict
  '(("" . #f)
    ("{}" . dict)
    ("{a: \"b\"}" . (dict (record "a" (string-pat "b"))))
    ("{a: \"b\"\nc: \"d\"}" . (dict (record "a" (string-pat "b")) (record "c" (string-pat "d"))))))

(test-opam-syntax
  "parse-conditions" condition
  '(("" . #f)
    ("{}" . #f)
    ("{build}" . (condition-var "build"))
    ("{>= \"0.2.0\"}" . (condition-greater-or-equal
                          (condition-string "0.2.0")))
    ("{>= \"0.2.0\" & test}" . (condition-and
                                 (condition-greater-or-equal
                                   (condition-string "0.2.0"))
                                 (condition-var "test")))
    ("{>= \"0.2.0\" | build}" . (condition-or
                                 (condition-greater-or-equal
                                   (condition-string "0.2.0"))
                                 (condition-var "build")))
    ("{ = \"1.0+beta19\" }" . (condition-eq
                                (condition-string "1.0+beta19")))))

(test-opam-syntax
  "parse-comment" list-pat
  '(("" . #f)
    ("[#comment\n]" . list-pat)))

(test-end "opam")
td>2019-04-03gnu: mate-utils: Update to 1.22.0.Guy fleury * gnu/packages/mate.scm (mate-utils): Update to 1.22.0. Signed-off-by: Danny Milosavljevic <dannym@scratchpost.org> 2019-04-03gnu: mate-screensaver: Update to 1.22.0.guy fleury iteriteka * gnu/packages/mate.scm (mate-screensaver): Update to 1.22.0. Signed-off-by: Danny Milosavljevic <dannym@scratchpost.org> 2019-04-03gnu: mate-netbook: Update to 1.22.0.guy fleury iteriteka * gnu/packages/mate.scm (mate-netbook): Update to 1.22.0. Signed-off-by: Danny Milosavljevic <dannym@scratchpost.org> 2019-04-03gnu: backgrounds: Update to 1.22.0.guy fleury iteriteka * gnu/packages/mate.scm (backgrounds): Update to 1.22.0. Signed-off-by: Danny Milosavljevic <dannym@scratchpost.org> 2019-04-03gnu: mate-calc: Update to 1.22.0.guy fleury iteriteka * gnu/packages/mate.scm (mate-calc): Update to 1.22.0. Signed-off-by: Danny Milosavljevic <dannym@scratchpost.org> 2019-04-03gnu: mate-user-guide: Update to 1.22.0.guy fleury iteriteka * gnu/packages/mate.scm (mate-user-guide): Update to 1.22.0. Signed-off-by: Danny Milosavljevic <dannym@scratchpost.org> 2019-04-03gnu: mate-control-center: Update to 1.22.0.guy fleury iteriteka * gnu/packages/mate.scm (mate-control-center): Update to 1.22.0. Signed-off-by: Danny Milosavljevic <dannym@scratchpost.org> 2019-04-03gnu: caja-extensions: Update to 1.22.0.guy fleury iteriteka * gnu/packages/mate.scm (caja-extensions): Update to 1.22.0. Signed-off-by: Danny Milosavljevic <dannym@scratchpost.org> 2019-04-03gnu: atril: Update to 1.22.0.guy fleury iteriteka * gnu/packages/mate.scm (atril): Update to 1.22.0. [arguments]<#:configure-flags>: Remove pre-GTK3 option. Signed-off-by: Danny Milosavljevic <dannym@scratchpost.org> 2019-04-03gnu: marco: Update to 1.22.0.guy fleury iteriteka * gnu/packages/mate.scm (marco): Update to 1.22.0. Signed-off-by: Danny Milosavljevic <dannym@scratchpost.org> 2019-04-03gnu: caja: Update to 1.22.0.guy fleury iteriteka * gnu/packages/mate.scm (caja): Update to 1.22.0. Signed-off-by: Danny Milosavljevic <dannym@scratchpost.org> 2019-04-03gnu: mate-media: Update to 1.22.0.guy fleury iteriteka * gnu/packages/mate.scm (mate-media): Update to 1.22.0. Signed-off-by: Danny Milosavljevic <dannym@scratchpost.org> 2019-04-03gnu: mate-applets: Update to 1.22.0.guy fleury iteriteka * gnu/packages/mate.scm (mate-applets): Update to 1.22.0. Signed-off-by: Danny Milosavljevic <dannym@scratchpost.org> 2019-04-03gnu: mate-panel: Update to 1.22.0.guy fleury iteriteka * gnu/packages/mate.scm (mate-panel): Update to 1.22.0. Signed-off-by: Danny Milosavljevic <dannym@scratchpost.org> 2019-04-03gnu: mate-menus: Update to 1.22.0.guy fleury iteriteka * gnu/packages/mate.scm (mate-menus): Update to 1.22.0. Signed-off-by: Danny Milosavljevic <dannym@scratchpost.org> 2019-04-03gnu: libmatekbd: Update to 1.22.0.guy fleury iteriteka * gnu/packages/mate.scm (libmatekbd): Update to 1.22.0. Signed-off-by: Danny Milosavljevic <dannym@scratchpost.org> 2019-04-03gnu: libmatemixer: Update to 1.22.0.guy fleury iteriteka * gnu/packages/mate.scm (libmatemixer): Update to 1.22.0. Signed-off-by: Danny Milosavljevic <dannym@scratchpost.org> 2019-04-03gnu: mate-settings-daemon: Update to 1.22.0.guy fleury iteriteka * gnu/packages/mate.scm (mate-settings-daemon): Update to 1.22.0. Signed-off-by: Danny Milosavljevic <dannym@scratchpost.org> 2019-04-03gnu: mate-session-manager: Update to 1.22.0.guy fleury iteriteka * gnu/packages/mate.scm (mate-session-manager): Update to 1.22.0. Signed-off-by: Danny Milosavljevic <dannym@scratchpost.org> 2019-04-03gnu: mate-terminal: Update to 1.22.0guy fleury iteriteka * gnu/packages/mate.scm (mate-terminal): Update to 1.22.0. Signed-off-by: Danny Milosavljevic <dannym@scratchpost.org> 2019-04-03gnu: libmatewether: Update to 1.22.0.guy fleury iteriteka * gnu/packages/mate.scm (libmatewether): Update to 1.22.0. Signed-off-by: Danny Milosavljevic <dannym@scratchpost.org> 2019-04-03gnu: mate-desktop: Update to 1.22.2.guy fleury iteriteka * gnu/packages/mate.scm (mate-desktop): Update to 1.22.0. [inputs]: Add iso-codes. Signed-off-by: Danny Milosavljevic <dannym@scratchpost.org> 2019-04-03gnu: mate-themes: Update to 3.22.19.guy fleury iteriteka * gnu/packages/mate.scm (mate-themes): Update to 3.22.19. Signed-off-by: Danny Milosavljevic <dannym@scratchpost.org> 2019-04-03gnu: mate-icon-theme: Update to 1.22.0.guy fleury iteriteka * gnu/packages/mate.scm (mate-icon-theme): Update to 1.20.3. Signed-off-by: Danny Milosavljevic <dannym@scratchpost.org> 2019-04-03gnu: mate-common: Update to 1.22.0.guy fleury iteriteka * gnu/packages/mate.scm (mate-common): Update to 1.22.0. Signed-off-by: Danny Milosavljevic <dannym@scratchpost.org> 2019-03-31gnu: Fix descriptions to not use quotes.Efraim Flashner * gnu/packages/admin.scm (wpa-supplicant-minimal, mingetty, di), * gnu/packages/audio.scm (fil-plugins), * gnu/packages/base.scm (make-ld-wrapper, make-glibc-locales), * gnu/packages/bioinformatics.scm (r-samtools), * gnu/packages/chez.scm (chez-mit), * gnu/packages/commencement.scm (make-gcc-toolchain), * gnu/packages/compression.scm (fastjar), * gnu/packages/cran.scm (r-maps, r-rcpp), * gnu/packages/databases.scm (sparql-query), * gnu/packages/dunst.scm (dunst), * gnu/packages/ftp.scm (ncftp), * gnu/packages/gl.scm (freeglut), * gnu/packages/haskell-check.scm (ghc-tasty-golden), * gnu/packages/haskell.scm (ghc-case-insensitive, ghc-text, ghc-haskell-src, ghc-syb, ghc-deepseq-generics, ghc-network-uri, ghc-rerebase, ghc-zlib), * gnu/packages/image.scm (jbig2dec), * gnu/packages/kde-frameworks.scm (kinit, karchive), * gnu/packages/linux.scm (wireless-tools, perf, module-init-tools, kbd), * gnu/packages/lirc.scm (lirc), * gnu/packages/lisp.scm (uglify-js), * gnu/packages/mate.scm (mate-netbook), * gnu/packages/microcom.scm (microcom), * gnu/packages/music.scm (bristol), * gnu/packages/networking.scm (perl-geo-ip), * gnu/packages/patchutils.scm (patches), * gnu/packages/perl-check.scm (perl-test-more-utf8), * gnu/packages/perl.scm (perl-log-report-optional, perl-file-which, perl-io-tty, perl-log-any, perl-digest-sha1, perl-class-load, perl-regexp-common, perl-module-pluggable, perl-class-modifier), * gnu/packages/python-xyz.scm (python-backports-abc, python-natsort), * gnu/packages/samba.scm (iniparser), * gnu/packages/search.scm (mlocate), * gnu/packages/spice.scm (spice), * gnu/packages/statistics.scm (r-dt, r-lubridate, r-estimability, r-commonmark, r-digest, r-viridislite, r-stringr), * gnu/packages/tex.scm (texlive-latex-changebar), * gnu/packages/version-control.scm (subversion), * gnu/packages/w3m.scm (w3m), * gnu/packages/web.scm (perl-http-parser, perl-plack-middleware-reverseproxy), * gnu/packages/xorg.scm (xkeyboard-config, mkfontdir, xcursor-theme, mkfontscale, xinit, font-alias)[description]: Use @code instead of quotes. 2019-03-18Correct name and email address for ng0.ng0 * .mailmap, Makefile.am, doc/guix.de.texi, doc/guix.fr.texi, doc/guix.texi, etc/completion/fish/guix.fish, gnu/packages/accessibility.scm, gnu/packages/admin.scm, gnu/packages/audio.scm, gnu/packages/autotools.scm, gnu/packages/cdrom.scm, gnu/packages/check.scm, gnu/packages/cinnamon.scm, gnu/packages/compression.scm, gnu/packages/crypto.scm, gnu/packages/databases.scm, gnu/packages/django.scm, gnu/packages/dns.scm, gnu/packages/elixir.scm, gnu/packages/emacs-xyz.scm, gnu/packages/emacs.scm, gnu/packages/enlightenment.scm, gnu/packages/erlang.scm, gnu/packages/fonts.scm, gnu/packages/fontutils.scm, gnu/packages/forth.scm, gnu/packages/fvwm.scm, gnu/packages/games.scm, gnu/packages/gl.scm, gnu/packages/gnome.scm, gnu/packages/gnunet.scm, gnu/packages/gnupg.scm, gnu/packages/gnuzilla.scm, gnu/packages/gtk.scm, gnu/packages/guile-wm.scm,gnu/packages/guile-xyz.scm, gnu/packages/haskell-check.scm, gnu/packages/haskell-crypto.scm, gnu/packages/haskell.scm, gnu/packages/image-viewers.scm, gnu/packages/image.scm, gnu/packages/irc.scm, gnu/packages/language.scm, gnu/packages/libcanberra.scm, gnu/packages/linux.scm, gnu/packages/lisp.scm, gnu/packages/lolcode.scm, gnu/packages/lxde.scm, gnu/packages/lxqt.scm, gnu/packages/mail.scm, gnu/packages/markup.scm, gnu/packages/mate.scm, gnu/packages/maths.scm, gnu/packages/mc.scm, gnu/packages/messaging.scm, gnu/packages/music.scm, gnu/packages/ncurses.scm, gnu/packages/networking.scm, gnu/packages/nickle.scm, gnu/packages/openbox.scm, gnu/packages/pdf.scm, gnu/packages/perl-check.scm, gnu/packages/perl.scm, gnu/packages/python-compression.scm, gnu/packages/python-crypto.scm, gnu/packages/python-web.scm, gnu/packages/python-xyz.scm, gnu/packages/python.scm, gnu/packages/qt.scm, gnu/packages/ruby.scm, gnu/packages/rust.scm, gnu/packages/scheme.scm, gnu/packages/serialization.scm, gnu/packages/shells.scm, gnu/packages/ssh.scm, gnu/packages/suckless.scm, gnu/packages/tbb.scm, gnu/packages/telephony.scm, gnu/packages/text-editors.scm, gnu/packages/textutils.scm, gnu/packages/time.scm, gnu/packages/tls.scm, gnu/packages/tor.scm, gnu/packages/version-control.scm, gnu/packages/video.scm, gnu/packages/vim.scm, gnu/packages/web.scm, gnu/packages/wm.scm, gnu/packages/xdisorg.scm, gnu/packages/xfce.scm, gnu/packages/xml.scm, gnu/packages/xorg.scm, gnu/services/certbot.scm, gnu/services/desktop.scm, gnu/services/version-control.scm, gnu/services/web.scm, guix/import/hackage.scm, guix/licenses.scm: Correct name and email address for ng0. Signed-off-by: Tobias Geerinckx-Rice <me@tobias.gr> 2019-01-15gnu: Separate Python core packages from the rest.Ricardo Wurmus * gnu/packages/python.scm: Move hundreds of package definitions from here... * gnu/packages/python-xyz.scm: ...to this new module. * gnu/local.mk (GNU_SYSTEM_MODULES): Add it. * gnu/packages/ada.scm, gnu/packages/admin.scm, gnu/packages/android.scm, gnu/packages/audio.scm, gnu/packages/backup.scm, gnu/packages/benchmark.scm, gnu/packages/bioinformatics.scm, gnu/packages/bittorrent.scm, gnu/packages/calendar.scm, gnu/packages/check.scm, gnu/packages/chemistry.scm, gnu/packages/cluster.scm, gnu/packages/compression.scm, gnu/packages/connman.scm, gnu/packages/crypto.scm, gnu/packages/cups.scm, gnu/packages/databases.scm, gnu/packages/dav.scm, gnu/packages/direct-connect.scm, gnu/packages/disk.scm, gnu/packages/django.scm, gnu/packages/dlang.scm, gnu/packages/docker.scm, gnu/packages/ebook.scm, gnu/packages/elf.scm, gnu/packages/emacs.scm, gnu/packages/emulators.scm, gnu/packages/engineering.scm, gnu/packages/enlightenment.scm, gnu/packages/finance.scm, gnu/packages/fltk.scm, gnu/packages/fontutils.scm, gnu/packages/freedesktop.scm, gnu/packages/game-development.scm, gnu/packages/games.scm, gnu/packages/geo.scm, gnu/packages/gl.scm, gnu/packages/glib.scm, gnu/packages/gnome.scm, gnu/packages/gnupg.scm, gnu/packages/gnuzilla.scm, gnu/packages/graph.scm, gnu/packages/graphics.scm, gnu/packages/graphviz.scm, gnu/packages/gtk.scm, gnu/packages/ham-radio.scm, gnu/packages/image-processing.scm, gnu/packages/image-viewers.scm, gnu/packages/image.scm, gnu/packages/irc.scm, gnu/packages/jrnl.scm, gnu/packages/julia.scm, gnu/packages/kde-frameworks.scm, gnu/packages/key-mon.scm, gnu/packages/libffi.scm, gnu/packages/libreoffice.scm, gnu/packages/libusb.scm, gnu/packages/lirc.scm, gnu/packages/logging.scm, gnu/packages/machine-learning.scm, gnu/packages/mail.scm, gnu/packages/mate.scm, gnu/packages/maths.scm, gnu/packages/medical.scm, gnu/packages/messaging.scm, gnu/packages/monitoring.scm, gnu/packages/mp3.scm, gnu/packages/mpd.scm, gnu/packages/music.scm, gnu/packages/networking.scm, gnu/packages/nutrition.scm, gnu/packages/openldap.scm, gnu/packages/openstack.scm, gnu/packages/package-management.scm, gnu/packages/password-utils.scm, gnu/packages/patchutils.scm, gnu/packages/pdf.scm, gnu/packages/photo.scm, gnu/packages/polkit.scm, gnu/packages/protobuf.scm, gnu/packages/python-crypto.scm, gnu/packages/python-web.scm, gnu/packages/qt.scm, gnu/packages/rdf.scm, gnu/packages/ruby.scm, gnu/packages/search.scm, gnu/packages/selinux.scm, gnu/packages/serialization.scm, gnu/packages/shells.scm, gnu/packages/simulation.scm, gnu/packages/ssh.scm, gnu/packages/statistics.scm, gnu/packages/storage.scm, gnu/packages/sync.scm, gnu/packages/terminals.scm, gnu/packages/textutils.scm, gnu/packages/time.scm, gnu/packages/tls.scm, gnu/packages/tor.scm, gnu/packages/tryton.scm, gnu/packages/version-control.scm, gnu/packages/video.scm, gnu/packages/virtualization.scm, gnu/packages/vpn.scm, gnu/packages/web-browsers.scm, gnu/packages/web.scm, gnu/packages/wicd.scm, gnu/packages/xdisorg.scm, gnu/packages/xorg.scm: Update module references.