gitstats: Licensed GitStats under the Apache License, 2.0
[git-stats.git] / src / t / t8100-stats.sh
blobdf9ef68e3e5a026c55c115388577caa62d72c010
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
11 PATH=$ORIG_PATH/..:$PATH
13 . ./test-lib.sh
15 export PATH GIT_STATS_PRETTY_PRINT="oneline"
17 ###########
18 # Setup
19 ###########
21 test_expect_success 'extract test repo path' '
22 TEST_REPO_PATH=$(python ../scripts/setupRepo.py test path) || {
23 trap - exit
24 echo >&5 "FATAL: Cannot extract test repo path"
25 exit 1
29 test_expect_success 'pre-clean' '
30 rm -fr "$TEST_REPO_PATH" || {
31 trap - exit
32 echo >&5 "FATAL: Cannot clean the fresh repo"
33 exit 1
37 test_expect_success 'setup' '
38 python ../scripts/setupRepo.py test path "$TEST_REPO_PATH" && \
39 cd "$TEST_REPO_PATH" || {
40 trap - exit
41 echo >&5 "FATAL: Cannot cd into fresh repo"
42 exit 1
46 test_expect_success 'Test that stats.py is reachable' '
47 stats.py -v || {
48 trap - exit
49 echo >&5 "FATAL: stats.py not reachable"
50 exit 1
54 echo "f1fdf284733011b1172b4517b4526879059bb414" > expected
56 test_expect_success 'Test that the expected tree was created by setupRepo' '
57 git rev-parse HEAD > actual
58 test_cmp expected actual || {
59 trap - exit
60 echo >&5 "FATAL: Head revision does not match"
61 exit 1
66 ###########
67 # Author tests
68 ###########
70 echo " 23: 23+ 1- 22~ = content.txt
71 10: 8+ 2- 6~ = docs/README.txt
72 3: 3+ 0- 3~ = notes.txt" > expected
74 test_expect_success \
75 'Test that "author -d" filters as expected for the primary author' \
77 stats.py author -d "author@example.com" > actual
78 test_cmp expected actual
81 echo " 2: 2+ 0- 2~ = content.txt" > expected
83 test_expect_success \
84 'Test that "author -d" filters as expected for the secondary author' \
86 stats.py author -d "roh.tua@example.com" > actual
87 test_cmp expected actual
90 echo "author@example.com:
91 23: 23+ 1- 22~ = content.txt
92 10: 8+ 2- 6~ = docs/README.txt
93 3: 3+ 0- 3~ = notes.txt
95 roh.tua@example.com:
96 2: 2+ 0- 2~ = content.txt
97 " > expected
99 test_expect_success \
100 'Test that "author -e" shows stats for all authors' \
102 stats.py author -e > actual
103 test_cmp expected actual
106 echo "author@example.com: 24
107 roh.tua@example.com: 2" > expected
109 test_expect_success 'Test that "author -f" aggregates as expected' '
110 stats.py author --file=content.txt > actual
111 test_cmp expected actual
114 echo " 25: 25+ 1- 24~ = content.txt
115 10: 8+ 2- 6~ = docs/README.txt
116 3: 3+ 0- 3~ = notes.txt" > expected
118 test_expect_success 'Test that "author -a" aggregates as expected' '
119 stats.py author -a > actual
120 test_cmp expected actual
123 ###########
124 # Branch tests
125 ###########
128 echo "Matching branches:"
129 echo "pu"
130 } > expected
132 test_expect_success 'Test that "branch -c" filters as expected' '
133 stats.py branch -c v0 > actual
134 test_cmp expected actual
138 echo "Matching branches:"
139 echo "erase"
140 echo "maint"
141 echo "master"
142 } > expected
144 test_expect_success \
145 'Test that "branch -c" filters as expected when multiple branches match' \
147 stats.py branch -c v1 > actual
148 test_cmp expected actual
151 echo "junio" >> expected
153 test_expect_success 'Test that "branch -r" works as expected' '
154 stats.py branch -r -c v1 > actual
155 test_cmp expected actual
159 ###########
160 # Commit tests
161 ###########
164 echo "3b0e7ae64f1b39f7b23d789a9d472443dd00c6fb Commit 3
165 9ae22dc6a76c6ac715cc9fe6a011156ca042f480 Commit 2
166 ae9fd667fe1611e0648a2ebec65788b63bb3ce16 Commit 1" > expected
168 test_expect_success 'Test that "commit -t" filters as expected' '
169 stats.py commit -t notes.txt > actual
170 test_cmp expected actual
173 test_expect_success 'commit tests setup' '
174 cd docs
177 echo 'f1fdf284733011b1172b4517b4526879059bb414 Last commit
178 4de759680bf8bd7b51e3a0481d027ee441998542 Revert "Commit 6"
179 255ef82de488015b727e0202f0dfe8ed82443ebb Commit 6
180 4838591dcda04acd0e8882397c5c681af09c9076 Revert "Last commit"
181 4b650481338f95cd8afbc113bd15cd85d94c0c3a Last commit
182 37837a72217f8da3f056d5aa8b159412b93efd69 Commit 5
183 a03fc7e69239cc3e29c96ebf74e7d22e2d72bbef Commit 4
184 39f4923417895119ac26524c572dbd198570f054 Commit 3
185 3302051a5e010ede6cdb6d8fa66cff7e89f63b28 Commit 2
186 7bd493f55b8b0b0c59c08ca5be7c8f98fb159885 Commit 1' > expected
188 test_expect_success 'Test that "commit -r" works as expected' '
189 stats.py commit -r -t README.txt > actual
190 test_cmp expected actual
193 test_expect_success \
194 'Test that "commit -r" works as expected when the file was not found' \
196 test_must_fail stats.py commit -t README.txt
199 test_expect_success 'commit tests teardown' '
200 cd ..
203 echo "9ebfa8e247b99c0ba0198244d574734899dac987 Initial commit" > expected
205 test_expect_success 'Test that "commit --log" filters as expected' '
206 stats.py commit --log-contains=Initial > actual
207 test_cmp expected actual
210 test_expect_success 'Test that "commit --diff" filters as expected' '
211 stats.py commit --diff-contains=Initial > actual
212 test_cmp expected actual
216 ###########
217 # Diff tests
218 ###########
221 echo "Missing the following keys:
222 ('a/test.c', 'b/test.c')" > expected
224 test_expect_success \
225 'Test that "diff -e" works as expected for equal diffs in different files' \
227 stats.py diff -e v0 v4 > actual
228 test_cmp expected actual
231 echo "Missing the following keys:
232 ('a/docs/README.txt', 'b/docs/README.txt')" > expected
234 test_expect_success \
235 'Test that "diff -e" works as expected for equal diffs in different files' \
237 stats.py diff -e v4 v0 > actual
238 test_cmp expected actual
241 echo "Equal" > expected
243 test_expect_success 'Test that "diff -e" works as expected for equal diffs' '
244 stats.py diff -e HEAD HEAD > actual
245 test_cmp expected actual
248 test_expect_success 'Test that "diff -n -e" works as expected' '
249 stats.py diff -n -e v2 v3 > actual
250 test_cmp expected actual
253 echo "Equal" > expected
255 test_expect_success 'Test that "diff -i" works as expected for reverts' '
256 stats.py diff -i -e v2 v3^ > actual
257 test_cmp expected actual
261 ###########
262 # Index tests
263 ###########
266 test_expect_success 'index test setup' '
267 echo "Some Change" >> notes.txt
268 git add notes.txt
271 echo "3b0e7ae64f1b39f7b23d789a9d472443dd00c6fb Commit 3
272 9ae22dc6a76c6ac715cc9fe6a011156ca042f480 Commit 2
273 ae9fd667fe1611e0648a2ebec65788b63bb3ce16 Commit 1" > expected
275 test_expect_success \
276 'Test that "index -t" works as expected when there are staged changes' \
278 stats.py index -t > actual
279 test_cmp expected actual
282 test_expect_success 'index test teardown' '
283 git reset --hard HEAD
286 test_expect_success 'index -a test setup' '
287 git checkout erase
288 git reset --soft v5^
292 echo "No changes staged, no matching commits, or only new files added"
293 } > expected
295 test_expect_success 'Test that "index -t" without -a works as expected' '
296 stats.py index -t > actual
297 test_cmp expected actual
300 echo '28b2600cf58d478b4b937262218e363c88756b89 Deleted file docs/README.txt
301 f1fdf284733011b1172b4517b4526879059bb414 Last commit
302 4de759680bf8bd7b51e3a0481d027ee441998542 Revert "Commit 6"
303 255ef82de488015b727e0202f0dfe8ed82443ebb Commit 6
304 4838591dcda04acd0e8882397c5c681af09c9076 Revert "Last commit"
305 4b650481338f95cd8afbc113bd15cd85d94c0c3a Last commit
306 37837a72217f8da3f056d5aa8b159412b93efd69 Commit 5
307 a03fc7e69239cc3e29c96ebf74e7d22e2d72bbef Commit 4
308 39f4923417895119ac26524c572dbd198570f054 Commit 3
309 3302051a5e010ede6cdb6d8fa66cff7e89f63b28 Commit 2
310 7bd493f55b8b0b0c59c08ca5be7c8f98fb159885 Commit 1' > expected
312 test_expect_success 'Test that "index -a" works as expected' '
313 stats.py index -a -t > actual
314 test_cmp expected actual
317 test_expect_success 'index -a test teardown' '
318 git reset --hard v5
319 git checkout master
323 ###########
324 # Teardown
325 ###########
328 test_expect_success 'Teardown' '
329 cd $ORIG_PATH
332 test_done