diff options
author | Philip McGrath <philip@philipmcgrath.com> | 2022-05-18 14:10:56 -0400 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2022-05-22 01:07:52 +0200 |
commit | 903c82583e1cec4c9ff09d5895c5cc646c37b661 (patch) | |
tree | f505b13b906873f22e5aa758bf1b9a0589d42e7b /tests/elm.scm | |
parent | 9a47fd56dd927995e68a2c894a237aed11aa32f7 (diff) |
import: Add Elm importer.
* guix/import/elm.scm, guix/scripts/import/elm.scm: New files.
* Makefile.am (MODULES): Add them.
* guix/scripts/import.scm (importers): Add "elm".
* doc/guix.texi (Invoking guix import): Document Elm importer.
* doc/contributing.texi (Elm Packages): Mention it.
* tests/elm.scm ("(guix import elm)"): New test group.
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'tests/elm.scm')
-rw-r--r-- | tests/elm.scm | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/tests/elm.scm b/tests/elm.scm index 96f958f060..c30623da03 100644 --- a/tests/elm.scm +++ b/tests/elm.scm @@ -18,6 +18,13 @@ (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") @@ -94,4 +101,168 @@ (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 + ,'`(("elm-core" ,elm-core))) + (inputs + ,'`(("elm-json" ,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") |