Skip to content

Commit 0333847

Browse files
committed
test: Add tests for stg email
These basic tests are just a start, certainly not comprehensive.
1 parent de2d77e commit 0333847

File tree

3 files changed

+166
-0
lines changed

3 files changed

+166
-0
lines changed

t/t1901-email.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
#
3+
test_description="Test 'stg email'"
4+
5+
. ./test-lib.sh
6+
7+
test_expect_success 'Check that email command requires subcommand' '
8+
general_error stg email 2>err &&
9+
grep "requires a subcommand" err
10+
'
11+
12+
test_expect_success 'Check email subcommand help' '
13+
stg email help format &&
14+
stg email help send
15+
'
16+
17+
test_done

t/t1902-email-format.sh

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/sh
2+
#
3+
test_description="Test 'stg email format'"
4+
5+
. ./test-lib.sh
6+
7+
test_expect_success 'Setup StGit stack' '
8+
test_commit_bulk --message="p%s" 7 &&
9+
stg init &&
10+
stg uncommit -n 7 &&
11+
stg goto p4
12+
'
13+
14+
test_expect_success 'Format all applied patches' '
15+
stg email format -o out --all &&
16+
test_path_exists out/0001-p1.patch &&
17+
test_path_exists out/0002-p2.patch &&
18+
test_path_exists out/0003-p3.patch &&
19+
test_path_exists out/0004-p4.patch &&
20+
rm out/0001-p1.patch &&
21+
rm out/0002-p2.patch &&
22+
rm out/0003-p3.patch &&
23+
rm out/0004-p4.patch &&
24+
test_dir_is_empty out &&
25+
rmdir out
26+
'
27+
28+
test_expect_success 'Format custom patch range' '
29+
stg email format -o out p3..p5 &&
30+
test_path_exists out/0001-p3.patch &&
31+
test_path_exists out/0002-p4.patch &&
32+
test_path_exists out/0003-p5.patch &&
33+
rm out/0001-p3.patch &&
34+
rm out/0002-p4.patch &&
35+
rm out/0003-p5.patch &&
36+
test_dir_is_empty out &&
37+
rmdir out
38+
'
39+
40+
test_expect_success 'Format single patch' '
41+
stg email format -o out p7 &&
42+
test_path_exists out/0001-p7.patch &&
43+
rm out/0001-p7.patch &&
44+
test_dir_is_empty out &&
45+
rmdir out
46+
'
47+
48+
test_expect_success 'Setup another branch' '
49+
stg branch --create other &&
50+
test_commit_bulk --filename=other%s.txt --message="other%s" 5 &&
51+
stg uncommit -n 5 &&
52+
stg goto other3 &&
53+
stg branch master
54+
'
55+
56+
test_expect_success 'Format patches from other branch' '
57+
stg email format -o out --branch other --all &&
58+
test_path_exists out/0001-other1.patch &&
59+
test_path_exists out/0002-other2.patch &&
60+
test_path_exists out/0003-other3.patch &&
61+
rm out/0001-other1.patch &&
62+
rm out/0002-other2.patch &&
63+
rm out/0003-other3.patch &&
64+
test_dir_is_empty out &&
65+
rmdir out
66+
'
67+
68+
test_expect_success 'With cover letter' '
69+
stg email format -o out --all --cover-letter &&
70+
test_path_exists out/0000-cover-letter.patch &&
71+
test_path_exists out/0001-p1.patch &&
72+
test_path_exists out/0002-p2.patch &&
73+
test_path_exists out/0003-p3.patch &&
74+
test_path_exists out/0004-p4.patch &&
75+
rm out/0000-cover-letter.patch &&
76+
rm out/0001-p1.patch &&
77+
rm out/0002-p2.patch &&
78+
rm out/0003-p3.patch &&
79+
rm out/0004-p4.patch &&
80+
test_dir_is_empty out &&
81+
rmdir out
82+
'
83+
84+
test_done

t/t1903-email-send.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/sh
2+
#
3+
test_description="Test 'stg email send'"
4+
5+
. ./test-lib.sh
6+
7+
test_expect_success 'Setup StGit stack' '
8+
test_commit_bulk --message="p%s" 7 &&
9+
stg init &&
10+
stg uncommit -n 7 &&
11+
stg goto p4
12+
'
13+
14+
cat >expected <<EOF
15+
Subject: [PATCH 1/4] p1
16+
Subject: [PATCH 2/4] p2
17+
Subject: [PATCH 3/4] p3
18+
Subject: [PATCH 4/4] p4
19+
EOF
20+
test_expect_success 'Send all applied patches' '
21+
stg email send --dry-run --to [email protected] --all >out &&
22+
grep "Subject: " out > subjects &&
23+
test_cmp expected subjects
24+
'
25+
26+
cat >expected <<EOF
27+
Subject: [PATCH 1/3] p3
28+
Subject: [PATCH 2/3] p4
29+
Subject: [PATCH 3/3] p5
30+
EOF
31+
test_expect_success 'Send custom patch range' '
32+
stg email send --dry-run --to [email protected] p3..p5 >out &&
33+
grep "Subject: " out > subjects &&
34+
test_cmp expected subjects
35+
'
36+
37+
cat >expected <<EOF
38+
Subject: [PATCH] p7
39+
EOF
40+
test_expect_success 'Send single patch' '
41+
stg email send --dry-run --to [email protected] p7 >out &&
42+
grep "Subject: " out > subjects &&
43+
test_cmp expected subjects
44+
'
45+
46+
test_expect_success 'Setup another branch' '
47+
stg branch --create other &&
48+
test_commit_bulk --filename=other%s.txt --message="other%s" 5 &&
49+
stg uncommit -n 5 &&
50+
stg goto other3 &&
51+
stg branch master
52+
'
53+
54+
cat >expected <<EOF
55+
Subject: [PATCH 1/3] other1
56+
Subject: [PATCH 2/3] other2
57+
Subject: [PATCH 3/3] other3
58+
EOF
59+
test_expect_success 'Send patches from other branch' '
60+
stg email send --dry-run --to [email protected] --branch other --all >out &&
61+
grep "Subject: " out > subjects &&
62+
test_cmp expected subjects
63+
'
64+
65+
test_done

0 commit comments

Comments
 (0)