aboutsummaryrefslogtreecommitdiff
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2022 Philip McGrath <philip@philipmcgrath.com>
;;;
;;; 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-elm)
  #:use-module (guix build-system elm)
  #:use-module (guix import elm)
  #:use-module (guix base32)
  #:use-module (guix hash)
  #:use-module (guix utils)
  #:autoload   (gcrypt hash) (hash-algorithm sha256)
  #:use-module (json)
  #:use-module (ice-9 match)
  #:use-module (srfi srfi-64))

(test-begin "elm")

(test-group "elm->package-name and infer-elm-package-name"
  (test-group "round trip"
    ;; Cases when our heuristics can find the upstream name.
    (define-syntax-rule (test-round-trip elm guix)
      (test-group elm
        (test-equal "elm->package-name" guix
                    (elm->package-name elm))
        (test-equal "infer-elm-package-name" elm
                    (infer-elm-package-name guix))))
    (test-round-trip "elm/core" "elm-core")
    (test-round-trip "elm/html" "elm-html")
    (test-round-trip "elm-explorations/markdown" "elm-explorations-markdown")
    (test-round-trip "elm-explorations/test" "elm-explorations-test")
    (test-round-trip "elm-explorations/foo-bar" "elm-explorations-foo-bar")
    (test-round-trip "elm/explorations" "elm-explorations")
    (test-round-trip "terezka/intervals" "elm-terezka-intervals")
    (test-round-trip "justinmimbs/time-extra" "elm-justinmimbs-time-extra")
    (test-round-trip "danhandrea/elm-date-format"
                     "elm-danhandrea-elm-date-format"))
  (test-group "upstream-name needed"
    ;; Upstream names that our heuristic can't infer.  We still check that the
    ;; round-trip behavior of 'infer-elm-package-name' works as promised for
    ;; the hypothetical Elm name it doesn't infer.
    (define-syntax-rule (test-upstream-needed elm guix inferred)
      (test-group elm
        (test-equal "elm->package-name" guix
                    (elm->package-name elm))
        (test-group "infer-elm-package-name"
          (test-equal "infers other name" inferred
                      (infer-elm-package-name guix))
          (test-equal "infered name round-trips" guix
                      (elm->package-name inferred)))))
    (test-upstream-needed "elm/virtual-dom"
                          "elm-virtual-dom"
                          "virtual/dom")
    (test-upstream-needed "elm/project-metadata-utils"
                          "elm-project-metadata-utils"
                          "project/metadata-utils")
    (test-upstream-needed "explorations/foo"
                          "elm-explorations-foo"
                          "elm-explorations/foo")
    (test-upstream-needed "explorations/foo-bar"
                          "elm-explorations-foo-bar"
                          "elm-explorations/foo-bar")
    (test-upstream-needed "explorations-central/foo"
                          "elm-explorations-central-foo"
                          "elm-explorations/central-foo")
    (test-upstream-needed "explorations-central/foo-bar"
                          "elm-explorations-central-foo-bar"
                          "elm-explorations/central-foo-bar")
    (test-upstream-needed "elm-xyz/foo"
                          "elm-xyz-foo"
                          "xyz/foo")
    (test-upstream-needed "elm-xyz/foo-bar"
                          "elm-xyz-foo-bar"
                          "xyz/foo-bar")
    (test-upstream-needed "elm-explorations-xyz/foo"
                          "elm-explorations-xyz-foo"
                          "elm-explorations/xyz-foo")
    (test-upstream-needed "elm-explorations-xyz/foo-bar"
                          "elm-explorations-xyz-foo-bar"
                          "elm-explorations/xyz-foo-bar"))
  (test-group "no inferred Elm name"
    ;; Cases that 'infer-elm-package-name' should not attempt to handle,
    ;; because 'elm->package-name' would never produce such names.
    (define-syntax-rule (test-not-inferred guix)
      (test-assert guix (not (infer-elm-package-name guix))))
    (test-not-inferred "elm")
    (test-not-inferred "guile")
    (test-not-inferred "gcc-toolchain")
    (test-not-inferred "font-adobe-source-sans-pro")))

(define test-package-registry-json
  ;; we intentionally list versions in different orders here
  "{
    \"elm/core\": [\"1.0.0\", \"1.0.1\", \"1.0.2\", \"1.0.3\", \"1.0.4\"],
    \"elm-guix/demo\": [\"2.0.0\", \"3.0.0\", \"1.0.0\"]
}")

(define test-elm-core-json
  "{
    \"type\": \"package\",
    \"name\": \"elm/core\",
    \"summary\": \"Elm's standard libraries\",
    \"license\": \"BSD-3-Clause\",
    \"version\": \"1.0.4\",
    \"exposed-modules\": {
        \"Primitives\": [
            \"Basics\",
            \"String\",
            \"Char\",
            \"Bitwise\",
            \"Tuple\"
        ],
        \"Collections\": [
            \"List\",
            \"Dict\",
            \"Set\",
            \"Array\"
        ],
        \"Error Handling\": [
            \"Maybe\",
            \"Result\"
        ],
        \"Debug\": [
            \"Debug\"
        ],
        \"Effects\": [
            \"Platform.Cmd\",
            \"Platform.Sub\",
            \"Platform\",
            \"Process\",
            \"Task\"
        ]
    },
    \"elm-version\": \"0.19.0 <= v < 0.20.0\",
    \"dependencies\": {},
    \"test-dependencies\": {}
}")

(define test-elm-core-readme
  "# Core Libraries

Every Elm project needs this package!

It provides **basic functionality** like addition and subtraction as well as
**data structures** like lists, dictionaries, and sets.")

(define test-elm-guix-demo-json
  "{
    \"type\": \"package\",
    \"name\": \"elm-guix/demo\",
    \"summary\": \"A test for `(guix import elm)`\",
    \"license\": \"GPL-3.0-or-later\",
    \"version\": \"3.0.0\",
    \"exposed-modules\": [
        \"Guix.Demo\"
    ],
    \"elm-version\": \"0.19.0 <= v < 0.20.0\",
    \"dependencies\": {
        \"elm/core\": \"1.0.0 <= v < 2.0.0\"
    },
    \"test-dependencies\": {
        \"elm/json\": \"1.0.0 <= v < 2.0.0\"
    }
}")

(define test-elm-guix-demo-readme
  ;; intentionally left blank
  "")

(define (directory-sha256 directory)
  "Returns the string representing the hash of DIRECTORY as would be used in a
package definition."
  (bytevector->nix-base32-string
   (file-hash* directory
               #:algorithm (hash-algorithm sha256)
               #:recursive? #t)))

(test-group "(guix import elm)"
  (call-with-temporary-directory
   (lambda (dir)
     ;; Initialize our fake git checkouts.
     (define elm-core-dir
       (string-append dir "/test-elm-core-1.0.4"))
     (define elm-guix-demo-dir
       (string-append dir "/test-elm-guix-demo-3.0.0"))
     (for-each (match-lambda
                 ((dir json readme)
                  (mkdir dir)
                  (with-output-to-file (string-append dir "/elm.json")
                    (lambda ()
                      (display json)))
                  (with-output-to-file (string-append dir "/README.md")
                    (lambda ()
                      (display readme)))))
               `((,elm-core-dir ,test-elm-core-json ,test-elm-core-readme)
                 (,elm-guix-demo-dir
                  ,test-elm-guix-demo-json
                  ,test-elm-guix-demo-readme)))
     ;; Replace network resources with sample data.
     (parameterize ((%elm-package-registry
                     (lambda ()
                       (json-string->scm test-package-registry-json)))
                    (%current-elm-checkout
                     (lambda (name version)
                       (match (list name version)
                         (("elm/core" "1.0.4")
                          elm-core-dir)
                         (("elm-guix/demo" "3.0.0")
                          elm-guix-demo-dir)))))
       (test-assert "(elm->guix-package \"elm/core\")"
         (match (elm->guix-package "elm/core")
           (`(package
               (name "elm-core")
               (version "1.0.4")
               (source (elm-package-origin
                        "elm/core"
                        version
                        (base32 ,(? string? hash))))
               (build-system elm-build-system)
               (home-page
                "https://package.elm-lang.org/packages/elm/core/1.0.4")
               (synopsis "Elm's standard libraries")
               (description "Every Elm project needs this package!")
               (license license:bsd-3))
            (equal? (directory-sha256 elm-core-dir)
                    hash))
           (x
            (raise-exception x))))
       (test-assert "(elm-recursive-import \"elm-guix/demo\")"
         (match (elm-recursive-import "elm-guix/demo")
           (`((package
                (name "elm-guix-demo")
                (version "3.0.0")
                (source (elm-package-origin
                         "elm-guix/demo"
                         version
                         (base32 ,(? string? hash))))
                (build-system elm-build-system)
                (propagated-inputs (list elm-core))
                (inputs (list elm-json))
                (home-page
                 "https://package.elm-lang.org/packages/elm-guix/demo/3.0.0")
                (synopsis "A test for `(guix import elm)`")
                (description
                 "This package provides a test for `(guix import elm)`.")
                (properties '((upstream-name . "elm-guix/demo")))
                (license license:gpl3+)))
            (equal? (directory-sha256 elm-guix-demo-dir)
                    hash))
           (x
            (raise-exception x))))))))

(test-end "elm")
dd missing -L flag in tk.pc and tkConfig.sh....* gnu/packages/tcl.scm (tk)[arguments]: Use 'modify-phases'. Add 'add-fontconfig-flag' phase. [inputs]: Add FONTCONFIG. Ludovic Courtès 2015-09-12gnu: tk: Update to 8.6.4....* gnu/packages/tcl.scm (tk): Update to 8.6.4. 宋文武 2015-09-12gnu: tcl: Update to 8.6.4....* gnu/packages/tcl.scm (tcl): Update to 8.6.4. 宋文武 2015-08-19gnu: tk: Build with Xft support....* gnu/packages/tcl.scm (tk)[inputs]: Add LIBXFT. [native-inputs]: New field. 宋文武 2015-03-14gnu: Update packages to use 'non-copyleft' instead of 'bsd-style'....* gnu/packages/avr.scm, gnu/packages/compression.scm, gnu/packages/curl.scm, gnu/packages/cyrus-sasl.scm, gnu/packages/databases.scm, gnu/packages/firmware.scm, gnu/packages/flex.scm, gnu/packages/fontutils.scm, gnu/packages/gd.scm, gnu/packages/ghostscript.scm, gnu/packages/gnunet.scm, gnu/packages/graphics.scm, gnu/packages/hugs.scm, gnu/packages/image.scm, gnu/packages/linux.scm, gnu/packages/mail.scm, gnu/packages/maths.scm, gnu/packages/mit-krb5.scm, gnu/packages/python.scm, gnu/packages/rdf.scm, gnu/packages/ssh.scm, gnu/packages/tcl.scm, gnu/packages/xdisorg.scm, gnu/packages/xiph.scm, gnu/packages/yasm.scm, gnu/packages/zip.scm: Use 'non-copyleft' instead of 'bsd-style'. Ludovic Courtès 2015-01-07gnu: tcl: Pass --mandir to configure....This partially reverts 9b1bf33081652210502c6ef34506e27a9bc60f06. "gnu: Remove a bunch of now unneeded '--mandir' configure flags." * gnu/packages/tcl.scm (tcl)[arguments]: Put back the --mandir configure flag, with a comment explaining why it's still needed. Mark H Weaver 2015-01-04gnu: Remove a bunch of now unneeded '--mandir' configure flags....This has become redundant with the 'validate-documentation-location' phase introduced in commit d68fe74. * gnu/packages/compression.scm (bzip2): Remove 'fix-man-dir' phase. * gnu/packages/ncurses.scm (ncurses)[arguments]: Remove --mandir. * gnu/packages/pth.scm (pth)[arguments]: Remove #:configure-flags. * gnu/packages/tcl.scm (tcl)[arguments]: Likewise. * gnu/packages/xiph.scm (flac)[arguments]: Likewise. Ludovic Courtès 2014-10-26gnu: Some cleanup based on lint checkers....* gnu/packages/admin.scm, gnu/packages/aidc.scm, gnu/packages/algebra.scm, gnu/packages/apr.scm, gnu/packages/avahi.scm, gnu/packages/backup.scm, gnu/packages/base.scm, gnu/packages/calcurse.scm, gnu/packages/cdrom.scm, gnu/packages/check.scm, gnu/packages/compression.scm, gnu/packages/cook.scm, gnu/packages/crypto.scm, gnu/packages/cryptsetup.scm, gnu/packages/curl.scm, gnu/packages/cyrus-sasl.scm, gnu/packages/databases.scm, gnu/packages/doxygen.scm, gnu/packages/dwm.scm, gnu/packages/elf.scm, gnu/packages/emacs.scm, gnu/packages/feh.scm, gnu/packages/file.scm, gnu/packages/fish.scm, gnu/packages/flex.scm, gnu/packages/fltk.scm, gnu/packages/fontutils.scm, gnu/packages/games.scm, gnu/packages/gcal.scm, gnu/packages/gcc.scm, gnu/packages/geeqie.scm, gnu/packages/ghostscript.scm, gnu/packages/gimp.scm, gnu/packages/gl.scm, gnu/packages/glib.scm, gnu/packages/gnome.scm, gnu/packages/gnunet.scm, gnu/packages/gnupg.scm, gnu/packages/gperf.scm, gnu/packages/grub.scm, gnu/packages/gsasl.scm, gnu/packages/gtk.scm, gnu/packages/guile-wm.scm, gnu/packages/guile.scm, gnu/packages/hurd.scm, gnu/packages/icu4c.scm, gnu/packages/image.scm, gnu/packages/imagemagick.scm, gnu/packages/irssi.scm, gnu/packages/kde.scm, gnu/packages/libdaemon.scm, gnu/packages/libevent.scm, gnu/packages/libidn.scm, gnu/packages/libusb.scm, gnu/packages/linux.scm, gnu/packages/lout.scm, gnu/packages/lsh.scm, gnu/packages/lsof.scm, gnu/packages/lua.scm, gnu/packages/maths.scm, gnu/packages/mcrypt.scm, gnu/packages/mp3.scm, gnu/packages/netpbm.scm, gnu/packages/noweb.scm, gnu/packages/ocaml.scm, gnu/packages/openssl.scm, gnu/packages/pcre.scm, gnu/packages/pdf.scm, gnu/packages/pkg-config.scm, gnu/packages/pretty-print.scm, gnu/packages/python.scm, gnu/packages/qt.scm, gnu/packages/rsync.scm, gnu/packages/scheme.scm, gnu/packages/scrot.scm, gnu/packages/sdl.scm, gnu/packages/skribilo.scm, gnu/packages/ssh.scm, gnu/packages/stalonetray.scm, gnu/packages/tcl.scm, gnu/packages/tcsh.scm, gnu/packages/telephony.scm, gnu/packages/texlive.scm, gnu/packages/tor.scm, gnu/packages/valgrind.scm, gnu/packages/version-control.scm, gnu/packages/vim.scm, gnu/packages/vpn.scm, gnu/packages/w3m.scm, gnu/packages/web.scm, gnu/packages/wordnet.scm, gnu/packages/xiph.scm, gnu/packages/xml.scm, gnu/packages/xorg.scm, gnu/packages/zile.scm, gnu/packages/zip.scm, gnu/packages/zsh.scm [synopsis, description]: Adjust according to lint checkers. * gnu/packages/fltk.scm (fltk)[source]: Wrap long line in uri. * /gnu/packages/xiph.scm (libogg, libtheora, vorbis-tools)[source]: Same. Eric Bavier 2014-09-22gnu: perl-tk: Build sequentially....Fixes <http://bugs.gnu.org/18262>. * gnu/packages/tcl.scm (perl-tk)[arguments]: Add #:parallel-build? #f. Ludovic Courtès 2014-09-13gnu: Adjust synopses as recommended by 'guix lint'....Remove leading articles and trailing periods in package synopses. Ludovic Courtès 2014-06-27gnu: Consolidate libjpeg, libpng, and libtiff into one module....* gnu/packages/image.scm: New file. * gnu-system.am (GNU_SYSTEM_MODULES): Add image.scm and remove libjpeg.scm, libpng.scm, and libtiff.scm. * gnu/packages/libjpeg.scm, gnu/packages/libpng.scm, gnu/packages/libtiff.scm: Delete files. * gnu/packages/emacs.scm gnu/packages/games.scm, gnu/packages/gd.scm, gnu/packages/geeqie.scm, gnu/packages/ghostscript.scm, gnu/packages/gimp.scm, gnu/packages/gnome.scm, gnu/packages/gnunet.scm, gnu/packages/gnustep.scm, gnu/packages/gnuzilla.scm, gnu/packages/graphviz.scm, gnu/packages/gtk.scm, gnu/packages/imagemagick.scm, gnu/packages/inkscape.scm, gnu/packages/netpbm.scm, gnu/packages/pdf.scm, gnu/packages/plotutils.scm, gnu/packages/qemu.scm, gnu/packages/qt.scm, gnu/packages/scheme.scm, gnu/packages/sdl.scm, gnu/packages/slim.scm, gnu/packages/tcl.scm, gnu/packages/texlive.scm, gnu/packages/video.scm, gnu/packages/xiph.scm, gnu/packages/xorg.scm: Use (gnu packages image) module. David Thompson 2014-05-12gnu: perl-tk: Patch for i686...* gnu/packages/patches/perl-tk-x11-discover.patch: New patch. * gnu-system.am [dist_patch_DATA]: Add it. * gnu/packages/tcl.scm (perl-tk)[origin]: Use it. Eric Bavier 2014-04-04gnu: Add perl-tk...* gnu/packages/tcl.scm (perl-tk): New variable Eric Bavier 2014-04-02gnu: expect: Install man pages in share/man....* gnu/packages/tcl.scm (expect): Add --mandir configure flag. Use 'let' to simplify configure flags generation. Mark H Weaver 2014-03-26gnu: tcl: Install man pages in share/man....* gnu/packages/tcl.scm (tcl): Add --mandir configure flag. Mark H Weaver