|
1
|
# |
|
2
|
# Copyright (c) 2013 D. Richard Hipp |
|
3
|
# |
|
4
|
# This program is free software; you can redistribute it and/or |
|
5
|
# modify it under the terms of the Simplified BSD License (also |
|
6
|
# known as the "2-Clause License" or "FreeBSD License".) |
|
7
|
# |
|
8
|
# This program is distributed in the hope that it will be useful, |
|
9
|
# but without any warranty; without even the implied warranty of |
|
10
|
# merchantability or fitness for a particular purpose. |
|
11
|
# |
|
12
|
# Author contact information: |
|
13
|
# [email protected] |
|
14
|
# http://www.hwaci.com/drh/ |
|
15
|
# |
|
16
|
############################################################################ |
|
17
|
# |
|
18
|
# |
|
19
|
# Tests for 'fossil stash' |
|
20
|
# |
|
21
|
# |
|
22
|
|
|
23
|
proc knownBug {t tests} { |
|
24
|
return [expr {$t in $tests ? "knownBug" : ""}] |
|
25
|
} |
|
26
|
|
|
27
|
# Test 'fossil stash' against expected results from 'fossil changes' and |
|
28
|
# 'fossil addremove -n', as well as by verifying the existence of files |
|
29
|
# on the file system. Unlike the similar function found in |
|
30
|
# revert.test, 'fossil undo' is not called after each test because |
|
31
|
# many stash operations aren't undoable, and because further testing |
|
32
|
# of the stash content is more likely to be useful. |
|
33
|
# |
|
34
|
# The extra list "-knownbugs" is a list of areas that should be |
|
35
|
# marked as "knownBug" to the inner call to test. Known areas are: |
|
36
|
# -code The exit status of fossil stash |
|
37
|
# -result The result string didn't match |
|
38
|
# -changes The changed file set didn't match |
|
39
|
# -addremove The addremove result set didn't match |
|
40
|
# -exists One or more listed files don't exist |
|
41
|
# -notexists One or more listed files do exist |
|
42
|
# |
|
43
|
# Also, if the exit status of fossil stash does not match |
|
44
|
# expectations, the rest of the areas are not tested. |
|
45
|
proc test_result_state {testid cmdArgs expectedOutput args} { |
|
46
|
global RESULT |
|
47
|
set passed 1 |
|
48
|
|
|
49
|
set args [dict merge { |
|
50
|
-changes {} -addremove {} -exists {} -notexists {} -knownbugs {} |
|
51
|
} $args] |
|
52
|
|
|
53
|
set knownbugs [dict get $args "-knownbugs"] |
|
54
|
set result $::RESULT |
|
55
|
set code $::CODE |
|
56
|
if {[lindex $cmdArgs end] eq "-expectError"} { |
|
57
|
test $testid-CODE {$code} [knownBug "-code" $knownbugs] |
|
58
|
if {!$code} { |
|
59
|
return |
|
60
|
} |
|
61
|
} else { |
|
62
|
test $testid-CODE {!$code} [knownBug "-code" $knownbugs] |
|
63
|
if {$code} { |
|
64
|
return |
|
65
|
} |
|
66
|
} |
|
67
|
test_status_list $testid $result $expectedOutput [knownBug "-result" $knownbugs] |
|
68
|
|
|
69
|
set statusListTests [list -changes changes -addremove {addremove -n}] |
|
70
|
foreach {key fossilArgs} $statusListTests { |
|
71
|
set expected [dict get $args $key] |
|
72
|
set result [fossil {*}$fossilArgs] |
|
73
|
test_status_list $testid$key $result $expected [knownBug $key $knownbugs] |
|
74
|
} |
|
75
|
|
|
76
|
set fileExistsTests [list -exists 1 does -notexists 0 should] |
|
77
|
foreach {key expected verb} $fileExistsTests { |
|
78
|
foreach path [dict get $args $key] { |
|
79
|
if {[file exists $path] != $expected} { |
|
80
|
set passed 0 |
|
81
|
protOut " Failure: File $verb not exist: $path" |
|
82
|
} |
|
83
|
} |
|
84
|
test $testid$key $passed [knownBug $key $knownbugs] |
|
85
|
} |
|
86
|
|
|
87
|
#fossil undo |
|
88
|
} |
|
89
|
|
|
90
|
proc stash-test {testid stashArgs expectedStashOutput args} { |
|
91
|
fossil stash {*}$stashArgs |
|
92
|
return [test_result_state stash-$testid "stash $stashArgs" $expectedStashOutput {*}$args] |
|
93
|
} |
|
94
|
|
|
95
|
require_no_open_checkout |
|
96
|
test_setup |
|
97
|
|
|
98
|
# Prepare first commit |
|
99
|
# |
|
100
|
write_file f1 "f1" |
|
101
|
write_file f2 "f2" |
|
102
|
write_file f3 "f3" |
|
103
|
fossil add f1 f2 f3 |
|
104
|
fossil commit -m "c1" --tag c1 |
|
105
|
|
|
106
|
######## |
|
107
|
# fossil stash |
|
108
|
# fossil stash save ?-m|--comment COMMENT? ?FILES...? |
|
109
|
|
|
110
|
# Make simple changes to stash |
|
111
|
# Add f0, remove f1, edit f2, rename f3 to f3n |
|
112
|
write_file f0 "f0" |
|
113
|
fossil add f0 |
|
114
|
file delete f1 |
|
115
|
fossil rm f1 |
|
116
|
write_file f2 "f2.1" |
|
117
|
file rename -force f3 f3n |
|
118
|
fossil mv f3 f3n |
|
119
|
|
|
120
|
# Stash these changes and confirm |
|
121
|
stash-test 1 {save -m "stash 1"} { |
|
122
|
UNMANAGE f0 |
|
123
|
REVERT f1 |
|
124
|
REVERT f2 |
|
125
|
REVERT f3 |
|
126
|
DELETE f3n |
|
127
|
} -addremove { |
|
128
|
ADDED f0 |
|
129
|
} -exists {f0 f1 f2 f3} -notexists {f3n} |
|
130
|
|
|
131
|
######## |
|
132
|
# fossil stash list|ls ?-v|--verbose? ?-W|--width <num>? |
|
133
|
|
|
134
|
# Confirm there is a stash saved |
|
135
|
fossil stash list |
|
136
|
#protOut "{[normalize_result]}" |
|
137
|
#{1: [21bc64cff8c702] on 2016-02-10 19:48:44 |
|
138
|
# stash 1} |
|
139
|
test stash-1-list-1 {[regexp {^1: \[[0-9a-z]+\] on } [first_data_line]]} |
|
140
|
test stash-1-list-2 {[regexp {^\s+stash 1\s*$} [second_data_line]]} |
|
141
|
|
|
142
|
set diff_stash_1 {DELETE f1 |
|
143
|
Index: f1 |
|
144
|
================================================================== |
|
145
|
--- f1 |
|
146
|
+++ /dev/null |
|
147
|
@@ -1,1 +0,0 @@ |
|
148
|
-f1 |
|
149
|
|
|
150
|
CHANGED f2 |
|
151
|
--- f2 |
|
152
|
+++ f2 |
|
153
|
@@ -1,1 +1,1 @@ |
|
154
|
-f2 |
|
155
|
+f2.1 |
|
156
|
|
|
157
|
CHANGED f3n |
|
158
|
--- f3n |
|
159
|
+++ f3n |
|
160
|
|
|
161
|
ADDED f0 |
|
162
|
Index: f0 |
|
163
|
================================================================== |
|
164
|
--- /dev/null |
|
165
|
+++ f0 |
|
166
|
@@ -0,0 +1,1 @@ |
|
167
|
+f0} |
|
168
|
|
|
169
|
######## |
|
170
|
# fossil stash show|cat ?STASHID? ?DIFF-OPTIONS? |
|
171
|
# fossil stash [g]diff ?STASHID? ?DIFF-OPTIONS? |
|
172
|
|
|
173
|
#fossil stash show |
|
174
|
#test stash-1-show {[normalize_result] eq $diff_stash_1} |
|
175
|
#fossil stash diff |
|
176
|
#test stash-1-diff {[normalize_result] eq $diff_stash_1} knownBug |
|
177
|
|
|
178
|
######## |
|
179
|
# fossil stash pop |
|
180
|
|
|
181
|
stash-test 2 pop { |
|
182
|
DELETE f1 |
|
183
|
UPDATE f2 |
|
184
|
UPDATE f3n |
|
185
|
ADDED f0 |
|
186
|
} -changes { |
|
187
|
ADDED f0 |
|
188
|
MISSING f1 |
|
189
|
EDITED f2 |
|
190
|
RENAMED f3 -> f3n |
|
191
|
} -addremove { |
|
192
|
DELETED f1 |
|
193
|
} -exists {f0 f2 f3n} -notexists {f1 f3} |
|
194
|
|
|
195
|
# Confirm there is no longer a stash saved |
|
196
|
fossil stash list |
|
197
|
test stash-2-list {[first_data_line] eq "empty stash"} |
|
198
|
|
|
199
|
|
|
200
|
# Test stashed mv without touching the file system |
|
201
|
# Issue reported by email to fossil-users |
|
202
|
# from Warren Young, dated Tue, 9 Feb 2016 01:22:54 -0700 |
|
203
|
# with checkin [b8c7af5bd9] plus a local patch on CentOS 5 |
|
204
|
# 64 bit intel, 8-byte pointer, 4-byte integer |
|
205
|
# Stashed renamed file said: |
|
206
|
# fossil: ./src/delta.c:231: checksum: Assertion '...' failed. |
|
207
|
# Should be triggered by this stash-WY-1 test. |
|
208
|
fossil checkout --force c1 |
|
209
|
fossil clean |
|
210
|
fossil mv --soft f1 f1new |
|
211
|
#stash-test WY-1 {-expectError save -m "Reported 2016-02-09"} { |
|
212
|
# REVERT f1 |
|
213
|
# DELETE f1new |
|
214
|
#} -changes { |
|
215
|
#} -addremove { |
|
216
|
#} -exists {f1 f2 f3} -notexists {f1new} -knownbugs {-code -result} |
|
217
|
# TODO: add tests that verify the saved stash is sensible. Possibly |
|
218
|
# by applying it and checking results. But until the SQLITE_CONSTRAINT |
|
219
|
# error is fixed, there is nothing stashed to test. |
|
220
|
|
|
221
|
|
|
222
|
|
|
223
|
# Test stashing the combination of a renamed file and an added file that |
|
224
|
# uses the renamed file's original filename. I expect to see the same |
|
225
|
# behavior as fossil revert: calmly back out both the rename and the |
|
226
|
# add, and presumably stash the content of the added file before it |
|
227
|
# is replaced by the revert. |
|
228
|
# |
|
229
|
test_setup |
|
230
|
write_file f1 "f1" |
|
231
|
fossil add f1 |
|
232
|
fossil commit -m "add f1" |
|
233
|
|
|
234
|
write_file f1n "f1n" |
|
235
|
fossil mv f1 f1n |
|
236
|
write_file f1 "f1b" |
|
237
|
fossil add f1 |
|
238
|
|
|
239
|
stash-test 2-1 {save -m "f1b"} { |
|
240
|
REVERT f1 |
|
241
|
DELETE f1n |
|
242
|
} -exists {f1} -notexists {f1n} -knownbugs {-code -result} |
|
243
|
# TODO: add tests that verify the saved stash is sensible. Possibly |
|
244
|
# by applying it and checking results. But until the MISSING file |
|
245
|
# error is fixed, there is nothing stashed to test. |
|
246
|
|
|
247
|
|
|
248
|
# Test stashing a newly added (but never committed) file. As with |
|
249
|
# fossil revert, fossil stash save unmanages the new file, but |
|
250
|
# leaves the copy present on disk. This is undocumented, but |
|
251
|
# probably sensible. |
|
252
|
test_setup |
|
253
|
write_file f1 "f1" |
|
254
|
write_file f2 "f2" |
|
255
|
fossil add f1 f2 |
|
256
|
fossil commit -m "baseline" |
|
257
|
|
|
258
|
write_file f3 "f3" |
|
259
|
fossil add f3 |
|
260
|
stash-test 3-1 {save -m f3} { |
|
261
|
UNMANAGE f3 |
|
262
|
} -addremove { |
|
263
|
ADDED f3 |
|
264
|
} -exists {f1 f2 f3} -notexists {} |
|
265
|
#fossil status |
|
266
|
fossil stash show |
|
267
|
test stash-3-1-show {[normalize_result] eq {ADDED f3 |
|
268
|
Index: f3 |
|
269
|
================================================================== |
|
270
|
--- /dev/null |
|
271
|
+++ f3 |
|
272
|
@@ -0,0 +1,1 @@ |
|
273
|
+f3}} |
|
274
|
stash-test 3-1-pop {pop} { |
|
275
|
ADDED f3 |
|
276
|
} -changes { |
|
277
|
ADDED f3 |
|
278
|
} -addremove { |
|
279
|
} -exists {f1 f2 f3} -notexists {} |
|
280
|
fossil status |
|
281
|
|
|
282
|
|
|
283
|
# Test stashing a rename of one file with at least one file |
|
284
|
# unchanged. This should stash (and revert) just the rename |
|
285
|
# operation. Instead it also stores and touches the unchanged file. |
|
286
|
test_setup |
|
287
|
write_file f1 "f1" |
|
288
|
write_file f2 "f2" |
|
289
|
fossil add f1 f2 |
|
290
|
fossil commit -m "baseline" |
|
291
|
|
|
292
|
fossil mv --hard f2 f2n |
|
293
|
test_result_state stash-3-2-mv "mv --hard f2 f2n" [concat { |
|
294
|
RENAME f2 f2n |
|
295
|
MOVED_FILE} [file normalize f2] { |
|
296
|
}] -changes { |
|
297
|
RENAMED f2 -> f2n |
|
298
|
} -addremove { |
|
299
|
} -exists {f1 f2n} -notexists {f2} |
|
300
|
|
|
301
|
fossil stash save -m f2n |
|
302
|
#stash-test 3-2 {save -m f2n} { |
|
303
|
# REVERT f2 |
|
304
|
# DELETE f2n |
|
305
|
#} -exists {f1 f2} -notexists {f2n} -knownbugs {-result} |
|
306
|
fossil stash show |
|
307
|
#test stash-3-2-show-1 {![regexp {\sf1} $RESULT]} knownBug |
|
308
|
test stash-3-2-show-2 {[regexp {\sf2n} $RESULT]} |
|
309
|
stash-test 3-2-pop {pop} { |
|
310
|
UPDATE f1 |
|
311
|
UPDATE f2n |
|
312
|
} -changes { |
|
313
|
RENAMED f2 -> f2n |
|
314
|
} -addremove { |
|
315
|
} -exists {f1 f2n} -notexists {f2} |
|
316
|
|
|
317
|
|
|
318
|
|
|
319
|
######## |
|
320
|
# fossil stash snapshot ?-m|--comment COMMENT? ?FILES...? |
|
321
|
|
|
322
|
test_setup |
|
323
|
write_file f1 "f1" |
|
324
|
write_file f2 "f2" |
|
325
|
write_file f3 "f3" |
|
326
|
fossil add f1 f2 f3 |
|
327
|
fossil commit -m "c1" --tag c1 |
|
328
|
|
|
329
|
# Make simple changes and snapshot them |
|
330
|
# Add f0, edit f2 |
|
331
|
write_file f0 "f0" |
|
332
|
fossil add f0 |
|
333
|
write_file f2 "f2.1" |
|
334
|
|
|
335
|
# Snapshot these changes and confirm |
|
336
|
stash-test 4-1 {snapshot -m "snap 1"} { |
|
337
|
} -changes { |
|
338
|
ADDED f0 |
|
339
|
EDITED f2 |
|
340
|
} -addremove { |
|
341
|
} -exists {f0 f1 f2 f3} -notexists {} |
|
342
|
fossil stash diff |
|
343
|
test stash-4-1-diff-CODE {!$::CODE} |
|
344
|
fossil stash show |
|
345
|
test stash-4-1-show-1 {[regexp {CHANGED f2} $RESULT]} |
|
346
|
test stash-4-1-show-2 {[regexp {ADDED f0} $RESULT]} |
|
347
|
|
|
348
|
# remove f1 and snapshot |
|
349
|
file delete f1 |
|
350
|
fossil rm f1 |
|
351
|
stash-test 4-2 {snapshot -m "snap 2"} { |
|
352
|
} -changes { |
|
353
|
ADDED f0 |
|
354
|
DELETED f1 |
|
355
|
EDITED f2 |
|
356
|
} -addremove { |
|
357
|
} -exists {f0 f2 f3} -notexists {f1} |
|
358
|
fossil stash diff |
|
359
|
test stash-4-2-diff-CODE {!$::CODE} knownBug |
|
360
|
fossil stash show |
|
361
|
test stash-4-2-show-1 {[regexp {DELETE f1} $RESULT]} |
|
362
|
test stash-4-2-show-2 {[regexp {CHANGED f2} $RESULT]} |
|
363
|
test stash-4-2-show-3 {[regexp {ADDED f0} $RESULT]} |
|
364
|
|
|
365
|
|
|
366
|
# rename f3 to f3n and snapshot |
|
367
|
file rename -force f3 f3n |
|
368
|
fossil mv f3 f3n |
|
369
|
stash-test 4-3 {snapshot -m "snap 3"} { |
|
370
|
} -changes { |
|
371
|
ADDED f0 |
|
372
|
DELETED f1 |
|
373
|
EDITED f2 |
|
374
|
RENAMED f3 -> f3n |
|
375
|
} -addremove { |
|
376
|
} -exists {f0 f2 f3n} -notexists {f1 f3} |
|
377
|
fossil stash diff |
|
378
|
test stash-4-3-diff-CODE {!$::CODE} knownBug |
|
379
|
fossil stash show |
|
380
|
test stash-4-3-show-1 {[regexp {DELETE f1} $RESULT]} |
|
381
|
test stash-4-3-show-2 {[regexp {CHANGED f2} $RESULT]} |
|
382
|
test stash-4-3-show-2 {[regexp {CHANGED f3n} $RESULT]} |
|
383
|
test stash-4-3-show-3 {[regexp {ADDED f0} $RESULT]} |
|
384
|
|
|
385
|
# fossil stash apply ?STASHID? |
|
386
|
# fossil stash goto ?STASHID? |
|
387
|
# fossil stash rm|drop ?STASHID? ?-a|--all? |
|
388
|
|
|
389
|
#fossil checkout --force c1 |
|
390
|
#fossil clean |
|
391
|
|
|
392
|
############################################################################### |
|
393
|
|
|
394
|
test_cleanup |
|
395
|
|