aboutsummaryrefslogtreecommitdiff
path: root/tests/git.scm
blob: aa4f03ca62ca0db8482f4dc5ac4825cb56c26ac3 (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
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2019, 2020 Ludovic Courtès <ludo@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-git)
  #:use-module (git)
  #:use-module (guix git)
  #:use-module (guix tests git)
  #:use-module (guix build utils)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-64))

;; Test the (guix git) tools.

(test-begin "git")

;; 'with-temporary-git-repository' relies on the 'git' command.
(unless (which (git-command)) (test-skip 1))
(test-assert "commit-difference, linear history"
  (with-temporary-git-repository directory
      '((add "a.txt" "A")
        (commit "first commit")
        (add "b.txt" "B")
        (commit "second commit")
        (add "c.txt" "C")
        (commit "third commit")
        (add "d.txt" "D")
        (commit "fourth commit"))
    (with-repository directory repository
      (let ((commit1 (find-commit repository "first"))
            (commit2 (find-commit repository "second"))
            (commit3 (find-commit repository "third"))
            (commit4 (find-commit repository "fourth")))
        (and (lset= eq? (commit-difference commit4 commit1)
                    (list commit2 commit3 commit4))
             (lset= eq? (commit-difference commit4 commit2)
                    (list commit3 commit4))
             (equal? (commit-difference commit3 commit2)
                     (list commit3))

             ;; COMMIT4 is not an ancestor of COMMIT1 so we should get the
             ;; empty list.
             (null? (commit-difference commit1 commit4)))))))

(unless (which (git-command)) (test-skip 1))
(test-assert "commit-difference, fork"
  (with-temporary-git-repository directory
      '((add "a.txt" "A")
        (commit "first commit")
        (branch "devel")
        (checkout "devel")
        (add "devel/1.txt" "1")
        (commit "first devel commit")
        (add "devel/2.txt" "2")
        (commit "second devel commit")
        (checkout "master")
        (add "b.txt" "B")
        (commit "second commit")
        (add "c.txt" "C")
        (commit "third commit")
        (merge "devel" "merge")
        (add "d.txt" "D")
        (commit "fourth commit"))
    (with-repository directory repository
      (let ((master1 (find-commit repository "first commit"))
            (master2 (find-commit repository "second commit"))
            (master3 (find-commit repository "third commit"))
            (master4 (find-commit repository "fourth commit"))
            (devel1  (find-commit repository "first devel"))
            (devel2  (find-commit repository "second devel"))
            (merge   (find-commit repository "merge")))
        (and (equal? (commit-difference master4 merge)
                     (list master4))
             (lset= eq? (commit-difference master3 master1)
                    (list master3 master2))
             (lset= eq? (commit-difference devel2 master1)
                    (list devel2 devel1))

             ;; The merge occurred between MASTER2 and MASTER4 so here we
             ;; expect to see all the commits from the "devel" branch in
             ;; addition to those on "master".
             (lset= eq? (commit-difference master4 master2)
                    (list master4 merge master3 devel1 devel2)))))))

(unless (which (git-command)) (test-skip 1))
(test-assert "commit-difference, excluded commits"
  (with-temporary-git-repository directory
      '((add "a.txt" "A")
        (commit "first commit")
        (add "b.txt" "B")
        (commit "second commit")
        (add "c.txt" "C")
        (commit "third commit")
        (add "d.txt" "D")
        (commit "fourth commit")
        (add "e.txt" "E")
        (commit "fifth commit"))
    (with-repository directory repository
      (let ((commit1 (find-commit repository "first"))
            (commit2 (find-commit repository "second"))
            (commit3 (find-commit repository "third"))
            (commit4 (find-commit repository "fourth"))
            (commit5 (find-commit repository "fifth")))
        (and (lset= eq? (commit-difference commit4 commit1 (list commit2))
                    (list commit3 commit4))
             (lset= eq? (commit-difference commit4 commit1 (list commit3))
                    (list commit4))
             (null? (commit-difference commit4 commit1 (list commit5))))))))

(unless (which (git-command)) (test-skip 1))
(test-equal "commit-relation"
  '(self                                          ;master3 master3
    ancestor                                      ;master1 master3
    descendant                                    ;master3 master1
    unrelated                                     ;master2 branch1
    unrelated                                     ;branch1 master2
    ancestor                                      ;branch1 merge
    descendant                                    ;merge branch1
    ancestor                                      ;master1 merge
    descendant)                                   ;merge master1
  (with-temporary-git-repository directory
      '((add "a.txt" "A")
        (commit "first commit")
        (branch "hack")
        (checkout "hack")
        (add "1.txt" "1")
        (commit "branch commit")
        (checkout "master")
        (add "b.txt" "B")
        (commit "second commit")
        (add "c.txt" "C")
        (commit "third commit")
        (merge "hack" "merge"))
    (with-repository directory repository
      (let ((master1 (find-commit repository "first"))
            (master2 (find-commit repository "second"))
            (master3 (find-commit repository "third"))
            (branch1 (find-commit repository "branch"))
            (merge   (find-commit repository "merge")))
        (list (commit-relation master3 master3)
              (commit-relation master1 master3)
              (commit-relation master3 master1)
              (commit-relation master2 branch1)
              (commit-relation branch1 master2)
              (commit-relation branch1 merge)
              (commit-relation merge branch1)
              (commit-relation master1 merge)
              (commit-relation merge master1))))))

(test-end "git")
quot;))) (inputs (list gmp)) (home-page "https://www.ginac.de/CLN/") (synopsis "Library for arbitrary precision computations") (description "CLN is a C++ library for efficient computations with all kinds of numbers in arbitrary precision. It provides a rich set of number classes and elementary, logical and transcendental functions.") (license gpl2+))) (define-public tomsfastmath (package (name "tomsfastmath") (version "0.13.1") (synopsis "Large integer arithmetic library") (source (origin (method url-fetch) (uri (string-append "https://github.com/libtom/tomsfastmath/" "releases/download/v" version "/" "tfm-" version ".tar.xz")) (sha256 (base32 "0f0pmiaskh89sp0q933pafxb914shpaj5ad8sb5rzk1wv8d7mja7")))) (build-system gnu-build-system) (native-inputs (list libtool)) (arguments `(#:make-flags (list "-f" "makefile.shared" (string-append "LIBPATH=" %output "/lib") (string-append "INCPATH=" %output "/include") "GROUP=root" "USER=root" "CC=gcc") #:phases (modify-phases %standard-phases (delete 'configure) ; no configuration (replace 'check (lambda* (#:key make-flags #:allow-other-keys) (apply invoke "make" "stest" "test_standalone" make-flags) (invoke "./stest") (invoke "./test"))) (add-before 'install 'install-nogroup (lambda _ ;; Let permissions inherit from the current process. (substitute* "makefile.shared" (("-g \\$\\(GROUP\\) -o \\$\\(USER\\)") "")) #t)) (add-after 'install 'install-doc (lambda* (#:key outputs #:allow-other-keys) (let ((docdir (string-append (assoc-ref outputs "out") "/share/doc/tomsfastmath"))) (install-file "doc/tfm.pdf" docdir) #t))) (add-after 'install 'install-pc (lambda* (#:key outputs #:allow-other-keys) (let* ((out (assoc-ref outputs "out")) (pc-dir (string-append out "/lib/pkgconfig"))) (call-with-output-file "tomsfastmath.pc" (lambda (port) (format port "~ Name: TomsFastMath Description: ~a Version: ~a Libs: -L~a/lib -ltfm~%" ,synopsis ,version out))) (install-file "tomsfastmath.pc" pc-dir) #t)))))) (home-page "https://www.libtom.net/TomsFastMath/") (description "TomsFastMath is a large integer library written in portable ISO C. It is a port of LibTomMath with optional support for inline assembler multiplies.") (license public-domain))) (define-public libtomcrypt (package (name "libtomcrypt") (version "1.18.2") (outputs '("out" "static")) (source (origin (method url-fetch) (uri (string-append "https://github.com/libtom/libtomcrypt" "/releases/download/v" version "/crypt-" version ".tar.xz")) (sha256 (base32 "113vfrgapyv72lalhd3nkw7jnks8az0gcb5wqn9hj19nhcxlrbcn")) (modules '((guix build utils))) (snippet '(begin ;; Patch CVE-2019-17362 ;; https://github.com/libtom/libtomcrypt/commit/25c26a3b7a9ad8192ccc923e15cf62bf0108ef94 (substitute* "src/pk/asn1/der/utf8/der_decode_utf8_string.c" (("z > 4") "z == 1 || z > 4")) #t)))) (build-system gnu-build-system) (arguments `(#:phases (modify-phases %standard-phases (delete 'configure) ; no configure (add-after 'unpack 'prepare-build (lambda _ ;; We want the shared library by default so force it to be the ;; default makefile target. (delete-file "makefile") (symlink "makefile.shared" "makefile") ;; We link to libtommath, so we need to add it to the pc file (substitute* "libtomcrypt.pc.in" (("-ltomcrypt") "-ltomcrypt -ltommath")) #t)) (add-after 'build 'build-static (lambda* (#:key make-flags #:allow-other-keys) (apply invoke "make" "-f" "makefile.unix" make-flags))) (replace 'check (lambda* (#:key test-target make-flags #:allow-other-keys) (apply invoke "make" "-f" "makefile.unix" test-target make-flags) (invoke "./test"))) (add-after 'install 'install-static-library (lambda* (#:key outputs #:allow-other-keys) (let ((out (assoc-ref outputs "out")) (static (assoc-ref outputs "static"))) (mkdir-p (string-append static "/lib")) (mkdir-p (string-append static "/include")) (rename-file (string-append out "/lib/libtomcrypt.a") (string-append static "/lib/libtomcrypt.a")) (copy-recursively (string-append out "/include") (string-append static "/include")) #t)))) #:test-target "test" #:make-flags (list (string-append "PREFIX=" (assoc-ref %outputs "out")) "CFLAGS += -DLTM_DESC -DUSE_LTM" (string-append "EXTRALIBS=" (search-input-file %build-inputs "/lib/libtommath.so")) (string-append "CC=" ,(cc-for-target))))) (native-inputs (list libtool)) (inputs (list libtommath)) (home-page "https://www.libtom.net/LibTomCrypt/") (synopsis "Cryptographic toolkit") (description "LibTomCrypt is a fairly comprehensive, modular and portable cryptographic toolkit that provides developers with a vast array of well known published block ciphers, one-way hash functions, chaining modes, pseudo-random number generators, public key cryptography and a plethora of other routines.") (properties `((lint-hidden-cve . ("CVE-2019-17362")))) (license unlicense))) (define-public libtommath (package (name "libtommath") (version "1.3.0") (outputs '("out" "static")) (source (origin (method url-fetch) (uri (string-append "https://github.com/libtom/libtommath/releases/" "download/v" version "/ltm-" version ".tar.xz")) (sha256 (base32 "024xzb66abhla7kjks07ga05id9lq007cq3kxc41769m6kcp4qi9")))) (build-system gnu-build-system) (arguments '(#:phases (modify-phases %standard-phases (delete 'configure) ; no configure (add-after 'unpack 'prepare-build (lambda _ ;; We want the shared library by default so force it to be the ;; default makefile target. (delete-file "makefile") (symlink "makefile.shared" "makefile"))) (add-after 'install 'remove-static-library (lambda* (#:key outputs #:allow-other-keys) (delete-file (string-append (assoc-ref outputs "out") "/lib/libtommath.a")))) (replace 'check (lambda* (#:key tests? test-target make-flags #:allow-other-keys) (when tests? (apply invoke "make" test-target make-flags) (invoke "sh" "test")))) (add-after 'install 'install-static-library (lambda* (#:key outputs #:allow-other-keys) (invoke "make" "-f" "makefile.unix" "install" (string-append "PREFIX=" (assoc-ref outputs "static")) (string-append "CC=" (which "gcc")))))) #:test-target "test" #:make-flags (list (string-append "PREFIX=" (assoc-ref %outputs "out")) "CC=gcc"))) (native-inputs (list libtool)) (home-page "https://www.libtom.net/LibTomMath/") (synopsis "Portable number theoretic multiple-precision integer library") (description "LibTomMath is a portable number theoretic multiple-precision integer library written entirely in C. It's designed to provide an API that is simple to work with that provides fairly efficient routines that build out of the box without configuration.") (properties `((upstream-name . "ltm") (lint-hidden-cve . ("CVE-2023-36328")))) (license unlicense)))