aboutsummaryrefslogtreecommitdiff
path: root/tests/combinators.scm
blob: 1e4bb236b72af1767c899ddb7d15651e4246262c (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
;;; 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>
;;;
;;; 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-combinators)
  #:use-module (guix combinators)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-64)
  #:use-module (ice-9 vlist))

(test-begin "combinators")

(test-equal "fold2, 1 list"
    (list (reverse (iota 5))
          (map - (reverse (iota 5))))
  (call-with-values
      (lambda ()
        (fold2 (lambda (i r1 r2)
                 (values (cons i r1)
                         (cons (- i) r2)))
               '() '()
               (iota 5)))
    list))

(test-equal "fold2, 2 lists"
    (list (reverse '((a . 0) (b . 1) (c . 2) (d . 3)))
          (reverse '((a . 0) (b . -1) (c . -2) (d . -3))))
  (call-with-values
      (lambda ()
        (fold2 (lambda (k v r1 r2)
                 (values (alist-cons k v r1)
                         (alist-cons k (- v) r2)))
               '() '()
               '(a b c d)
               '(0 1 2 3)))
    list))

(let* ((tree (alist->vhash
              '((0 2 3) (1 3 4) (2) (3 5 6) (4 6) (5) (6))
              hashq))
       (add-one (lambda (_ r) (1+ r)))
       (tree-lookup (lambda (n) (cdr (vhash-assq n tree)))))
  (test-equal "fold-tree, single root"
    5 (fold-tree add-one 0 tree-lookup '(0)))
  (test-equal "fold-tree, two roots"
    7 (fold-tree add-one 0 tree-lookup '(0 1)))
  (test-equal "fold-tree, sum"
    16 (fold-tree + 0 tree-lookup '(0)))
  (test-equal "fold-tree, internal"
    18 (fold-tree + 0 tree-lookup '(3 4)))
  (test-equal "fold-tree, cons"
    '(1 3 4 5 6)
    (sort (fold-tree cons '() tree-lookup '(1)) <))
  (test-equal "fold-tree, overlapping paths"
    '(1 3 4 5 6)
    (sort (fold-tree cons '() tree-lookup '(1 4)) <))
  (test-equal "fold-tree, cons, two roots"
    '(0 2 3 4 5 6)
    (sort (fold-tree cons '() tree-lookup '(0 4)) <))
  (test-equal "fold-tree-leaves, single root"
    2 (fold-tree-leaves add-one 0 tree-lookup '(1)))
  (test-equal "fold-tree-leaves, single root, sum"
    11 (fold-tree-leaves + 0 tree-lookup '(1)))
  (test-equal "fold-tree-leaves, two roots"
    3 (fold-tree-leaves add-one 0 tree-lookup '(0 1)))
  (test-equal "fold-tree-leaves, two roots, sum"
    13 (fold-tree-leaves + 0 tree-lookup '(0 1))))

(test-end)

e-inputs inputs configure-flags #:allow-other-keys) (let ((sh (search-input-file (or native-inputs inputs) "bin/sh"))) ;; The configure script does not understand some of the default ;; options of gnu-build-system, so run it "by hand". (apply invoke "./configure" (string-append "SHELL=" sh) (string-append "CONFIG_SHELL=" sh) (string-append "--prefix=" #$output) configure-flags))))))) (home-page "https://www.wxwidgets.org/") (synopsis "Widget toolkit for creating graphical user interfaces") (description "wxWidgets is a C++ library that lets developers create applications with a graphical user interface. It has language bindings for Python, Perl, Ruby and many other languages.") (license (list l:lgpl2.0+ (l:fsf-free "file://doc/license.txt"))))) (define-public wxwidgets-gtk2 (package/inherit wxwidgets (name "wxwidgets-gtk2") (inputs (modify-inputs (package-inputs wxwidgets) (delete "gtk+") (prepend gtk+-2))) (arguments (substitute-keyword-arguments (package-arguments wxwidgets) ((#:configure-flags flags #~'()) #~(append #$flags '("--with-gtk=2"))))))) (define-public wxwidgets-3.0 (package (inherit wxwidgets) (version "3.0.5.1") (source (origin (method url-fetch) (uri (string-append "https://github.com/wxWidgets/wxWidgets/" "releases/download/v" version "/wxWidgets-" version ".tar.bz2")) (sha256 (base32 "01y89999jw5q7njrhxajincx7lydls6yq37ikazjryssrxrnw3s4")))) (arguments `(#:configure-flags '("--with-regex" "--with-libmspack" "--with-sdl" "--enable-webview" "--enable-webkit" "--enable-webviewwebkit" ,@(if (string=? "aarch64-linux" (%current-system)) '("--build=aarch64-unknown-linux-gnu") '())) #:make-flags (list (string-append "LDFLAGS=-Wl,-rpath=" (assoc-ref %outputs "out") "/lib")) ;; No 'check' target. #:tests? #f #:phases (modify-phases %standard-phases (add-after 'unpack 'refer-to-inputs (lambda* (#:key inputs #:allow-other-keys) (let ((mime (search-input-directory inputs "share/mime")) (xdg-open (search-input-file inputs "bin/xdg-open"))) (substitute* "src/unix/utilsx11.cpp" (("wxExecute\\(xdg_open \\+") (string-append "wxExecute(\"" xdg-open "\""))) (substitute* "src/unix/mimetype.cpp" (("/usr(/local)?/share/mime") mime)))))))))) (define-public wxwidgets-gtk2-3.0 (package/inherit wxwidgets-3.0 (name "wxwidgets-gtk2") (inputs (modify-inputs (package-inputs wxwidgets-3.0) (delete "gtk+") (prepend gtk+-2))) (arguments (substitute-keyword-arguments (package-arguments wxwidgets-3.0) ((#:configure-flags flags #~'()) #~(append #$flags '("--with-gtk=2"))))))) (define-public wxwidgets-2 (package (inherit wxwidgets) (version "2.8.12") (source (origin (method url-fetch) (uri (string-append "https://github.com/wxWidgets/wxWidgets/" "releases/download/v" version "/wxGTK-" version ".tar.gz")) (sha256 (base32 "1gjs9vfga60mk4j4ngiwsk9h6c7j22pw26m3asxr1jwvqbr8kkqk")))) (inputs `(("gtk" ,gtk+-2) ("libjpeg" ,libjpeg-turbo) ("libtiff" ,libtiff) ("libmspack" ,libmspack) ("sdl" ,sdl) ("unixodbc" ,unixodbc))) (arguments `(#:configure-flags '("--enable-unicode" "--with-regex=sys" "--with-sdl") #:make-flags (list (string-append "LDFLAGS=-Wl,-rpath=" (assoc-ref %outputs "out") "/lib")) ;; No 'check' target. #:tests? #f #:phases (modify-phases %standard-phases (add-after 'unpack 'ignore-narrowing-errors (lambda _ (substitute* "configure" (("-Wall") "-Wall -Wno-narrowing")) #t))))))) (define-public prusa-wxwidgets ;; There is no proper tag/release, all patches are in separate branches based on ;; the wxWidgets release (e.g. this commit is taken from "v3.2.0-patched" branch".) (let ((commit "78aa2dc0ea7ce99dc19adc1140f74c3e2e3f3a26") (revision "0")) (package (inherit wxwidgets) (name "prusa-wxwidgets") (version (git-version "3.2.0" revision commit)) (home-page "https://github.com/prusa3d/wxWidgets") (source (origin (method git-fetch) (uri (git-reference (url home-page) (commit commit))) (file-name (git-file-name name version)) ;; The patch is taken from the NixOS nixpkgs repository (see ;; <https://github.com/NixOS/nixpkgs/commit/0e724ac89f3dbf6ed31d647290a371b44a85e5ad>.) (patches (search-patches "prusa-wxwidgets-makefile-fix.patch")) (sha256 (base32 "1xk6w7q4xv4cj906xa5dwam5q51mc8bszbkkz7l8d3wjmsz73rwv")))) (native-inputs (modify-inputs (package-native-inputs wxwidgets) (prepend nanosvg))) (arguments (substitute-keyword-arguments (package-arguments wxwidgets) ((#:configure-flags flags) ;; To fix 3D rendering in PrusaSlicer, wxWidgets must be compiled with ;; "--disable-glcanvasegl" flag (see ;; <https://github.com/NixOS/nixpkgs/issues/193135>.) #~(cons "--disable-glcanvasegl" #$flags)) ((#:phases phases) #~(modify-phases #$phases (add-after 'unpack 'copy-nanosvg-source (lambda _ (copy-recursively #$(package-source nanosvg) "3rdparty/nanosvg/")))))))))) (define-public python-wxpython (package (name "python-wxpython") (version "4.2.0") (source (origin (method url-fetch) (uri (pypi-uri "wxPython" version)) (sha256 (base32 "1iw6xp76b3fmdqwbqmsx9i1razzpfki5z1hq6l8mszlxa32fng36")) (modules '((guix build utils))) (snippet '(begin ;; Remove bundled wxwidgets (delete-file-recursively "ext/wxWidgets"))) (patches (search-patches "python-wxwidgets-type-errors.patch")))) (build-system python-build-system) (outputs '("out" "debug")) (arguments (list #:phases #~(modify-phases %standard-phases (add-before 'build 'configure (lambda* (#:key inputs #:allow-other-keys) ;; Configure the build options provided to the 'build.py' build ;; script. (setenv "WXPYTHON_BUILD_ARGS" (string-join '("--debug" ;include debug symbols "--use_syswx"))) ;use system wxwidgets (setenv "WXWIN" #$(this-package-input "wxwidgets")) ;; Copy the waf executable to the source directory since it needs ;; to be in a writable directory. (copy-file (search-input-file inputs "/bin/waf") "bin/waf") (setenv "WAF" "bin/waf") ;; The build script tries to copy license files from the ;; wxwidgets source tree. Prevent it. (substitute* "wscript" (("updateLicenseFiles\\(cfg\\)" all) (string-append "#" all))) ;; The build script tries to write to demo/version.py. So, we set ;; correct write permissions. (chmod "demo/version.py" #o644)))))) (inputs (list gtk+ wxwidgets)) (native-inputs (list pkg-config python-waf)) (propagated-inputs (list python-attrdict3 python-numpy python-pillow python-six)) (home-page "https://wxpython.org/") (synopsis "Cross platform GUI toolkit for Python") (description "wxPython is a cross-platform GUI toolkit for the Python programming language. It is implemented as a set of Python extension modules that wrap the GUI components of the popular wxWidgets cross platform C++ library. In most cases, wxPython uses the native widgets on each platform to provide a 100% native look and feel for the application.") (license l:wxwindows3.1+))) (define-public wxsvg (package (name "wxsvg") (version "1.5.24") (source (origin (method url-fetch) (uri (string-append "mirror://sourceforge/wxsvg/wxsvg/" version "/wxsvg-" version ".tar.bz2")) (sha256 (base32 "10i4bv1bfbfgrrpxvfdjrr5svgn64v471lkcl2pzx9fhz28k4ixf")))) (build-system glib-or-gtk-build-system) (inputs (list wxwidgets cairo ffmpeg)) (native-inputs (list pkg-config)) (propagated-inputs ;; In Requires.private of libwxsvg.pc. (list libexif pango)) (synopsis "C++ library to create, manipulate and render SVG files") (description "wxSVG is a C++ library to create, manipulate and render @dfn{Scalable Vector Graphics} (SVG) files with the wxWidgets toolkit.") (home-page "https://wxsvg.sourceforge.net") ;; wxSVG is licenced under the "wxWindows library licence", which is ;; the LGPL2.0+, with a few extra permissions. (license (list l:lgpl2.0+ (l:fsf-free "file://COPYING"))))) (define-public perl-alien-wxwidgets (package (name "perl-alien-wxwidgets") (version "0.69") (source (origin (method url-fetch) (uri (string-append "mirror://cpan/authors/id/M/MD/MDOOTSON/Alien-wxWidgets-" version ".tar.gz")) (sha256 (base32 "0jg2dmkzhj03f6b0vmv597yryfw9cclsdn9ynvvlrzzgpd5lw8jk")))) (build-system perl-build-system) (native-inputs (list perl-lwp-protocol-https perl-module-build perl-test-pod perl-test-pod-coverage wxwidgets)) (propagated-inputs (list perl-module-pluggable)) (home-page "https://metacpan.org/release/Alien-wxWidgets") (synopsis "Perl module for wxWidgets binaries") (description "Alien::wxWidgets is a Perl module for detecting and getting configuration settings from an installed wxWidgets package.") (license l:perl-license)))