Skip to content

Commit 8fc8f8e

Browse files
committed
Add t0008-series.sh
This adds significant test coverage for `stg series`. Signed-off-by: Peter Grayson <[email protected]>
1 parent 4355940 commit 8fc8f8e

File tree

2 files changed

+140
-3
lines changed

2 files changed

+140
-3
lines changed

stgit/commands/series.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,7 @@ def func(parser, options, args):
275275
else:
276276
branch_str = ''
277277

278-
max_len = 0
279-
if len(patches) > 0:
280-
max_len = max([len(i + branch_str) for i in patches])
278+
max_len = len(branch_str) + max(len(p) for p in patches)
281279

282280
if applied:
283281
for p in applied[:-1]:

t/t0008-series.sh

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#!/bin/sh
2+
3+
test_description='Test stg series'
4+
5+
. ./test-lib.sh
6+
7+
test_expect_success 'Test uninitialized branch' '
8+
command_error stg series 2>&1 | grep -e "branch not initialized"
9+
'
10+
11+
test_expect_success 'Initialize series' '
12+
stg init &&
13+
echo "hello" > file.txt &&
14+
git add file.txt &&
15+
git commit -m "Add file.txt"
16+
'
17+
18+
test_expect_success 'Test empty series' '
19+
stg series > series.txt 2> error.txt &&
20+
test_line_count = 0 series.txt &&
21+
test_line_count = 0 error.txt
22+
'
23+
24+
test_expect_success 'Test invalid --all and --short' '
25+
command_error stg series --all --short
26+
'
27+
28+
test_expect_success 'Test invalid --all and --applied/--unapplied' '
29+
command_error stg series --all --applied &&
30+
command_error stg series --all --unapplied
31+
'
32+
33+
test_expect_success 'Test empty series count' '
34+
test "$(stg series --count)" = "0"
35+
'
36+
37+
test_expect_success 'Add patches' '
38+
echo "a" >> file.txt &&
39+
stg new -m "message 0" p0 &&
40+
stg refresh &&
41+
echo "b" >> file.txt &&
42+
stg new -m "message 1" --authname "B Author" p1 &&
43+
stg refresh &&
44+
echo "c" >> file.txt &&
45+
stg new -m "message 2" p2 &&
46+
stg refresh &&
47+
stg new -m "message 3" p3 &&
48+
stg pop p3
49+
'
50+
51+
test_expect_success 'Test default series' '
52+
stg series > series.txt 2> error.txt &&
53+
test_line_count = 4 series.txt &&
54+
test_line_count = 0 error.txt &&
55+
echo "+ p0" > expected.txt &&
56+
echo "+ p1" >> expected.txt &&
57+
echo "> p2" >> expected.txt &&
58+
echo "- p3" >> expected.txt &&
59+
test_cmp expected.txt series.txt
60+
'
61+
62+
test_expect_success 'Test showbranch' '
63+
stg series --showbranch > series.txt &&
64+
test_line_count = 4 series.txt &&
65+
echo "+ master:p0" > expected.txt &&
66+
echo "+ master:p1" >> expected.txt &&
67+
echo "> master:p2" >> expected.txt &&
68+
echo "- master:p3" >> expected.txt &&
69+
test_cmp expected.txt series.txt
70+
'
71+
72+
test_expect_success 'Test author' '
73+
stg series --author > series.txt &&
74+
test_line_count = 4 series.txt &&
75+
echo "+ p0 # A Ú Thor" > expected.txt &&
76+
echo "+ p1 # B Author" >> expected.txt &&
77+
echo "> p2 # A Ú Thor" >> expected.txt &&
78+
echo "- p3 # A Ú Thor" >> expected.txt &&
79+
test_cmp expected.txt series.txt
80+
'
81+
82+
test_expect_success 'Test description' '
83+
stg series --description > series.txt 2> error.txt &&
84+
test_line_count = 4 series.txt &&
85+
test_line_count = 0 error.txt &&
86+
echo "+ p0 # message 0" > expected.txt &&
87+
echo "+ p1 # message 1" >> expected.txt &&
88+
echo "> p2 # message 2" >> expected.txt &&
89+
echo "- p3 # message 3" >> expected.txt &&
90+
test_cmp expected.txt series.txt
91+
'
92+
93+
test_expect_success 'Test empty' '
94+
stg series --empty > series.txt &&
95+
echo " + p0" > expected.txt &&
96+
echo " + p1" >> expected.txt &&
97+
echo " > p2" >> expected.txt &&
98+
echo "0- p3" >> expected.txt &&
99+
test_cmp expected.txt series.txt
100+
'
101+
102+
test_expect_success 'Test short' '
103+
test_config stgit.shortnr 1 &&
104+
stg series --short > series.txt &&
105+
echo "+ p1" > expected.txt &&
106+
echo "> p2" >> expected.txt &&
107+
echo "- p3" >> expected.txt &&
108+
test_cmp expected.txt series.txt
109+
'
110+
111+
test_expect_success 'Test short no applied' '
112+
test_when_finished "stg goto p2" &&
113+
test_config stgit.shortnr 1 &&
114+
stg pop -a &&
115+
stg series --short > series.txt &&
116+
echo "- p0" > expected.txt &&
117+
test_cmp expected.txt series.txt
118+
'
119+
120+
test_expect_success 'Test effects' '
121+
test_config stgit.color.applied none &&
122+
stg series --applied > series.txt &&
123+
test_line_count = 3 series.txt
124+
'
125+
126+
test_expect_success 'Test missing' '
127+
stg branch --clone -- other &&
128+
test "$(stg branch)" = "other" &&
129+
stg series --missing=master > series.txt &&
130+
test_line_count = 0 series.txt &&
131+
stg pop p2 p1 &&
132+
stg delete p2 p1 &&
133+
stg series --noprefix --missing=master > series.txt &&
134+
echo "p1" > expected.txt &&
135+
echo "p2" >> expected.txt &&
136+
test_cmp expected.txt series.txt
137+
'
138+
139+
test_done

0 commit comments

Comments
 (0)