Use the new GIT_STATS_PRETTY_PRINT and added tags features
[git-stats.git] / src / t / t8100-stats.sh
blob710e3200c4ecf34aa724031ab5a322136dfe6899
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
14 export GIT_STATS_PRETTY_PRINT="oneline"
16 ###########
17 # Setup
18 ###########
21 test_expect_success 'pre-clean' '
22 rm -fr "/tmp/testrepo" || {
23 trap - exit
24 echo >&5 "FATAL: Cannot clean the fresh repo"
25 exit 1
29 test_expect_success 'setup' '
30 ../scripts/setupRepo.py test && \
31 cd "/tmp/testrepo" || {
32 trap - exit
33 echo >&5 "FATAL: Cannot cd into fresh repo"
34 exit 1
38 test_expect_success 'Test that stats.py is reachable' '
39 stats.py -v || {
40 trap - exit
41 echo >&5 "FATAL: stats.py not reachable"
42 exit 1
46 echo "f1fdf284733011b1172b4517b4526879059bb414" > expected
48 test_expect_success 'Test that the expected tree was created by setupRepo' '
49 git rev-parse HEAD > actual
50 test_cmp expected actual || {
51 trap - exit
52 echo >&5 "FATAL: Head revision does not match"
53 exit 1
58 ###########
59 # Author tests
60 ###########
64 echo "notes.txt = 3: +3 -0"
65 echo "content.txt = 23: +23 -1"
66 echo "docs/README.txt = 10: +8 -2"
67 } > expected
69 test_expect_success \
70 'Test that "author -d" filters as expected for the primary author' \
72 stats.py author -d "author@example.com" > actual
73 test_cmp expected actual
77 echo "content.txt = 2: +2 -0"
78 } > expected
80 test_expect_success \
81 'Test that "author -d" filters as expected for the secondary author' \
83 stats.py author -d "roh.tua@example.com" > actual
84 test_cmp expected actual
87 rm expected
88 touch expected
90 test_expect_failure 'Test that "author -a" aggregates as expected' '
91 `stats.py author -a` > actual
92 test_must_fail test_cmp expected actual
95 ###########
96 # Branch tests
97 ###########
100 echo "Matching branches:"
101 echo "pu"
102 } > expected
104 test_expect_success 'Test that "branch -c" filters as expected' '
105 stats.py branch -c v0 > actual
106 test_cmp expected actual
110 echo "Matching branches:"
111 echo "erase"
112 echo "maint"
113 echo "master"
114 } > expected
116 test_expect_success \
117 'Test that "branch -c" filters as expected when multiple branches match' \
119 stats.py branch -c v1 > actual
120 test_cmp expected actual
123 echo "junio" >> expected
125 test_expect_success 'Test that "branch -r" works as expected' '
126 stats.py branch -r -c v1 > actual
127 test_cmp expected actual
131 ###########
132 # Commit tests
133 ###########
136 echo "3b0e7ae64f1b39f7b23d789a9d472443dd00c6fb Commit 3
137 9ae22dc6a76c6ac715cc9fe6a011156ca042f480 Commit 2
138 ae9fd667fe1611e0648a2ebec65788b63bb3ce16 Commit 1" > expected
140 test_expect_success 'Test that "commit -t" filters as expected' '
141 stats.py commit -t notes.txt > actual
142 test_cmp expected actual
145 test_expect_success 'commit tests setup' '
146 cd docs
149 echo 'f1fdf284733011b1172b4517b4526879059bb414 Last commit
150 4de759680bf8bd7b51e3a0481d027ee441998542 Revert "Commit 6"
151 255ef82de488015b727e0202f0dfe8ed82443ebb Commit 6
152 4838591dcda04acd0e8882397c5c681af09c9076 Revert "Last commit"
153 4b650481338f95cd8afbc113bd15cd85d94c0c3a Last commit
154 37837a72217f8da3f056d5aa8b159412b93efd69 Commit 5
155 a03fc7e69239cc3e29c96ebf74e7d22e2d72bbef Commit 4
156 39f4923417895119ac26524c572dbd198570f054 Commit 3
157 3302051a5e010ede6cdb6d8fa66cff7e89f63b28 Commit 2
158 7bd493f55b8b0b0c59c08ca5be7c8f98fb159885 Commit 1' > expected
160 test_expect_success 'Test that "commit -r" works as expected' '
161 stats.py commit -r -t README.txt > actual
162 test_cmp expected actual
165 test_expect_success \
166 'Test that "commit -r" works as expected when the file was not found' \
168 test_must_fail stats.py commit -t README.txt
171 test_expect_success 'commit tests teardown' '
172 cd ..
175 echo "9ebfa8e247b99c0ba0198244d574734899dac987 Initial commit" > expected
177 test_expect_success 'Test that "commit --log" filters as expected' '
178 stats.py commit --log-contains=Initial > actual
179 test_cmp expected actual
182 test_expect_success 'Test that "commit --diff" filters as expected' '
183 stats.py commit --diff-contains=Initial > actual
184 test_cmp expected actual
188 ###########
189 # Diff tests
190 ###########
193 echo "Missing the following keys:
194 ('a/test.c', 'b/test.c')" > expected
196 test_expect_success \
197 'Test that "diff -e" works as expected for equal diffs in different files' \
199 stats.py diff -e v0 v4 > actual
200 test_cmp expected actual
203 echo "Missing the following keys:
204 ('a/docs/README.txt', 'b/docs/README.txt')" > expected
206 test_expect_success \
207 'Test that "diff -e" works as expected for equal diffs in different files' \
209 stats.py diff -e v4 v0 > actual
210 test_cmp expected actual
213 echo "Equal" > expected
215 test_expect_success 'Test that "diff -e" works as expected for equal diffs' '
216 stats.py diff -e HEAD HEAD > actual
217 test_cmp expected actual
220 test_expect_success 'Test that "diff -n -e" works as expected' '
221 stats.py diff -n -e v2 v3 > actual
222 test_cmp expected actual
225 echo "Equal" > expected
227 test_expect_success 'Test that "diff -i" works as expected for reverts' '
228 stats.py diff -i -e v2 v3^ > actual
229 test_cmp expected actual
233 ###########
234 # Index tests
235 ###########
238 test_expect_success 'index test setup' '
239 echo "Some Change" >> notes.txt
240 git add notes.txt
243 echo "3b0e7ae64f1b39f7b23d789a9d472443dd00c6fb Commit 3
244 9ae22dc6a76c6ac715cc9fe6a011156ca042f480 Commit 2
245 ae9fd667fe1611e0648a2ebec65788b63bb3ce16 Commit 1" > expected
247 test_expect_success \
248 'Test that "index -t" works as expected when there are staged changes' \
250 stats.py index -t > actual
251 test_cmp expected actual
254 test_expect_success 'index test teardown' '
255 git reset --hard HEAD
258 test_expect_success 'index -a test setup' '
259 git checkout erase
260 git reset --soft v5^
264 echo "No changes staged, no matching commits, or only new files added"
265 } > expected
267 test_expect_success 'Test that "index -t" without -a works as expected' '
268 stats.py index -t > actual
269 test_cmp expected actual
272 echo '28b2600cf58d478b4b937262218e363c88756b89 Deleted file docs/README.txt
273 f1fdf284733011b1172b4517b4526879059bb414 Last commit
274 4de759680bf8bd7b51e3a0481d027ee441998542 Revert "Commit 6"
275 255ef82de488015b727e0202f0dfe8ed82443ebb Commit 6
276 4838591dcda04acd0e8882397c5c681af09c9076 Revert "Last commit"
277 4b650481338f95cd8afbc113bd15cd85d94c0c3a Last commit
278 37837a72217f8da3f056d5aa8b159412b93efd69 Commit 5
279 a03fc7e69239cc3e29c96ebf74e7d22e2d72bbef Commit 4
280 39f4923417895119ac26524c572dbd198570f054 Commit 3
281 3302051a5e010ede6cdb6d8fa66cff7e89f63b28 Commit 2
282 7bd493f55b8b0b0c59c08ca5be7c8f98fb159885 Commit 1' > expected
284 test_expect_success 'Test that "index -a" works as expected' '
285 stats.py index -a -t > actual
286 test_cmp expected actual
289 test_expect_success 'index -a test teardown' '
290 git reset --hard v5
291 git checkout master
295 ###########
296 # Teardown
297 ###########
300 test_expect_success 'Teardown' '
301 cd $ORIG_PATH
304 test_done