gitstats: Bugfix, created a missing test for "diff -n"
[git-stats.git] / src / t / t8100-stats.sh
blob0ea00046ee0135a52d93e8c947abb39dd90fbc17
1 #!/bin/sh
3 # Copyright (c) 2008 Sverre Rabbelier
6 test_description='stats tests (basics)
8 This test verifies that the basic stats commands work as expected.'
10 ORIG_PATH=$PWD
12 . ./test-lib.sh
15 ###########
16 # Setup
17 ###########
20 test_expect_success pre-clean '
21 rm -fr "/tmp/freshrepo" || {
22 trap - exit
23 echo >&5 "FATAL: Cannot clean the fresh repo"
24 exit 1
28 test_expect_success setup '
29 ../scripts/setupRepo.py
30 cd /tmp/freshrepo
31 test_must_fail stats.py
34 test_expect_success 'Test that the expected tree was created by setupRepo' '
35 test `git rev-parse HEAD` = "38aa44905fb99a661bfb0b675557f5aaf4934454"
39 ###########
40 # Author tests
41 ###########
45 echo "notes.txt = 3: +3 -0"
46 echo "content.txt = 23: +23 -1"
47 echo "docs/README.txt = 10: +8 -2"
48 } > expected
50 test_expect_success \
51 'Test that "author -d" filters as expected for the primary author' \
53 stats.py author -d "author@example.com" > actual
54 test_cmp expected actual
58 echo "content.txt = 2: +2 -0"
59 } > expected
61 test_expect_success \
62 'Test that "author -d" filters as expected for the secondary author' \
64 stats.py author -d "roh.tua@example.com" > actual
65 test_cmp expected actual
68 rm expected
69 touch expected
71 test_expect_failure 'Test that "author -a" aggregates as expected' '
72 `stats.py author -a` > actual
73 test_must_fail test_cmp expected actual
76 ###########
77 # Branch tests
78 ###########
81 echo "Matching branches:"
82 echo "pu"
83 } > expected
85 test_expect_success 'Test that "branch -c" filters as expected' '
86 stats.py branch -c 6f01ab2afb8471d6eee83162ddeabe179e443d59 > actual
87 test_cmp expected actual
91 echo "Matching branches:"
92 echo "maint"
93 echo "master"
94 } > expected
96 test_expect_success \
97 'Test that "branch -c" filters as expected when multiple branches match' \
99 stats.py branch -c c0e49264fd921d2a62f90556340e371e719b45cc > actual
100 test_cmp expected actual
103 test_expect_failure 'There is no test for "branch -r"' '
104 `false`
108 ###########
109 # Commit tests
110 ###########
113 echo "commit e76ad031836912c01da47ab93d3c21676763267e
114 Author: A U Thor <author@example.com>
115 Date: Thu May 26 23:30:00 2005 +0000
117 Commit 3
119 notes.txt
121 commit e8fa5fed0d1823c1e3e120579b03343aecf26ab6
122 Author: A U Thor <author@example.com>
123 Date: Thu May 26 23:30:00 2005 +0000
125 Commit 2
127 notes.txt
129 commit bd952062891010102e3632aecd0f738a35c1fca3
130 Author: A U Thor <author@example.com>
131 Date: Thu May 26 23:30:00 2005 +0000
133 Commit 1
135 notes.txt
136 " > expected
138 test_expect_success 'Test that "commit -t" filters as expected' '
139 stats.py commit -t notes.txt > actual
140 test_cmp expected actual
143 test_expect_success 'commit tests setup' '
144 cd docs
147 test_expect_success 'Test that "commit -r" works as expected' '
148 stats.py commit -r -t README.txt
151 test_expect_success \
152 'Test that "commit -r" works as expected when the file was not found' \
154 test_must_fail stats.py commit -t README.txt
157 test_expect_success 'commit tests teardown' '
158 cd ..
161 echo "commit bc6d646fd15953cdb514d14458f013a1fc05153c
162 Author: A U Thor <author@example.com>
163 Date: Thu May 26 23:30:00 2005 +0000
165 Initial commit
167 content.txt
168 " > expected
170 test_expect_success 'Test that "commit --log" filters as expected' '
171 stats.py commit --log-contains=Initial > actual
172 test_cmp expected actual
175 test_expect_success 'Test that "commit --diff" filters as expected' '
176 stats.py commit --diff-contains=Initial > actual
177 test_cmp expected actual
181 ###########
182 # Diff tests
183 ###########
186 echo "Missing the following keys:
187 ('/dev/null', 'b/notes.txt')" > expected
189 test_expect_success \
190 'Test that "diff -e" works as expected for equal diffs in different files' \
192 stats.py diff -e bd9520628910101 3c34aec51560970c > actual
193 test_cmp expected actual
196 echo "Missing the following keys:
197 ('/dev/null', 'b/test.c')" > expected
199 test_expect_success \
200 'Test that "diff -e" works as expected for equal diffs in different files' \
202 stats.py diff -e 3c34aec51560970c bd9520628910101 > actual
203 test_cmp expected actual
206 echo "Equal" > expected
208 test_expect_success 'Test that "diff -e" works as expected for equal diffs' '
209 stats.py diff -e HEAD HEAD > actual
210 test_cmp expected actual
213 test_expect_success 'Test that "diff -n -e" works as expected' '
214 stats.py diff -n -e 90511e146e24b29 38aa44905fb99a6 > actual
215 test_cmp expected actual
218 echo "Equal" > expected
220 test_expect_success 'Test that "diff -i" works as expected for reverts' '
221 stats.py diff -i -e cc2d11f96d7ec43 c2d26c33f9e8eb6 > actual
222 test_cmp expected actual
226 ###########
227 # Index tests
228 ###########
231 test_expect_success 'index test setup' '
232 echo "Some Change" >> notes.txt
233 git add notes.txt
236 echo "commit e76ad031836912c01da47ab93d3c21676763267e
237 Author: A U Thor <author@example.com>
238 Date: Thu May 26 23:30:00 2005 +0000
240 Commit 3
242 notes.txt
244 commit e8fa5fed0d1823c1e3e120579b03343aecf26ab6
245 Author: A U Thor <author@example.com>
246 Date: Thu May 26 23:30:00 2005 +0000
248 Commit 2
250 notes.txt
252 commit bd952062891010102e3632aecd0f738a35c1fca3
253 Author: A U Thor <author@example.com>
254 Date: Thu May 26 23:30:00 2005 +0000
256 Commit 1
258 notes.txt
259 " > expected
261 test_expect_success \
262 'Test that "index -t" works as expected when there are staged changes' \
264 stats.py index -t > actual
265 test_cmp expected actual
268 test_expect_success 'index test teardown' '
269 git reset --hard HEAD
272 test_expect_failure 'There is no test for "index -a"' '
273 `false`
277 ###########
278 # Teardown
279 ###########
282 test_expect_success 'Teardown' '
283 cd $ORIG_PATH
286 test_done