chiark / gitweb /
New policy: Only use test_expect_failure for broken tests
[stgit] / t / t2000-sync.sh
CommitLineData
06848fab
CM
1#!/bin/sh
2#
3# Copyright (c) 2006 Catalin Marinas
4#
5
6test_description='Test the sync command.'
7
8. ./test-lib.sh
9
10test_expect_success \
11 'Initialize the StGIT repository' \
12 '
13 stg init
14 '
15
16test_expect_success \
17 'Create some patches' \
18 '
19 stg new p1 -m p1 &&
20 echo foo1 > foo1.txt &&
21 stg add foo1.txt &&
22 stg refresh &&
23 stg new p2 -m p2 &&
24 echo foo2 > foo2.txt &&
25 stg add foo2.txt &&
26 stg refresh &&
27 stg new p3 -m p3 &&
28 echo foo3 > foo3.txt &&
29 stg add foo3.txt &&
30 stg refresh &&
31 stg export &&
fea352bf
KH
32 stg pop &&
33 [ "$(echo $(stg applied))" = "p1 p2" ] &&
34 [ "$(echo $(stg unapplied))" = "p3" ]
06848fab
CM
35 '
36
37test_expect_success \
38 'Create a branch with empty patches' \
39 '
40 stg branch -c foo base &&
41 stg new p1 -m p1 &&
42 stg new p2 -m p2 &&
fea352bf
KH
43 stg new p3 -m p3 &&
44 [ "$(echo $(stg applied))" = "p1 p2 p3" ] &&
45 [ "$(echo $(stg unapplied))" = "" ]
06848fab
CM
46 '
47
48test_expect_success \
49 'Synchronise second patch with the master branch' \
50 '
6b79a09c 51 stg sync -B master p2 &&
fea352bf
KH
52 [ "$(echo $(stg applied))" = "p1 p2 p3" ] &&
53 [ "$(echo $(stg unapplied))" = "" ] &&
89f64744 54 test $(cat foo2.txt) = "foo2"
06848fab
CM
55 '
56
57test_expect_success \
58 'Synchronise the first two patches with the master branch' \
59 '
6b79a09c 60 stg sync -B master -a &&
fea352bf
KH
61 [ "$(echo $(stg applied))" = "p1 p2 p3" ] &&
62 [ "$(echo $(stg unapplied))" = "" ] &&
89f64744
KH
63 test $(cat foo1.txt) = "foo1" &&
64 test $(cat foo2.txt) = "foo2"
06848fab
CM
65 '
66
67test_expect_success \
68 'Synchronise all the patches with the exported series' \
69 '
70 stg sync -s patches-master/series -a &&
fea352bf
KH
71 [ "$(echo $(stg applied))" = "p1 p2 p3" ] &&
72 [ "$(echo $(stg unapplied))" = "" ] &&
89f64744
KH
73 test $(cat foo1.txt) = "foo1" &&
74 test $(cat foo2.txt) = "foo2" &&
75 test $(cat foo3.txt) = "foo3"
06848fab
CM
76 '
77
78test_expect_success \
79 'Modify the master patches' \
80 '
81 stg branch master &&
fea352bf
KH
82 [ "$(echo $(stg applied))" = "p1 p2" ] &&
83 [ "$(echo $(stg unapplied))" = "p3" ] &&
06848fab
CM
84 stg goto p1 &&
85 echo bar1 >> foo1.txt &&
86 stg refresh &&
87 stg goto p2 &&
88 echo bar2 > bar2.txt &&
89 stg add bar2.txt &&
90 stg refresh &&
91 stg goto p3 &&
92 echo bar3 >> foo3.txt &&
93 stg refresh &&
fea352bf
KH
94 [ "$(echo $(stg applied))" = "p1 p2 p3" ] &&
95 [ "$(echo $(stg unapplied))" = "" ] &&
06848fab
CM
96 stg export &&
97 stg branch foo
98 '
99
100test_expect_success \
101 'Synchronise second patch with the master branch' \
102 '
6b79a09c 103 stg sync -B master p2 &&
fea352bf
KH
104 [ "$(echo $(stg applied))" = "p1 p2 p3" ] &&
105 [ "$(echo $(stg unapplied))" = "" ] &&
89f64744 106 test $(cat bar2.txt) = "bar2"
06848fab
CM
107 '
108
5f594e90 109test_expect_success \
06848fab
CM
110 'Synchronise the first two patches with the master branch (to fail)' \
111 '
5f594e90 112 ! stg sync -B master -a
06848fab
CM
113 '
114
115test_expect_success \
116 'Restore the stack status after the failed sync' \
117 '
fea352bf
KH
118 [ "$(echo $(stg applied))" = "p1" ] &&
119 [ "$(echo $(stg unapplied))" = "p2 p3" ] &&
06848fab
CM
120 stg resolved -a &&
121 stg refresh &&
122 stg goto p3
fea352bf
KH
123 [ "$(echo $(stg applied))" = "p1 p2 p3" ] &&
124 [ "$(echo $(stg unapplied))" = "" ]
06848fab
CM
125 '
126
5f594e90 127test_expect_success \
06848fab
CM
128 'Synchronise the third patch with the exported series (to fail)' \
129 '
5f594e90 130 ! stg sync -s patches-master/series p3
06848fab
CM
131 '
132
133test_expect_success \
134 'Restore the stack status after the failed sync' \
135 '
fea352bf
KH
136 [ "$(echo $(stg applied))" = "p1 p2 p3" ] &&
137 [ "$(echo $(stg unapplied))" = "" ] &&
06848fab 138 stg resolved -a &&
fea352bf
KH
139 stg refresh &&
140 [ "$(echo $(stg applied))" = "p1 p2 p3" ] &&
141 [ "$(echo $(stg unapplied))" = "" ]
06848fab
CM
142 '
143
144test_done