summaryrefslogtreecommitdiff
path: root/tests/git.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2019-09-14 17:54:06 +0200
committerLudovic Courtès <ludo@gnu.org>2019-09-23 10:38:43 +0200
commit873f6f1334ab06a69e768a8aea0054404237542f (patch)
tree81d0183061f1dec3c0a0fb276d9c912412c45105 /tests/git.scm
parenta78dcb3d599cc84b347578940bb0fd44b1ad50b4 (diff)
git: Add 'commit-difference'.
* guix/git.scm (commit-closure, commit-difference): New procedures. * guix/tests/git.scm, tests/git.scm: New files. * Makefile.am (dist_noinst_DATA): Add guix/tests/git.scm. (SCM_TESTS): Add tests/git.scm.
Diffstat (limited to 'tests/git.scm')
-rw-r--r--tests/git.scm99
1 files changed, 99 insertions, 0 deletions
diff --git a/tests/git.scm b/tests/git.scm
new file mode 100644
index 00000000000..8ba10ece510
--- /dev/null
+++ b/tests/git.scm
@@ -0,0 +1,99 @@
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
3;;;
4;;; This file is part of GNU Guix.
5;;;
6;;; GNU 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;;; GNU 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 GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19(define-module (test-git)
20 #:use-module (git)
21 #:use-module (guix git)
22 #:use-module (guix tests git)
23 #:use-module (guix build utils)
24 #:use-module (srfi srfi-1)
25 #:use-module (srfi srfi-64))
26
27;; Test the (guix git) tools.
28
29(test-begin "git")
30
31;; 'with-temporary-git-repository' relies on the 'git' command.
32(unless (which (git-command)) (test-skip 1))
33(test-assert "commit-difference, linear history"
34 (with-temporary-git-repository directory
35 '((add "a.txt" "A")
36 (commit "first commit")
37 (add "b.txt" "B")
38 (commit "second commit")
39 (add "c.txt" "C")
40 (commit "third commit")
41 (add "d.txt" "D")
42 (commit "fourth commit"))
43 (with-repository directory repository
44 (let ((commit1 (find-commit repository "first"))
45 (commit2 (find-commit repository "second"))
46 (commit3 (find-commit repository "third"))
47 (commit4 (find-commit repository "fourth")))
48 (and (lset= eq? (commit-difference commit4 commit1)
49 (list commit2 commit3 commit4))
50 (lset= eq? (commit-difference commit4 commit2)
51 (list commit3 commit4))
52 (equal? (commit-difference commit3 commit2)
53 (list commit3))
54
55 ;; COMMIT4 is not an ancestor of COMMIT1 so we should get the
56 ;; empty list.
57 (null? (commit-difference commit1 commit4)))))))
58
59(unless (which (git-command)) (test-skip 1))
60(test-assert "commit-difference, fork"
61 (with-temporary-git-repository directory
62 '((add "a.txt" "A")
63 (commit "first commit")
64 (branch "devel")
65 (checkout "devel")
66 (add "devel/1.txt" "1")
67 (commit "first devel commit")
68 (add "devel/2.txt" "2")
69 (commit "second devel commit")
70 (checkout "master")
71 (add "b.txt" "B")
72 (commit "second commit")
73 (add "c.txt" "C")
74 (commit "third commit")
75 (merge "devel" "merge")
76 (add "d.txt" "D")
77 (commit "fourth commit"))
78 (with-repository directory repository
79 (let ((master1 (find-commit repository "first commit"))
80 (master2 (find-commit repository "second commit"))
81 (master3 (find-commit repository "third commit"))
82 (master4 (find-commit repository "fourth commit"))
83 (devel1 (find-commit repository "first devel"))
84 (devel2 (find-commit repository "second devel"))
85 (merge (find-commit repository "merge")))
86 (and (equal? (commit-difference master4 merge)
87 (list master4))
88 (lset= eq? (commit-difference master3 master1)
89 (list master3 master2))
90 (lset= eq? (commit-difference devel2 master1)
91 (list devel2 devel1))
92
93 ;; The merge occurred between MASTER2 and MASTER4 so here we
94 ;; expect to see all the commits from the "devel" branch in
95 ;; addition to those on "master".
96 (lset= eq? (commit-difference master4 master2)
97 (list master4 merge master3 devel1 devel2)))))))
98
99(test-end "git")