aboutsummaryrefslogtreecommitdiff
path: root/tests/opam.scm
blob: 11984b56a6df0199f6c49ca8d2381eba1daf3e84 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2018 Julien Lepiller <julien@lepiller.eu>
;;;
;;; 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))
  #:use-module ((guix utils) #:select (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.\"\"\"
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 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)))))
        (mock ((guix import opam) get-opam-repository
               (const test-repo))
              (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 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
                    ('quasiquote
                     (("ocaml-zarith" ('unquote 'ocaml-zarith)))))
                   ('native-inputs
                    ('quasiquote
                     (("ocaml-alcotest" ('unquote 'ocaml-alcotest))
                      ("ocamlbuild" ('unquote 'ocamlbuild)))))
                   ('home-page "https://example.org/")
                   ('synopsis "Some example package")
                   ('description "This package is just an example.")
                   ('license #f))
                 (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")
n the result of 'json->scm'. * tests/import-utils.scm ("alist->package with dependencies"): New test. * gnu/installer.scm (build-compiled-file)[builder]: Use GUILE-JSON-3. * gnu/installer.scm (installer-program)[installer-builder]: Likewise. * gnu/installer/locale.scm (iso639->iso639-languages): Use 'assoc-ref' instead of 'hash-ref', and pass vectors through 'vector->list'. (iso3166->iso3166-territories): Likewise. * gnu/system/vm.scm (system-docker-image)[build]: Use GUILE-JSON-3. * guix/docker.scm (manifest, config): Adjust for Guile-JSON 3. * guix/scripts/pack.scm (docker-image)[build]: Use GUILE-JSON-3. * guix/import/github.scm (fetch-releases-or-tags): Update docstring. (latest-released-version): Use 'assoc-ref' instead of 'hash-ref'. Pass the result of 'fetch-releases-or-tags' to 'vector->list'. * guix/import/launchpad.scm (latest-released-version): Likewise. Ludovic Courtès 2019-05-15installer: Increase backtrace verbosity....* gnu/installer.scm (installer-program): Set terminal-width to 200 to make guile backtraces more verbose. Mathieu Othacehe 2019-05-14installer: Add btrfs-progs to PATH....* gnu/installer.scm (installer-program): Add btrfs-progs to PATH. Danny Milosavljevic 2019-05-13installer: Use 'glibc-supported-locales'....The list of locales supported by glibc is now built from source. * gnu/installer/locale.scm (locale-string->locale): Add optional 'codeset' parameter and honor it. (supported-locales->locales): Rewrite to 'read' from SUPPORTED-LOCALES. * gnu/installer.scm (compute-locale-step): Pass the result of 'glibc-supported-locales' instead of the "aux-files/SUPPORTED" file. * gnu/installer/aux-files/SUPPORTED: Remove. * gnu/local.mk (dist_installer_DATA): Remove it. Ludovic Courtès 2019-04-26installer: Actually reboot when the user presses "Reboot."...* gnu/installer/newt/final.scm (run-install-success-page): Return 'success. * gnu/installer.scm (installer-program): Check the result of the 'final step and reboot upon success. Ludovic Courtès 2019-04-26installer: Run wrapped program with 'execl', not 'system'....'system' invokes /bin/sh, which is certainly not needed here. * gnu/installer.scm (installer-program): Use 'execl', not 'system'. Ludovic Courtès 2019-04-17installer: Translate keyboard layout names....* gnu/installer.scm (installer-program)[installer-builder]: Call 'bindtextdomain' for "xkeyboard-config". * gnu/installer/newt/keymap.scm (run-keymap-page): Add calls to 'gettext'. Ludovic Courtès 2019-04-17installer: Display language and territory names natively....* gnu/installer.scm (installer-program): Add calls to 'bindtextdomain'. * gnu/installer/newt/locale.scm (run-locale-page) <language, territory>: Add calls to 'gettext'. Ludovic Courtès 2019-04-12installer: Choosing a locale opens the translated manual on tty2....Suggested by Florian Pelz. * gnu/system/install.scm (%installation-node-names): New variable. (log-to-info): Expect the chosen locale as an argument. Compute the language, Info file name, and node name. Install the locale. (documentation-shepherd-service): Add 'locale' parameter to the 'start' action and honor it. Set GUIX_LOCPATH and TERM as environment variables for the process. * gnu/installer.scm (apply-locale): Use (gnu services herd). Call 'stop-service' and 'start-service' with the chosen locale. Ludovic Courtès 2019-04-07installer: Generalize desktop environments to system services....* gnu/installer/services.scm (<desktop-environment>): Rename to... (<system-service>): ... this. Add a 'type' field. (%desktop-environments): Rename to... (%system-services): ... this. (desktop-system-service?): New procedure. (desktop-environments->configuration): Rename to... (system-services->configuration): ... this. Determine the base list of services based on whether SERVICES contains at least one "desktop" service. * gnu/installer/newt/services.scm (run-desktop-environments-cbt-page): Adjust accordingly. * gnu/installer.scm (installer-steps): Likewise. Ludovic Courtès 2019-04-07installer: Move the 'locale' step before the 'welcome' step....* gnu/installer.scm (installer-steps): Move the 'locale step before 'welcome. Ludovic Courtès 2019-03-27installer: Produce an 'initrd-modules' field if needed....* gnu/installer/parted.scm (root-user-partition?): New procedure. (bootloader-configuration): Use it. (user-partition-missing-modules, initrd-configuration): New procedures. (user-partitions->configuration): Call 'initrd-configuration'.o * gnu/installer.scm (not-config?): Rename to... (module-to-import?): ... this. Add cases to exclude non-installer and non-build (gnu …) modules. (installer-program)[installer-builder]: Add GUIX to the extension list. Ludovic Courtès 2019-03-25installer: Set the system's 'keyboard-layout' field....* gnu/installer/newt/keymap.scm (keyboard-layout->configuration): New procedure. * gnu/installer.scm (compute-keymap-step): Return RESULT. (installer-steps) <'keymap>: Add 'configuration-formatter' field. (installer-program): Use (gnu installer newt keymap). * gnu/installer/parted.scm (bootloader-configuration): Set 'keyboard-layout'. Ludovic Courtès 2019-01-28gnu: Move most packages from guile.scm to new module....* gnu/packages/guile.scm (artanis, guildhall, guile-aspell, guile-bash, guile-8sync, guile-daemon, guile-dsv, guile-fibers, guile-syntax-highlight, guile-sjson, guile-colorized, guile-pfds, guile-aa-tree, guile-simple-zmq, jupyter-guile-kernel, guile-sparql, guile-debbugs, guile-email, guile-debbugs-next, guile-newt, guile-mastodon, guile-parted, guile-xosd, guile-dbi, guile-dbd-sqlite3, guile-config, guile-hall, guile-ics, guile-wisp, guile-sly, g-wrap, guile-miniadapton, guile-reader, guile2.2-reader, guile-ncurses, guile-ncurses/gpm, guile-lib, guile2.0-lib, guile2.2-lib, guile-minikanren, guile2.0-minikanren, guile2.2-minikanren, guile-irregex, guile2.0-irregex, guile2.2-irregex, haunt, guile2.0-haunt, guile2.2-haunt, guile-redis, guile2.0-redis, guile2.2-redis, guile-commonmark, guile2.0-commonmark, guile2.2-commonmark, mcron, mcron2): Move these variables from here... * gnu/packages/guile-xyz.scm: ...to this new file. * gnu/local.mk (GNU_SYSTEM_MODULES): Add it. * gnu/installer.scm, gnu/packages/bioinformatics.scm, gnu/packages/ci.scm, gnu/packages/gtk.scm, gnu/packages/guile.scm, gnu/packages/mail.scm, gnu/packages/package-management.scm, gnu/packages/skribilo.scm, gnu/packages/web.scm, gnu/services/mcron.scm: Update module references. Ricardo Wurmus 2019-01-17installer: Various renamings....1. s/partitionment/partitioning/ 2. s/crypted/encrypted/ * gnu/installer.scm (installer-steps): Apply renamings. * gnu/installer/newt/partition.scm (run-disk-page): ditto, * gnu/installer/parted.scm (auto-partition): ditto, (luks-format-and-open): ditto, (luks-close): ditto, (user-partitions->configuration): ditto. Mathieu Othacehe 2019-01-17installer: partionment: Add encryption support....* gnu/installer.scm (set-installer-path): Add cryptsetup. * gnu/installer/newt/partition.scm (prompt-luks-passwords): New procedure, (run-partioning-page): Add the possibility to set encryption to "On" on a partition and choose a label, add a new partition scheme: "Guided - using the entire disk with encryption", prompt for encryption passwords before proceeding to formating. * gnu/installer/parted.scm (<user-partition>)[crypt-label], [crypt-password]: New fields, (partition-description): add the encryption label, (user-partition-description): add an encryption field, (auto-partition): add two partitioning schemes: entire-crypted-root and entire-crypted-root-home, (call-with-luks-key-file): new procedure, (user-partition-upper-path): new procedure, (luks-format-and-open): new procedure, (luks-close): new procedure, (format-user-partitions): format and open luks partitions before creating file-system. (mount-user-partitions): use the path returned by user-partition-upper-path, (umount-user-partitions): close the luks partitions, (user-partition->file-system): set device field to label for luks partitions and to uuid for the rest, (user-partition->mapped-device): new procedure, (user-partitions->configuration): add mapped-devices field. Mathieu Othacehe 2019-01-17installer: Display an eventual backtrace in a page....* gnu/installer.scm (installer-program): Write the backtrace in "/tmp/last-installer-error" and pass the filename to installer-exit-error. * gnu/installer/newt.scm (exit-error): Display the file passed above in a textbox. Mathieu Othacehe 2019-01-17installer: Reorder partitionment step....* gnu/installer.scm (installer-steps): Run partitionment step after keymap step, so that the keyboard is correctly mapped when filling the mount-point entry in partitionment page. Mathieu Othacehe 2019-01-17installer: Add partitioning support....* gnu/installer.scm (installer-steps): Add partitioning step. * gnu/installer/newt.scm (newt-installer): Add partition-page field. * gnu/installer/newt/partition.scm: New file. * gnu/installer/parted.scm: New file. * gnu/installer/record (installer): New partition-page field. * gnu/local.mk (GNU_SYSTEM_MODULES): Add new files. * po/guix/POTFILES.in: Add new files. Mathieu Othacehe 2019-01-17installer: Fix comments....* gnu/installer.scm (installer-steps): Fix comments. Mathieu Othacehe 2019-01-17installer: Add hostname....* gnu/installer/hostname.scm: New file. * gnu/installer.scm (installer-program): Use new module above. * gnu/local.mk (GNU_SYSTEM_MODULES): Add new file. * po/guix/POTFILES.in: Add new file. Mathieu Othacehe 2019-01-17installer: Add services page....Add a page to select services, for now only desktop environments choice is available. * gnu/installer.scm (steps): Add services step. * gnu/installer/newt.scm (newt-installer): Add services-page field. * gnu/installer/newt/services.scm: New file. * gnu/installer/record.scm (installer): Add services-page field. * gnu/installer/services.scm: New file. * gnu/local.mk (GNU_SYSTEM_MODULES): Add new files. * po/guix/POTFILES.in: Add new files. Mathieu Othacehe 2019-01-17installer: Do not ask for keyboard model....Suppose that the keyboard model is "pc105". * gnu/installer.scm (apply-keymap): Remove model ... * gnu/installer/newt/keymap.scm (run-keymap-page): passed here. (run-model-page): remove procedure * gnu/installer/record.scm (installer): Edit keymap-page prototype in comment. * gnu/installer/keymap.scm (default-keyboard-model): New exported parameter. Mathieu Othacehe 2019-01-17installer: Add configuration formatter....* gnu/installer.scm (installer-steps): Add configuration-formatter procedures. * gnu/installer/final.scm: New file. * gnu/installer/locale.scm (locale->configuration): New exported procedure. * gnu/installer/newt.scm (newt-installer): Add final page. * gnu/installer/newt/final.scm: New file. * gnu/installer/record.scm (installer): Add final-page field. * gnu/installer/timezone.scm (posix-tz->configuration): New exported procedure. * gnu/installer/steps.scm (installer-step): Rename configuration-proc field to configuration-formatter. (%installer-configuration-file): New exported parameter, (%installer-target-dir): ditto, (%configuration-file-width): ditto, (format-configuration): new exported procedure, (configuration->file): new exported procedure. Mathieu Othacehe 2019-01-17installer: Fix locale installation....For some mysterious reason, calling 'setlocale' as first instruction of installer-builder does not install unicode support correctly. So set LANG env variable and start the installer until this is understood. * gnu/installer.scm (installer-program): Wrap installer-builder to have the opportunity to set LANG environment variable before starting the installer. Mathieu Othacehe 2019-01-17installer: Move everything to the build side....* gnu/installer.scm: Rename to ... * gnu/installer/record.scm: ... this. * gnu/installer/build-installer.scm: Move everything to the build side and rename to gnu/installer.scm. * gnu/installer/newt.scm: Remove all the gexps and add depencies to newt modules as this code will only be used on the build side by now. * gnu/local.mk (GNU_SYSTEM_MODULES): Adapt it, (dist_installer_DATA): New rule to install installer's aux-files. * gnu/system/install.scm (%installation-services): Use only 'installer-program' from (gnu installer). The installer is now choosen on the build side. * guix/self.scm (*system-modules*): Restore previous behaviour and add all installer files to #:extra-files field of the scheme-node. * po/guix/POTFILES.in: Adapt it. Mathieu Othacehe 2019-01-17gnu: Add graphical installer support....* configure.ac: Require that guile-newt is available. * gnu/installer.scm: New file. * gnu/installer/aux-files/logo.txt: New file. * gnu/installer/build-installer.scm: New file. * gnu/installer/connman.scm: New file. * gnu/installer/keymap.scm: New file. * gnu/installer/locale.scm: New file. * gnu/installer/newt.scm: New file. * gnu/installer/newt/ethernet.scm: New file. * gnu/installer/newt/hostname.scm: New file. * gnu/installer/newt/keymap.scm: New file. * gnu/installer/newt/locale.scm: New file. * gnu/installer/newt/menu.scm: New file. * gnu/installer/newt/network.scm: New file. * gnu/installer/newt/page.scm: New file. * gnu/installer/newt/timezone.scm: New file. * gnu/installer/newt/user.scm: New file. * gnu/installer/newt/utils.scm: New file. * gnu/installer/newt/welcome.scm: New file. * gnu/installer/newt/wifi.scm: New file. * gnu/installer/steps.scm: New file. * gnu/installer/timezone.scm: New file. * gnu/installer/utils.scm: New file. * gnu/local.mk (GNU_SYSTEM_MODULES): Add previous files. * gnu/system.scm: Export %root-account. * gnu/system/install.scm (%installation-services): Use kmscon instead of linux VT for all tty. (installation-os)[users]: Add the graphical installer as shell of the root account. [packages]: Add font related packages. * po/guix/POTFILES.in: Add installer files. Mathieu Othacehe