Commit | Line | Data |
---|---|---|
233e7676 | 1 | ;;; GNU Guix --- Functional package management for GNU |
bbb7a00e | 2 | ;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org> |
e3deeebb | 3 | ;;; |
233e7676 | 4 | ;;; This file is part of GNU Guix. |
e3deeebb | 5 | ;;; |
233e7676 | 6 | ;;; GNU Guix is free software; you can redistribute it and/or modify it |
e3deeebb LC |
7 | ;;; under the terms of the GNU General Public License as published by |
8 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
9 | ;;; your option) any later version. | |
10 | ;;; | |
233e7676 | 11 | ;;; GNU Guix is distributed in the hope that it will be useful, but |
e3deeebb LC |
12 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | ;;; GNU General Public License for more details. | |
15 | ;;; | |
16 | ;;; You should have received a copy of the GNU General Public License | |
233e7676 | 17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. |
e3deeebb | 18 | |
e3deeebb | 19 | (define-module (test-utils) |
e0fbbc88 | 20 | #:use-module ((guix config) #:select (%gzip)) |
e3deeebb | 21 | #:use-module (guix utils) |
b980f0f9 | 22 | #:use-module ((guix store) #:select (%store-prefix store-path-package-name)) |
e3deeebb | 23 | #:use-module (srfi srfi-1) |
98090557 | 24 | #:use-module (srfi srfi-11) |
e3deeebb | 25 | #:use-module (srfi srfi-64) |
f9c7080a | 26 | #:use-module (rnrs bytevectors) |
e0fbbc88 | 27 | #:use-module (rnrs io ports) |
72d86963 | 28 | #:use-module (ice-9 match)) |
e3deeebb LC |
29 | |
30 | (test-begin "utils") | |
31 | ||
6d800a80 LC |
32 | (test-assert "bytevector->base16-string->bytevector" |
33 | (every (lambda (bv) | |
34 | (equal? (base16-string->bytevector | |
35 | (bytevector->base16-string bv)) | |
36 | bv)) | |
37 | (map string->utf8 '("" "f" "fo" "foo" "foob" "fooba" "foobar")))) | |
38 | ||
98090557 LC |
39 | (test-assert "gnu-triplet->nix-system" |
40 | (let ((samples '(("i586-gnu0.3" "i686-gnu") | |
41 | ("x86_64-unknown-linux-gnu" "x86_64-linux") | |
42 | ("i386-pc-linux-gnu" "i686-linux") | |
43 | ("x86_64-unknown-freebsd8.2" "x86_64-freebsd") | |
44 | ("x86_64-apple-darwin10.8.0" "x86_64-darwin") | |
45 | ("i686-pc-cygwin" "i686-cygwin")))) | |
46 | (let-values (((gnu nix) (unzip2 samples))) | |
47 | (every (lambda (gnu nix) | |
48 | (equal? nix (gnu-triplet->nix-system gnu))) | |
49 | gnu nix)))) | |
50 | ||
9b48fb88 LC |
51 | (test-assert "package-name->name+version" |
52 | (every (match-lambda | |
53 | ((name version) | |
54 | (let*-values (((full-name) | |
55 | (if version | |
56 | (string-append name "-" version) | |
57 | name)) | |
58 | ((name* version*) | |
59 | (package-name->name+version full-name))) | |
60 | (and (equal? name* name) | |
61 | (equal? version* version))))) | |
62 | '(("foo" "0.9.1b") | |
63 | ("foo-bar" "1.0") | |
64 | ("foo-bar2" #f) | |
65 | ("guile" "2.0.6.65-134c9") ; as produced by `git-version-gen' | |
66 | ("nixpkgs" "1.0pre22125_a28fe19") | |
67 | ("gtk2" "2.38.0")))) | |
68 | ||
2bcfb9e0 LC |
69 | (test-equal "string-tokenize*" |
70 | '(("foo") | |
71 | ("foo" "bar" "baz") | |
72 | ("foo" "bar" "") | |
73 | ("foo" "bar" "baz")) | |
74 | (list (string-tokenize* "foo" ":") | |
75 | (string-tokenize* "foo;bar;baz" ";") | |
76 | (string-tokenize* "foo!bar!" "!") | |
77 | (string-tokenize* "foo+-+bar+-+baz" "+-+"))) | |
78 | ||
04fd96ca LC |
79 | (test-equal "fold2, 1 list" |
80 | (list (reverse (iota 5)) | |
81 | (map - (reverse (iota 5)))) | |
82 | (call-with-values | |
83 | (lambda () | |
84 | (fold2 (lambda (i r1 r2) | |
85 | (values (cons i r1) | |
86 | (cons (- i) r2))) | |
87 | '() '() | |
88 | (iota 5))) | |
89 | list)) | |
90 | ||
91 | (test-equal "fold2, 2 lists" | |
92 | (list (reverse '((a . 0) (b . 1) (c . 2) (d . 3))) | |
93 | (reverse '((a . 0) (b . -1) (c . -2) (d . -3)))) | |
94 | (call-with-values | |
95 | (lambda () | |
96 | (fold2 (lambda (k v r1 r2) | |
97 | (values (alist-cons k v r1) | |
98 | (alist-cons k (- v) r2))) | |
99 | '() '() | |
100 | '(a b c d) | |
101 | '(0 1 2 3))) | |
102 | list)) | |
103 | ||
e0fbbc88 | 104 | (test-assert "filtered-port, file" |
101d9f3f | 105 | (let* ((file (search-path %load-path "guix.scm")) |
b6952cad | 106 | (input (open-file file "r0b"))) |
101d9f3f LC |
107 | (let*-values (((compressed pids1) |
108 | (filtered-port `(,%gzip "-c" "--fast") input)) | |
109 | ((decompressed pids2) | |
110 | (filtered-port `(,%gzip "-d") compressed))) | |
111 | (and (every (compose zero? cdr waitpid) | |
112 | (append pids1 pids2)) | |
113 | (equal? (get-bytevector-all decompressed) | |
114 | (call-with-input-file file get-bytevector-all)))))) | |
e0fbbc88 LC |
115 | |
116 | (test-assert "filtered-port, non-file" | |
117 | (let ((data (call-with-input-file (search-path %load-path "guix.scm") | |
118 | get-bytevector-all))) | |
119 | (let*-values (((compressed pids1) | |
120 | (filtered-port `(,%gzip "-c" "--fast") | |
121 | (open-bytevector-input-port data))) | |
122 | ((decompressed pids2) | |
123 | (filtered-port `(,%gzip "-d") compressed))) | |
124 | (and (pk (every (compose zero? cdr waitpid) | |
125 | (append pids1 pids2))) | |
126 | (equal? (get-bytevector-all decompressed) data))))) | |
127 | ||
e3d74106 LC |
128 | ;; This is actually in (guix store). |
129 | (test-equal "store-path-package-name" | |
130 | "bash-4.2-p24" | |
131 | (store-path-package-name | |
b980f0f9 LC |
132 | (string-append (%store-prefix) |
133 | "/qvs2rj2ia5vci3wsdb7qvydrmacig4pg-bash-4.2-p24"))) | |
e3d74106 | 134 | |
e3deeebb LC |
135 | (test-end) |
136 | ||
137 | \f | |
138 | (exit (= (test-runner-fail-count (test-runner-current)) 0)) |