git.fiddlerwoaroof.com
Browse code

feat: initial tests for git objects, commit components

Ed L authored on 16/11/2020 08:13:10
Showing 7 changed files
... ...
@@ -29,6 +29,14 @@
29 29
    (cadr
30 30
     (fw.lu:v-assoc :tree (metadata object)
31 31
                    :test 'string-equal))))
32
+(defmethod component ((component (eql :author)) (object git-commit))
33
+  (second
34
+   (fw.lu:v-assoc :author (metadata object)
35
+                  :test 'string-equal)))
36
+(defmethod component ((component (eql :committer)) (object git-commit))
37
+  (second
38
+   (fw.lu:v-assoc :committer (metadata object)
39
+                  :test 'string-equal)))
32 40
 (defmethod component ((component (eql :parents)) (object git-commit))
33 41
   (coerce (remove-if-not (serapeum:op
34 42
                            (string= "parent" _))
... ...
@@ -6,6 +6,6 @@
6 6
     nil)
7 7
 
8 8
 (sb-ext:exit
9
- :code (if (5am:run-all-tests)
9
+ :code (if (5am:explain! (5am:run :fwoar.cl-git))
10 10
            0
11 11
            42))
... ...
@@ -4,7 +4,8 @@
4 4
   (:use :cl )
5 5
   (:export
6 6
    #:ensure-ref
7
-   #:repository))
7
+   #:repository
8
+   #:component))
8 9
 
9 10
 (defpackage :cl-git-user
10 11
   (:use :cl :fwoar.cl-git))
11 12
new file mode 100644
... ...
@@ -0,0 +1,64 @@
1
+(defpackage :fwoar.cl-git.git-objects
2
+  (:use :cl )
3
+  (:export ))
4
+(in-package :fwoar.cl-git.git-objects)
5
+
6
+(fiveam:def-suite :fwoar.cl-git.git-objects
7
+  :description "testing branch resolution"
8
+  :in :fwoar.cl-git)
9
+(fiveam:in-suite :fwoar.cl-git.git-objects)
10
+
11
+(fw.lu:defclass+ fake-ref ()
12
+  ((%repo :initarg :repo :reader repo)
13
+   (%hash :initarg :hash :reader hash)))
14
+(defmethod fwoar.cl-git::ref ((repo (eql :the-repo)) hash)
15
+  (fake-ref repo hash))
16
+
17
+
18
+(fiveam:def-test basic-commit ()
19
+  (let ((fwoar.cl-git::*git-repository* :the-repo)
20
+        (object (fwoar.cl-git::extract-loose-object
21
+                 nil
22
+                 (asdf:system-relative-pathname
23
+                  :cl-git
24
+                  "tests/sample-git-objects/hello-world-commit.git-obj"))))
25
+    (5am:is (typep object 'fwoar.cl-git::git-commit))
26
+    (5am:is (equal "hello, git!
27
+"
28
+                   (fwoar.cl-git:component :message object)))
29
+    (5am:is (equal ()
30
+                   (fwoar.cl-git:component :parents object)))
31
+    (5am:is (equal "L Edgley <foo@bar.com> 1605513585 -0800"
32
+                   (fwoar.cl-git:component :author object)))
33
+    (5am:is (equal "Ed L <el-github@elangley.org> 1605513585 -0800"
34
+                   (fwoar.cl-git:component :committer object)))
35
+    (5am:is (equal ()
36
+                   (fwoar.cl-git:component :parents object)))
37
+    (5am:is (equal "1da546ab4697b719efb62f11fd785d6ad3b226d2"
38
+                   (hash (fwoar.cl-git:component :tree object))))
39
+    (5am:is (equal :the-repo
40
+                   (repo (fwoar.cl-git:component :tree object))))
41
+    (5am:is (equal '(("author" "L Edgley <foo@bar.com> 1605513585 -0800")
42
+                     ("committer" "Ed L <el-github@elangley.org> 1605513585 -0800")
43
+                     ("tree" "1da546ab4697b719efb62f11fd785d6ad3b226d2"))
44
+                   (coerce (sort (copy-seq (fwoar.cl-git::metadata object))
45
+                                 'string-lessp
46
+                                 :key 'car)
47
+                           'list)))))
48
+
49
+(fiveam:def-test basic-tree ()
50
+  (let ((object (fwoar.cl-git::extract-loose-object
51
+                 nil
52
+                 (asdf:system-relative-pathname
53
+                  :cl-git
54
+                  "tests/sample-git-objects/hello-world-tree.git-obj"))))
55
+    (5am:is (typep object 'fwoar.cl-git::git-tree))
56
+    (let* ((entries (fwoar.cl-git::entries object))
57
+           (entry (progn (5am:is (= (length entries) 1))
58
+                         (car entries))))
59
+      (5am:is (equal "4b5fa63702dd96796042e92787f464e28f09f17d"
60
+                     (fwoar.cl-git:component :hash entry)))
61
+      (5am:is (equal "a"
62
+                     (fwoar.cl-git:component :name entry)))
63
+      (5am:is (equal "100644"
64
+                     (fwoar.cl-git:component :mode entry))))))
0 65
new file mode 100644
... ...
@@ -0,0 +1,3 @@
1
+xm��� E;��{5����ƥ[�&�K��ҽ��9�nt{��[-� �U��n���&1cpZ!������I��d���
2
+���c�,�hu�����J�A7��������MZ0wq��r+f{�
3
+=��Gd	s�4�ξ�w3
0 4
\ No newline at end of file
1 5
new file mode 100644
2 6
Binary files /dev/null and b/tests/sample-git-objects/hello-world-tree.git-obj differ
3 7
new file mode 100644
... ...
@@ -0,0 +1,7 @@
1
+(defpackage :fwoar.cl-git.tests
2
+  (:use :cl )
3
+  (:export ))
4
+(in-package :fwoar.cl-git.tests)
5
+
6
+(5am:def-suite :fwoar.cl-git
7
+  :description "tests of cl-git")