aboutsummaryrefslogtreecommitdiff
path: root/tests/utils.scm
blob: 6590ed91cf8cca567f31a286adc74ab9dc37fe37 (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
195
196
197
198
199
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2012, 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2014 Eric Bavier <bavier@member.fsf.org>
;;; Copyright © 2016 Mathieu Lirzin <mthl@gnu.org>
;;;
;;; 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-utils)
  #:use-module ((guix config) #:select (%gzip))
  #:use-module (guix utils)
  #:use-module ((guix store) #:select (%store-prefix store-path-package-name))
  #:use-module ((guix search-paths) #:select (string-tokenize*))
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-11)
  #:use-module (srfi srfi-64)
  #:use-module (rnrs bytevectors)
  #:use-module (rnrs io ports)
  #:use-module (ice-9 match)
  #:use-module (ice-9 vlist))

(define temp-file
  (string-append "t-utils-" (number->string (getpid))))

(test-begin "utils")

(test-assert "bytevector->base16-string->bytevector"
  (every (lambda (bv)
           (equal? (base16-string->bytevector
                    (bytevector->base16-string bv))
                   bv))
         (map string->utf8 '("" "f" "fo" "foo" "foob" "fooba" "foobar"))))

(test-assert "gnu-triplet->nix-system"
  (let ((samples '(("i586-gnu0.3" "i686-gnu")
                   ("x86_64-unknown-linux-gnu" "x86_64-linux")
                   ("i386-pc-linux-gnu" "i686-linux")
                   ("x86_64-unknown-freebsd8.2" "x86_64-freebsd")
                   ("x86_64-apple-darwin10.8.0" "x86_64-darwin")
                   ("i686-pc-cygwin" "i686-cygwin"))))
    (let-values (((gnu nix) (unzip2 samples)))
      (every (lambda (gnu nix)
               (equal? nix (gnu-triplet->nix-system gnu)))
             gnu nix))))

(test-assert "package-name->name+version"
  (every (match-lambda
          ((name version)
           (let*-values (((full-name)
                          (if version
                              (string-append name "@" version)
                              name))
                         ((name* version*)
                          (package-name->name+version full-name)))
             (and (equal? name* name)
                  (equal? version* version)))))
         '(("foo" "0.9.1b")
           ("foo-14-bar" "320")
           ("foo-bar2" #f)
           ("guile" "2.0.6.65-134c9") ; as produced by `git-version-gen'
           ("nixpkgs" "1.0pre22125_a28fe19")
           ("gtk2" "2.38.0"))))

(test-assert "guile-version>? 1.8"
  (guile-version>? "1.8"))

(test-assert "guile-version>? 10.5"
  (not (guile-version>? "10.5")))

(test-equal "string-tokenize*"
  '(("foo")
    ("foo" "bar" "baz")
    ("foo" "bar" "")
    ("foo" "bar" "baz"))
  (list (string-tokenize* "foo" ":")
        (string-tokenize* "foo;bar;baz" ";")
        (string-tokenize* "foo!bar!" "!")
        (string-tokenize* "foo+-+bar+-+baz" "+-+")))

(test-equal "string-replace-substring"
  '("foo BAR! baz"
    "/gnu/store/chbouib"
    "")
  (list (string-replace-substring "foo bar baz" "bar" "BAR!")
        (string-replace-substring "/nix/store/chbouib" "/nix/" "/gnu/")
        (string-replace-substring "" "foo" "bar")))

(test-equal "strip-keyword-arguments"
  '(a #:b b #:c c)
  (strip-keyword-arguments '(#:foo #:bar #:baz)
                           '(a #:foo 42 #:b b #:baz 3
                               #:c c #:bar 4)))

(test-equal "ensure-keyword-arguments"
  '((#:foo 2)
    (#:foo 2 #:bar 3)
    (#:foo 42 #:bar 3))
  (list (ensure-keyword-arguments '(#:foo 2) '(#:foo 2))
        (ensure-keyword-arguments '(#:foo 2) '(#:bar 3))
        (ensure-keyword-arguments '(#:foo 2) '(#:bar 3 #:foo 42))))

(test-assert "filtered-port, file"
  (let* ((file  (search-path %load-path "guix.scm"))
         (input (open-file file "r0b")))
    (let*-values (((compressed pids1)
                   (filtered-port `(,%gzip "-c" "--fast") input))
                  ((decompressed pids2)
                   (filtered-port `(,%gzip "-d") compressed)))
      (and (every (compose zero? cdr waitpid)
                  (append pids1 pids2))
           (equal? (get-bytevector-all decompressed)
                   (call-with-input-file file get-bytevector-all))))))

(test-assert "filtered-port, non-file"
  (let ((data (call-with-input-file (search-path %load-path "guix.scm")
                get-bytevector-all)))
    (let*-values (((compressed pids1)
                   (filtered-port `(,%gzip "-c" "--fast")
                                  (open-bytevector-input-port data)))
                  ((decompressed pids2)
                   (filtered-port `(,%gzip "-d") compressed)))
      (and (pk (every (compose zero? cdr waitpid)
                   (append pids1 pids2)))
           (equal? (get-bytevector-all decompressed) data)))))

(test-assert "filtered-port, does not exist"
  (let* ((file  (search-path %load-path "guix.scm"))
         (input (open-file file "r0b")))
    (let-values (((port pids)
                  (filtered-port '("/does/not/exist") input)))
      (any (compose (negate zero?) cdr waitpid)
           pids))))

(test-assert "compressed-port, decompressed-port, non-file"
  (let ((data (call-with-input-file (search-path %load-path "guix.scm")
                get-bytevector-all)))
    (let*-values (((compressed pids1)
                   (compressed-port 'xz (open-bytevector-input-port data)))
                  ((decompressed pids2)
                   (decompressed-port 'xz compressed)))
      (and (every (compose zero? cdr waitpid)
                  (append pids1 pids2))
           (equal? (get-bytevector-all decompressed) data)))))

(false-if-exception (delete-file temp-file))
(test-assert "compressed-output-port + decompressed-port"
  (let* ((file (search-path %load-path "guix/derivations.scm"))
         (data (call-with-input-file file get-bytevector-all))
         (port (open-file temp-file "w0b")))
    (call-with-compressed-output-port 'xz port
      (lambda (compressed)
        (put-bytevector compressed data)))
    (close-port port)

    (bytevector=? data
                  (call-with-decompressed-port 'xz (open-file temp-file "r0b")
                    get-bytevector-all))))

;; This is actually in (guix store).
(test-equal "store-path-package-name"
  "bash-4.2-p24"
  (store-path-package-name
   (string-append (%store-prefix)
                  "/qvs2rj2ia5vci3wsdb7qvydrmacig4pg-bash-4.2-p24")))

(test-equal "canonical-newline-port"
  "This is a journey\nInto the sound\nA journey ...\n"
  (let ((port (open-string-input-port
               "This is a journey\r\nInto the sound\r\nA journey ...\n")))
    (get-string-all (canonical-newline-port port))))


(test-equal "edit-expression"
  "(display \"GNU Guix\")\n(newline)\n"
  (begin
    (call-with-output-file temp-file
      (lambda (port)
        (display "(display \"xiuG UNG\")\n(newline)\n" port)))
    (edit-expression `((filename . ,temp-file)
                       (line     . 0)
                       (column   . 9))
                     string-reverse)
    (call-with-input-file temp-file get-string-all)))

(test-end)

(false-if-exception (delete-file temp-file))
timedia.scm?id=ade77dd0d3fec4950e89bbb59c69a5f1fe668c38'>gnu: Fix input typoes....* gnu/packages/crates-io.scm (rust-nettle-sys-2)[inputs]: Move ‘,’ to its operand. * gnu/packages/docbook.scm (docbook-dsssl)[native-inputs]: Likewise. (docbook-dsssl-doc)[native-inputs]: Likewise. * gnu/packages/emacs-xyz.scm (emacs-helm-slack)[propagated-inputs]: Likewise. * gnu/packages/kde-multimedia.scm (audiocd-kio)[inputs]: Likewise. * gnu/packages/kde-pim.scm (akonadi-mime, kalarmcal, kcalendarsupport) (keventviews, kmailtransport, kpimtextedit)[inputs]: Likewise. * gnu/packages/mpd.scm (cantata)[inputs]: Likewise. * gnu/packages/raspberry-pi.scm (bcm2835): Likewise. * gnu/packages/samba.scm (samba)[native-inputs]: Likewise. * gnu/packages/xdisorg.scm (dex)[inputs]: Likewise. Tobias Geerinckx-Rice 2021-01-04gnu: elisa: Update to 20.12.0....* gnu/packages/kde-multimedia.scm (elisa): Update to 20.12.0. [source]: Use new upstream source URI. [arguments]: Replace 'check phase. Efraim Flashner 2020-12-12gnu: KDE: Fix old cgit home-pages....Fix all home-pages pointing to git-repos a cgit.kde.org, which is gone, to now use the correct repo at invent.kde.org. * gnu/packages/kde.scm (grantleetheme, kdiagram): Update home-page. * gnu/packages/kde-frameworks.scm (kholidays): Likewise. * gnu/packages/kde-internet.scm (libgravatar, libktorrent): Likewise. * gnu/packages/kde-multimedia.scm (libkcddb, libkcompactdisc): Likewise. * gnu/packages/kde-pim.scm (kblog, kdav, kdepim-apps-libs, kdepim-runtime, keventviews, kincidenceeditor, kmailcommon, kmailimporter, kmessagelib, kpimcommon, ksmtp, libkdepim, libkgapi, libkleo, libksieve): Likewise. * gnu/packages/kde-plasma.scm (kdecoration, kscreenlocker): Likewise. Hartmut Goebel 2020-09-07gnu: k3b: Add missing input....* gnu/packages/kde-multimedia.scm (inputs): Add zlib. Remove FIXME for library that is referenced by the final package. Andreas Enge 2020-06-21gnu: k3b: Update to 20.04.2....* gnu/packages/kde-multimedia.scm (k3b): Update to 20.04.2. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Timotej Lazar 2020-06-21gnu: k3b: Note the runtime dependency on udisks-service....* gnu/packages/kde-multimedia.scm (k3b)[description]: Note that udisks-service should be enabled. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Timotej Lazar 2020-06-21gnu: k3b: Add inputs for libraries loaded at runtime....Patch the source to load these from absolute paths. Actual loading is done by the Qt library, so we cannot use k3b’s runpath. * gnu/packages/kde-multimedia.scm (k3b)[inputs]: Add libcdio-paranoia and libdvdcss. [arguments]<#:phases>[set-absolute-library-paths]: New phase. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Timotej Lazar 2020-06-21gnu: k3b: Add inputs for external programs....* gnu/packages/kde-multimedia.scm (k3b)[inputs]: Add cdrdao, dvd+rw-tools, libburn and sox. [arguments]<#:phases>[wrap-path]: New phase to wrap the binary with paths to the above. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Timotej Lazar 2020-06-06gnu: KDE: Update to 20.04.1....* gnu/packages/patches/akonadi-paths.patch: Adjust for upstream changes. * gnu/packages/patches/kdepim-runtime-Fix-missing-link-libraries.patch: Delete file. * gnu/local.mk (dist_patch_DATA): Adjust accordingly. * gnu/packages/kde-internet.scm (kget, kopete, krdc, libgravatar): Update to 20.04.1. [source](uri): Adjust for new upstream location. * gnu/packages/kde-multimedia.scm (audiocd-kio, dragon, ffmpegthumbs, juk, k3b, kamoso, kmix, kwave, libkcddb, libkcompactdisc): Likewise. * gnu/packages/kde-systemtools.scm (dolphin, dolphin-plugins, khelpcenter, konsole, krfb, ksystemlog): Update to 20.04.1. [source](uri): Adjust for new upstream location. * gnu/packages/kde-utils.scm (kate, kmag, kmousetool, kmouth, sweeper): Update to 20.04.1. [source](uri): Adjust for new upstream location. * gnu/packages/kde.scm (baloo-widgets, libkomparediff2, kqtquickcharts, grantleetheme, kcachegrind, libkdegames, zeroconf-ioslave): Update to 20.04.1. [source](uri): Adjust for new upstream location. (grantleetheme)[inputs]: Add KGUIADDONS. * gnu/packages/kde-pim.scm (akonadi, akonadi-calendar, akonadi-contacts, akonadi-mime, akonadi-notes, akonadi-search, kincidenceeditor, kaddressbook, kalarmcal, kblog, kcalendarsupport, kcalutils, kdav, kdepim-apps-libs, kdepim-runtime, keventviews, kgpg, kidentitymanagement, kimap, kldap, kleopatra, kmail, kmailcommon, kmailimporter, kmailtransport, kmbox, kmessagelib, kmime, knotes, kontactinterface, korganizer, kpimcommon, kpimtextedit, ksmtp, ktnef, libkdepim, libkgapi, libkleo, libksieve): Update to 20.04.1. [source](uri): Adjust to current. (akonadi)[inputs]: Remove KDBUSADDONS and KDESIGNERPLUGIN. (akonadi-calendar)[inputs]: Remove KDBUSADDONS. (kdepim-runtime)[source](patches): Remove. [arguments]: Add phase 'extend-CPLUS_INCLUDE_PATH'. [inputs]: Remove KDBUSADDONS and KICONTHEMES. (kmessagelib)[arguments]: Add phase 'extend-CPLUS_INCLUDE_PATH. [inputs]: Add QCA. (kdepim-apps-libs)[inputs]: Remove KDBUSADDONS and KICONTHEMES. (knotes)[inputs]: Remove KDBUSADDONS. (kpimcommon)[inputs]: Remove KDBUSADDONS and KCOMPLETION. (libksieve)[arguments]: Disable one more test. (korganizer)[arguments]: Disable one test. Marius Bakke 2020-04-12gnu: elisa: Fix grammar of "allows to browse" to "browses"....* gnu/packages/kde-multimedia (elisa): Fix grammar. Vagrant Cascadian 2020-03-08gnu: Reword and extend descriptions for some KDE packages....* gnu/packages/kde-multimedia.scm (libkcompatdisc)[description]: Extend. * gnu/packages/kde-pim.scm (akonadi-search, kalarmcal, kdemailimporter, kdepim-apps-libs, kidentitymanagement, kldap, kmailtransport, kmbox, kmime, kontactinterface, kpimtextedit)[description]: Reword and extend. (ktnef, kpimcommon, libkdepim)[synopsis, description]: Reword and extend. (kmailtransport)[synopsis]: Fix space. * gnu/packages/kde-systemtools.scm (khelpcenter)[description]: Extend. Hartmut Goebel 2019-12-26gnu: Add ffmpegthumbs....* gnu/packages/kde-multimedia.scm (ffmpegthumbs): New variable. Hartmut Goebel 2019-12-26gnu: Add audiocd-kio....* gnu/packages/kde-multimedia.scm (audiocd-kio): New variable. Hartmut Goebel 2019-12-26gnu: Add libkcompactdisc....* gnu/packages/kde-multimedia.scm (libkcompactdisc): New variable. Hartmut Goebel 2019-12-26gnu: Add kamoso....* gnu/packages/kde-multimedia.scm (kamoso): New variable. Hartmut Goebel 2019-12-26gnu: Add elisa....* gnu/packages/kde-multimedia.scm (elisa): New variable. Hartmut Goebel 2019-12-26gnu: Add kwave....* gnu/packages/kde-multimedia.scm (kwave): New variable. Hartmut Goebel 2019-12-26gnu: Add kmplayer....`guix lint` reports two CVEs, both are unrelated: - CVE-2018-5200: for vendor "pandora" and some 4.2.2.x version - CVE-2019-9133: windows only (I assume it it alsow relates to the "pandora" vendor, since the version the CVE refers to as "solving the issue" does not exist at KDE.) * gnu/packages/kde-multimedia.scm (kmplayer): New variable. * gnu/packages/patches/kmplayer-aarch64.patch, gnu/packages/patches/kmplayer-upstream_Fix-build-with-Qt-5.9.patch: New files. * gnu/local.mk: Add them. Hartmut Goebel 2019-12-26gnu: Add kmix....* gnu/packages/kde-multimedia.scm (kmix): New variable. Hartmut Goebel 2019-12-26gnu: Add kaffeine....* gnu/packages/kde-multimedia.scm (kaffeine): New variable. Hartmut Goebel 2019-12-26gnu: Add libkcddb....* gnu/packages/kde-multimedia.scm (libkcddb): New variable. Hartmut Goebel 2019-12-26gnu: Add k3b....* gnu/packages/kde-multimedia.scm (k3b): New variable. Hartmut Goebel 2019-12-26gnu: Add juk....* gnu/packages/kde-multimedia.scm (juk): New variable. Hartmut Goebel 2019-12-26gnu: Add dragon....* gnu/packages/kde-multimedia.scm: New file. * gnu/lokal.mk (MODULES): Add it. Hartmut Goebel