Fossil SCM
Additional tests for the rest of the arguments.
Commit
ac3ccc4e72f17cc5e94bc01387373eaf4f269d0d
Parent
e4b5c2c2271e994…
1 file changed
+129
-4
+129
-4
| --- test/amend.test | ||
| +++ test/amend.test | ||
| @@ -1,23 +1,40 @@ | ||
| 1 | 1 | # |
| 2 | 2 | # Tests for the "amend" command. |
| 3 | 3 | # |
| 4 | + | |
| 5 | +proc short_uuid {uuid {len 10}} { | |
| 6 | + string range $uuid 0 $len-1 | |
| 7 | +} | |
| 8 | + | |
| 9 | +proc artifact_from_timeline {res var} { | |
| 10 | + upvar $var artid | |
| 11 | + regexp {(?x)[0-9]{2}(?::[0-9]{2}){2}\s+\[([0-9a-f]+)]} $res m artid | |
| 12 | +} | |
| 13 | + | |
| 14 | +proc manifest_comment {comment} { | |
| 15 | + string map [list { } {\\s} \n {\\n} \r {\\r}] $comment | |
| 16 | +} | |
| 17 | + | |
| 18 | +proc uuid_from_commit {res var} { | |
| 19 | + upvar $var UUID | |
| 20 | + regexp {^New_Version: ([0-9a-f]{40})$} $res m UUID | |
| 21 | +} | |
| 4 | 22 | |
| 5 | 23 | # Make sure we are not in an open repository and initialize new repository |
| 6 | 24 | repo_init |
| 7 | 25 | |
| 8 | 26 | ######################################## |
| 9 | 27 | # Setup: Add file and commit # |
| 10 | 28 | ######################################## |
| 11 | 29 | write_file datafile "data" |
| 12 | -write_file commitmsg "committed" | |
| 13 | 30 | |
| 14 | 31 | fossil add datafile |
| 15 | 32 | fossil commit -m "c1" |
| 16 | 33 | write_file datafile "data.file" |
| 17 | 34 | fossil commit -m "c2" |
| 18 | -if {![regexp {^New_Version: ([0-9a-f]{40})$} $RESULT m UUID]} { | |
| 35 | +if {![uuid_from_commit $RESULT UUID]} { | |
| 19 | 36 | test amend-setup-failure false |
| 20 | 37 | return |
| 21 | 38 | } |
| 22 | 39 | |
| 23 | 40 | ######################################## |
| @@ -61,12 +78,11 @@ | ||
| 61 | 78 | test amend-bgcolor-$tc.2 {[string first "bgcolor=$result" $RESULT] != -1} |
| 62 | 79 | fossil timeline -n 1 |
| 63 | 80 | test amend-bgcolor-$tc.3 { |
| 64 | 81 | [string match "*Change*background*color*to*\"$result\"*" $RESULT] |
| 65 | 82 | } |
| 66 | - if {[regexp {(?x)[0-9]{2}(?::[0-9]{2}){2}\s+\[([0-9a-f]+)]} $RESULT m artid]}\ | |
| 67 | - { | |
| 83 | + if {[artifact_from_timeline $RESULT artid]} { | |
| 68 | 84 | fossil artifact $artid |
| 69 | 85 | test amend-bgcolor-$tc.4 { |
| 70 | 86 | [string match "*T +bgcolor $UUID $result*" $RESULT] |
| 71 | 87 | } |
| 72 | 88 | } else { |
| @@ -178,5 +194,114 @@ | ||
| 178 | 194 | } |
| 179 | 195 | write_file datafile "changed" |
| 180 | 196 | fossil commit -m "should fail" |
| 181 | 197 | test amend-close-3.4 {[string first "closed leaf" $RESULT] != -1} |
| 182 | 198 | } |
| 199 | + | |
| 200 | +######################################## | |
| 201 | +# Test: -tag/-cancel # | |
| 202 | +######################################## | |
| 203 | +set tagtests { | |
| 204 | + tagged tagged | |
| 205 | + {000000 lower Upper alpha 0alpha} {000000 0alpha Upper alpha lower} | |
| 206 | +} | |
| 207 | +set tc 0 | |
| 208 | +foreach {tagt result} $tagtests { | |
| 209 | + incr tc | |
| 210 | + set tags {} | |
| 211 | + set cancels {} | |
| 212 | + set t1exp "" | |
| 213 | + set t2exp "*" | |
| 214 | + set t3exp "*" | |
| 215 | + set t5exp "*" | |
| 216 | + foreach tag $tagt { | |
| 217 | + lappend tags -tag $tag | |
| 218 | + lappend cancels -cancel $tag | |
| 219 | + } | |
| 220 | + foreach res $result { | |
| 221 | + append t1exp ", $res" | |
| 222 | + append t2exp "sym-$res*" | |
| 223 | + append t3exp "Add*tag*\"$res\".*" | |
| 224 | + append t5exp "Cancel*tag*\"$res\".*" | |
| 225 | + } | |
| 226 | + eval fossil amend $UUID $tags | |
| 227 | + test amend-tag-$tc.1 {[string match "*uuid:*$UUID*tags:*$t1exp*" $RESULT]} | |
| 228 | + fossil tag ls --raw $UUID | |
| 229 | + test amend-tag-$tc.2 {[string match $t2exp $RESULT]} | |
| 230 | + fossil timeline -n 1 | |
| 231 | + test amend-tag-$tc.3 {[string match $t3exp $RESULT]} | |
| 232 | + eval fossil amend $UUID $cancels | |
| 233 | + test amend-tag-$tc.4 {![string match "*tags:*$t1exp*" $RESULT]} | |
| 234 | + fossil timeline -n 1 | |
| 235 | + test amend-tag-$tc.5 {[string match $t5exp $RESULT]} | |
| 236 | +} | |
| 237 | + | |
| 238 | +######################################## | |
| 239 | +# Test: -comment # | |
| 240 | +######################################## | |
| 241 | +proc prep-test {comment content} { | |
| 242 | + global UUID RESULT | |
| 243 | + | |
| 244 | + fossil revert | |
| 245 | + fossil update trunk | |
| 246 | + write_file datafile $comment | |
| 247 | + fossil commit -m $content | |
| 248 | + if {![uuid_from_commit $RESULT UUID]} { | |
| 249 | + set UUID "" | |
| 250 | + } | |
| 251 | +} | |
| 252 | + | |
| 253 | +proc test-comment {name UUID comment} { | |
| 254 | + global VERBOSE RESULT | |
| 255 | + | |
| 256 | + test amend-comment-$name.1 { | |
| 257 | + [string match "*uuid:*$UUID*comment:*$comment*" $RESULT] | |
| 258 | + } | |
| 259 | + fossil timeline -n 1 | |
| 260 | + if {[artifact_from_timeline $RESULT artid]} { | |
| 261 | + fossil artifact $artid | |
| 262 | + test amend-comment-$name.2 { | |
| 263 | + [string match "*T +comment $UUID *[manifest_comment $comment]*" $RESULT] | |
| 264 | + } | |
| 265 | + } else { | |
| 266 | + if {$VERBOSE} { protOut "No artifact found in timeline output: $RESULT" } | |
| 267 | + test amend-comment-$name.2 false | |
| 268 | + } | |
| 269 | + fossil timeline -n 1 | |
| 270 | + test amend-comment-$name.3 { | |
| 271 | + [string match "*[short_uuid $UUID]*Edit*check-in*comment.*" $RESULT] | |
| 272 | + } | |
| 273 | + fossil info $UUID | |
| 274 | + test amend-comment-$name.4 { | |
| 275 | + [string match "*uuid:*$UUID*comment:*$comment*" $RESULT] | |
| 276 | + } | |
| 277 | +} | |
| 278 | + | |
| 279 | +prep-test "revision 1" "revision 1" | |
| 280 | +fossil amend $UUID -comment "revised revision 1" | |
| 281 | +test-comment 1 $UUID "revised revision 1" | |
| 282 | + | |
| 283 | +prep-test "revision 2" "revision 2" | |
| 284 | +fossil amend $UUID -m "revised revision 2 with -m" | |
| 285 | +test-comment 2 $UUID "revised revision 2 with -m" | |
| 286 | + | |
| 287 | +prep-test "revision 3" "revision 3" | |
| 288 | +write_file commitmsg "revision 3 revised" | |
| 289 | +fossil amend $UUID -message-file commitmsg | |
| 290 | +test-comment 3 $UUID "revision 3 revised" | |
| 291 | + | |
| 292 | +prep-test "revision 4" "revision 4" | |
| 293 | +write_file commitmsg "revision 4 revised with -M" | |
| 294 | +fossil amend $UUID -M commitmsg | |
| 295 | +test-comment 4 $UUID "revision 4 revised with -M" | |
| 296 | + | |
| 297 | +prep-test "final comment" "final content" | |
| 298 | +if {[catch {exec which ed} result]} { | |
| 299 | + if {$VERBOSE} { protOut "Install ed for interactive comment test: $result" } | |
| 300 | + test-comment 5 $UUID "ed required for interactive edit" | |
| 301 | +} else { | |
| 302 | + set env(EDITOR) "ed -s" | |
| 303 | + set comment "interactive edited comment" | |
| 304 | + fossil_maybe_answer "a\n$comment\n.\nw\nq\n" amend $UUID --edit-comment | |
| 305 | + unset env(EDITOR) | |
| 306 | + test-comment 5 $UUID $comment | |
| 307 | +} | |
| 183 | 308 |
| --- test/amend.test | |
| +++ test/amend.test | |
| @@ -1,23 +1,40 @@ | |
| 1 | # |
| 2 | # Tests for the "amend" command. |
| 3 | # |
| 4 | |
| 5 | # Make sure we are not in an open repository and initialize new repository |
| 6 | repo_init |
| 7 | |
| 8 | ######################################## |
| 9 | # Setup: Add file and commit # |
| 10 | ######################################## |
| 11 | write_file datafile "data" |
| 12 | write_file commitmsg "committed" |
| 13 | |
| 14 | fossil add datafile |
| 15 | fossil commit -m "c1" |
| 16 | write_file datafile "data.file" |
| 17 | fossil commit -m "c2" |
| 18 | if {![regexp {^New_Version: ([0-9a-f]{40})$} $RESULT m UUID]} { |
| 19 | test amend-setup-failure false |
| 20 | return |
| 21 | } |
| 22 | |
| 23 | ######################################## |
| @@ -61,12 +78,11 @@ | |
| 61 | test amend-bgcolor-$tc.2 {[string first "bgcolor=$result" $RESULT] != -1} |
| 62 | fossil timeline -n 1 |
| 63 | test amend-bgcolor-$tc.3 { |
| 64 | [string match "*Change*background*color*to*\"$result\"*" $RESULT] |
| 65 | } |
| 66 | if {[regexp {(?x)[0-9]{2}(?::[0-9]{2}){2}\s+\[([0-9a-f]+)]} $RESULT m artid]}\ |
| 67 | { |
| 68 | fossil artifact $artid |
| 69 | test amend-bgcolor-$tc.4 { |
| 70 | [string match "*T +bgcolor $UUID $result*" $RESULT] |
| 71 | } |
| 72 | } else { |
| @@ -178,5 +194,114 @@ | |
| 178 | } |
| 179 | write_file datafile "changed" |
| 180 | fossil commit -m "should fail" |
| 181 | test amend-close-3.4 {[string first "closed leaf" $RESULT] != -1} |
| 182 | } |
| 183 |
| --- test/amend.test | |
| +++ test/amend.test | |
| @@ -1,23 +1,40 @@ | |
| 1 | # |
| 2 | # Tests for the "amend" command. |
| 3 | # |
| 4 | |
| 5 | proc short_uuid {uuid {len 10}} { |
| 6 | string range $uuid 0 $len-1 |
| 7 | } |
| 8 | |
| 9 | proc artifact_from_timeline {res var} { |
| 10 | upvar $var artid |
| 11 | regexp {(?x)[0-9]{2}(?::[0-9]{2}){2}\s+\[([0-9a-f]+)]} $res m artid |
| 12 | } |
| 13 | |
| 14 | proc manifest_comment {comment} { |
| 15 | string map [list { } {\\s} \n {\\n} \r {\\r}] $comment |
| 16 | } |
| 17 | |
| 18 | proc uuid_from_commit {res var} { |
| 19 | upvar $var UUID |
| 20 | regexp {^New_Version: ([0-9a-f]{40})$} $res m UUID |
| 21 | } |
| 22 | |
| 23 | # Make sure we are not in an open repository and initialize new repository |
| 24 | repo_init |
| 25 | |
| 26 | ######################################## |
| 27 | # Setup: Add file and commit # |
| 28 | ######################################## |
| 29 | write_file datafile "data" |
| 30 | |
| 31 | fossil add datafile |
| 32 | fossil commit -m "c1" |
| 33 | write_file datafile "data.file" |
| 34 | fossil commit -m "c2" |
| 35 | if {![uuid_from_commit $RESULT UUID]} { |
| 36 | test amend-setup-failure false |
| 37 | return |
| 38 | } |
| 39 | |
| 40 | ######################################## |
| @@ -61,12 +78,11 @@ | |
| 78 | test amend-bgcolor-$tc.2 {[string first "bgcolor=$result" $RESULT] != -1} |
| 79 | fossil timeline -n 1 |
| 80 | test amend-bgcolor-$tc.3 { |
| 81 | [string match "*Change*background*color*to*\"$result\"*" $RESULT] |
| 82 | } |
| 83 | if {[artifact_from_timeline $RESULT artid]} { |
| 84 | fossil artifact $artid |
| 85 | test amend-bgcolor-$tc.4 { |
| 86 | [string match "*T +bgcolor $UUID $result*" $RESULT] |
| 87 | } |
| 88 | } else { |
| @@ -178,5 +194,114 @@ | |
| 194 | } |
| 195 | write_file datafile "changed" |
| 196 | fossil commit -m "should fail" |
| 197 | test amend-close-3.4 {[string first "closed leaf" $RESULT] != -1} |
| 198 | } |
| 199 | |
| 200 | ######################################## |
| 201 | # Test: -tag/-cancel # |
| 202 | ######################################## |
| 203 | set tagtests { |
| 204 | tagged tagged |
| 205 | {000000 lower Upper alpha 0alpha} {000000 0alpha Upper alpha lower} |
| 206 | } |
| 207 | set tc 0 |
| 208 | foreach {tagt result} $tagtests { |
| 209 | incr tc |
| 210 | set tags {} |
| 211 | set cancels {} |
| 212 | set t1exp "" |
| 213 | set t2exp "*" |
| 214 | set t3exp "*" |
| 215 | set t5exp "*" |
| 216 | foreach tag $tagt { |
| 217 | lappend tags -tag $tag |
| 218 | lappend cancels -cancel $tag |
| 219 | } |
| 220 | foreach res $result { |
| 221 | append t1exp ", $res" |
| 222 | append t2exp "sym-$res*" |
| 223 | append t3exp "Add*tag*\"$res\".*" |
| 224 | append t5exp "Cancel*tag*\"$res\".*" |
| 225 | } |
| 226 | eval fossil amend $UUID $tags |
| 227 | test amend-tag-$tc.1 {[string match "*uuid:*$UUID*tags:*$t1exp*" $RESULT]} |
| 228 | fossil tag ls --raw $UUID |
| 229 | test amend-tag-$tc.2 {[string match $t2exp $RESULT]} |
| 230 | fossil timeline -n 1 |
| 231 | test amend-tag-$tc.3 {[string match $t3exp $RESULT]} |
| 232 | eval fossil amend $UUID $cancels |
| 233 | test amend-tag-$tc.4 {![string match "*tags:*$t1exp*" $RESULT]} |
| 234 | fossil timeline -n 1 |
| 235 | test amend-tag-$tc.5 {[string match $t5exp $RESULT]} |
| 236 | } |
| 237 | |
| 238 | ######################################## |
| 239 | # Test: -comment # |
| 240 | ######################################## |
| 241 | proc prep-test {comment content} { |
| 242 | global UUID RESULT |
| 243 | |
| 244 | fossil revert |
| 245 | fossil update trunk |
| 246 | write_file datafile $comment |
| 247 | fossil commit -m $content |
| 248 | if {![uuid_from_commit $RESULT UUID]} { |
| 249 | set UUID "" |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | proc test-comment {name UUID comment} { |
| 254 | global VERBOSE RESULT |
| 255 | |
| 256 | test amend-comment-$name.1 { |
| 257 | [string match "*uuid:*$UUID*comment:*$comment*" $RESULT] |
| 258 | } |
| 259 | fossil timeline -n 1 |
| 260 | if {[artifact_from_timeline $RESULT artid]} { |
| 261 | fossil artifact $artid |
| 262 | test amend-comment-$name.2 { |
| 263 | [string match "*T +comment $UUID *[manifest_comment $comment]*" $RESULT] |
| 264 | } |
| 265 | } else { |
| 266 | if {$VERBOSE} { protOut "No artifact found in timeline output: $RESULT" } |
| 267 | test amend-comment-$name.2 false |
| 268 | } |
| 269 | fossil timeline -n 1 |
| 270 | test amend-comment-$name.3 { |
| 271 | [string match "*[short_uuid $UUID]*Edit*check-in*comment.*" $RESULT] |
| 272 | } |
| 273 | fossil info $UUID |
| 274 | test amend-comment-$name.4 { |
| 275 | [string match "*uuid:*$UUID*comment:*$comment*" $RESULT] |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | prep-test "revision 1" "revision 1" |
| 280 | fossil amend $UUID -comment "revised revision 1" |
| 281 | test-comment 1 $UUID "revised revision 1" |
| 282 | |
| 283 | prep-test "revision 2" "revision 2" |
| 284 | fossil amend $UUID -m "revised revision 2 with -m" |
| 285 | test-comment 2 $UUID "revised revision 2 with -m" |
| 286 | |
| 287 | prep-test "revision 3" "revision 3" |
| 288 | write_file commitmsg "revision 3 revised" |
| 289 | fossil amend $UUID -message-file commitmsg |
| 290 | test-comment 3 $UUID "revision 3 revised" |
| 291 | |
| 292 | prep-test "revision 4" "revision 4" |
| 293 | write_file commitmsg "revision 4 revised with -M" |
| 294 | fossil amend $UUID -M commitmsg |
| 295 | test-comment 4 $UUID "revision 4 revised with -M" |
| 296 | |
| 297 | prep-test "final comment" "final content" |
| 298 | if {[catch {exec which ed} result]} { |
| 299 | if {$VERBOSE} { protOut "Install ed for interactive comment test: $result" } |
| 300 | test-comment 5 $UUID "ed required for interactive edit" |
| 301 | } else { |
| 302 | set env(EDITOR) "ed -s" |
| 303 | set comment "interactive edited comment" |
| 304 | fossil_maybe_answer "a\n$comment\n.\nw\nq\n" amend $UUID --edit-comment |
| 305 | unset env(EDITOR) |
| 306 | test-comment 5 $UUID $comment |
| 307 | } |
| 308 |