Commit | Line | Data |
---|---|---|
e3deeebb LC |
1 | ;;; Guix --- Nix package management from Guile. -*- coding: utf-8 -*- |
2 | ;;; Copyright (C) 2012 Ludovic Courtès <ludo@gnu.org> | |
3 | ;;; | |
4 | ;;; This file is part of Guix. | |
5 | ;;; | |
6 | ;;; Guix is free software; you can redistribute it and/or modify it | |
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 | ;;; | |
11 | ;;; Guix is distributed in the hope that it will be useful, but | |
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 | |
17 | ;;; along with Guix. If not, see <http://www.gnu.org/licenses/>. | |
18 | ||
e3deeebb LC |
19 | (define-module (test-utils) |
20 | #:use-module (guix utils) | |
e3d74106 | 21 | #:use-module ((guix store) #:select (store-path-package-name)) |
e3deeebb | 22 | #:use-module (srfi srfi-1) |
98090557 | 23 | #:use-module (srfi srfi-11) |
e3deeebb | 24 | #:use-module (srfi srfi-64) |
f9c7080a | 25 | #:use-module (rnrs bytevectors) |
72d86963 | 26 | #:use-module (ice-9 match)) |
e3deeebb LC |
27 | |
28 | (test-begin "utils") | |
29 | ||
6d800a80 LC |
30 | (test-assert "bytevector->base16-string->bytevector" |
31 | (every (lambda (bv) | |
32 | (equal? (base16-string->bytevector | |
33 | (bytevector->base16-string bv)) | |
34 | bv)) | |
35 | (map string->utf8 '("" "f" "fo" "foo" "foob" "fooba" "foobar")))) | |
36 | ||
98090557 LC |
37 | (test-assert "gnu-triplet->nix-system" |
38 | (let ((samples '(("i586-gnu0.3" "i686-gnu") | |
39 | ("x86_64-unknown-linux-gnu" "x86_64-linux") | |
40 | ("i386-pc-linux-gnu" "i686-linux") | |
41 | ("x86_64-unknown-freebsd8.2" "x86_64-freebsd") | |
42 | ("x86_64-apple-darwin10.8.0" "x86_64-darwin") | |
43 | ("i686-pc-cygwin" "i686-cygwin")))) | |
44 | (let-values (((gnu nix) (unzip2 samples))) | |
45 | (every (lambda (gnu nix) | |
46 | (equal? nix (gnu-triplet->nix-system gnu))) | |
47 | gnu nix)))) | |
48 | ||
9b48fb88 LC |
49 | (test-assert "package-name->name+version" |
50 | (every (match-lambda | |
51 | ((name version) | |
52 | (let*-values (((full-name) | |
53 | (if version | |
54 | (string-append name "-" version) | |
55 | name)) | |
56 | ((name* version*) | |
57 | (package-name->name+version full-name))) | |
58 | (and (equal? name* name) | |
59 | (equal? version* version))))) | |
60 | '(("foo" "0.9.1b") | |
61 | ("foo-bar" "1.0") | |
62 | ("foo-bar2" #f) | |
63 | ("guile" "2.0.6.65-134c9") ; as produced by `git-version-gen' | |
64 | ("nixpkgs" "1.0pre22125_a28fe19") | |
65 | ("gtk2" "2.38.0")))) | |
66 | ||
72d86963 LC |
67 | (test-assert "define-record-type*" |
68 | (begin | |
69 | (define-record-type* <foo> foo make-foo | |
70 | foo? | |
71 | (bar foo-bar) | |
72 | (baz foo-baz (default (+ 40 2)))) | |
73 | (and (match (foo (bar 1) (baz 2)) | |
74 | (($ <foo> 1 2) #t)) | |
75 | (match (foo (baz 2) (bar 1)) | |
76 | (($ <foo> 1 2) #t)) | |
77 | (match (foo (bar 1)) | |
78 | (($ <foo> 1 42) #t))))) | |
79 | ||
8fd5bd2b LC |
80 | (test-assert "define-record-type* with letrec* behavior" |
81 | ;; Make sure field initializers can refer to each other as if they were in | |
82 | ;; a `letrec*'. | |
83 | (begin | |
84 | (define-record-type* <bar> bar make-bar | |
85 | foo? | |
86 | (x bar-x) | |
87 | (y bar-y (default (+ 40 2))) | |
88 | (z bar-z)) | |
89 | (and (match (bar (x 1) (y (+ x 1)) (z (* y 2))) | |
90 | (($ <bar> 1 2 4) #t)) | |
91 | (match (bar (x 7) (z (* x 3))) | |
92 | (($ <bar> 7 42 21))) | |
93 | (match (bar (z 21) (x (/ z 3))) | |
94 | (($ <bar> 7 42 21)))))) | |
95 | ||
dcd60f43 LC |
96 | (test-assert "define-record-type* & inherit" |
97 | (begin | |
98 | (define-record-type* <foo> foo make-foo | |
99 | foo? | |
100 | (bar foo-bar) | |
101 | (baz foo-baz (default (+ 40 2)))) | |
102 | (let* ((a (foo (bar 1))) | |
103 | (b (foo (inherit a) (baz 2))) | |
104 | (c (foo (inherit b) (bar -2))) | |
105 | (d (foo (inherit c))) | |
106 | (e (foo (inherit (foo (bar 42))) (baz 77)))) | |
107 | (and (match a (($ <foo> 1 42) #t)) | |
108 | (match b (($ <foo> 1 2) #t)) | |
109 | (match c (($ <foo> -2 2) #t)) | |
110 | (equal? c d) | |
111 | (match e (($ <foo> 42 77) #t)))))) | |
112 | ||
113 | (test-assert "define-record-type* & inherit & letrec* behavior" | |
114 | (begin | |
115 | (define-record-type* <foo> foo make-foo | |
116 | foo? | |
117 | (bar foo-bar) | |
118 | (baz foo-baz (default (+ 40 2)))) | |
119 | (let* ((a (foo (bar 77))) | |
120 | (b (foo (inherit a) (bar 1) (baz (+ bar 1)))) | |
121 | (c (foo (inherit b) (baz 2) (bar (- baz 1))))) | |
122 | (and (match a (($ <foo> 77 42) #t)) | |
123 | (match b (($ <foo> 1 2) #t)) | |
124 | (equal? b c))))) | |
125 | ||
e3d74106 LC |
126 | ;; This is actually in (guix store). |
127 | (test-equal "store-path-package-name" | |
128 | "bash-4.2-p24" | |
129 | (store-path-package-name | |
130 | "/nix/store/qvs2rj2ia5vci3wsdb7qvydrmacig4pg-bash-4.2-p24")) | |
131 | ||
e3deeebb LC |
132 | (test-end) |
133 | ||
134 | \f | |
135 | (exit (= (test-runner-fail-count (test-runner-current)) 0)) | |
136 | ||
137 | ;;; Local Variables: | |
138 | ;;; eval: (put 'test-assert 'scheme-indent-function 1) | |
139 | ;;; End: |