Fossil SCM

Add some utility functions to tester.tcl to reduce boilerplate code in certain tests.

joel 2014-02-22 05:31 trunk
Commit 23d3113bb1518f5f529dc8bef32da9b192fd276d
--- test/merge_renames.test
+++ test/merge_renames.test
@@ -1,30 +1,16 @@
11
#
22
# Tests for merging with renames
33
#
44
#
5
-
6
-catch {exec $::fossilexe info} res
7
-puts res=$res
8
-if {![regexp {use --repository} $res]} {
9
- puts stderr "Cannot run this test within an open checkout"
10
- return
11
-}
12
-
13
-
14
-# Fossil will write data on $HOME, running 'fossil new' here.
15
-# We need not to clutter the $HOME of the test caller.
16
-set env(HOME) [pwd]
17
-
185
196
######################################
207
# Test 1 #
218
# Reported: Ticket [554f44ee74e3d] #
229
######################################
2310
24
-fossil new rep.fossil
25
-fossil open rep.fossil
11
+repo_init
2612
2713
write_file f1 "line"
2814
fossil add f1
2915
fossil commit -m "c1"
3016
fossil tag add pivot current
@@ -73,20 +59,16 @@
7359
test merge_renames-1 0
7460
} else {
7561
test merge_renames-1 1
7662
}
7763
78
-fossil close -f
79
-file delete rep.fossil
80
-
8164
######################################
8265
# Test 2 #
8366
# Reported: Ticket [74413366fe5067] #
8467
######################################
8568
86
-fossil new rep.fossil
87
-fossil open rep.fossil
69
+repo_init
8870
8971
write_file f1 "line"
9072
fossil add f1
9173
fossil commit -m "base file"
9274
fossil tag add pivot current
@@ -125,20 +107,16 @@
125107
test merge_renames-2 0
126108
} else {
127109
test merge_renames-2 1
128110
}
129111
130
-fossil close -f
131
-file delete rep.fossil
132
-
133112
######################################
134113
# Test 3 #
135114
# Reported: Ticket [30b28cf351] #
136115
######################################
137116
138
-fossil new rep.fossil
139
-fossil open rep.fossil
117
+repo_init
140118
141119
write_file f1 "line"
142120
fossil add f1
143121
fossil commit -m "base file"
144122
fossil tag add pivot current
@@ -177,13 +155,10 @@
177155
test merge_renames-2 0
178156
} else {
179157
test merge_renames-2 1
180158
}
181159
182
-fossil close -f
183
-file delete rep.fossil
184
-
185160
######################################
186161
# Test 4 #
187162
# Reported: Ticket [67176c3aa4] #
188163
######################################
189164
190165
--- test/merge_renames.test
+++ test/merge_renames.test
@@ -1,30 +1,16 @@
1 #
2 # Tests for merging with renames
3 #
4 #
5
6 catch {exec $::fossilexe info} res
7 puts res=$res
8 if {![regexp {use --repository} $res]} {
9 puts stderr "Cannot run this test within an open checkout"
10 return
11 }
12
13
14 # Fossil will write data on $HOME, running 'fossil new' here.
15 # We need not to clutter the $HOME of the test caller.
16 set env(HOME) [pwd]
17
18
19 ######################################
20 # Test 1 #
21 # Reported: Ticket [554f44ee74e3d] #
22 ######################################
23
24 fossil new rep.fossil
25 fossil open rep.fossil
26
27 write_file f1 "line"
28 fossil add f1
29 fossil commit -m "c1"
30 fossil tag add pivot current
@@ -73,20 +59,16 @@
73 test merge_renames-1 0
74 } else {
75 test merge_renames-1 1
76 }
77
78 fossil close -f
79 file delete rep.fossil
80
81 ######################################
82 # Test 2 #
83 # Reported: Ticket [74413366fe5067] #
84 ######################################
85
86 fossil new rep.fossil
87 fossil open rep.fossil
88
89 write_file f1 "line"
90 fossil add f1
91 fossil commit -m "base file"
92 fossil tag add pivot current
@@ -125,20 +107,16 @@
125 test merge_renames-2 0
126 } else {
127 test merge_renames-2 1
128 }
129
130 fossil close -f
131 file delete rep.fossil
132
133 ######################################
134 # Test 3 #
135 # Reported: Ticket [30b28cf351] #
136 ######################################
137
138 fossil new rep.fossil
139 fossil open rep.fossil
140
141 write_file f1 "line"
142 fossil add f1
143 fossil commit -m "base file"
144 fossil tag add pivot current
@@ -177,13 +155,10 @@
177 test merge_renames-2 0
178 } else {
179 test merge_renames-2 1
180 }
181
182 fossil close -f
183 file delete rep.fossil
184
185 ######################################
186 # Test 4 #
187 # Reported: Ticket [67176c3aa4] #
188 ######################################
189
190
--- test/merge_renames.test
+++ test/merge_renames.test
@@ -1,30 +1,16 @@
1 #
2 # Tests for merging with renames
3 #
4 #
 
 
 
 
 
 
 
 
 
 
 
 
 
5
6 ######################################
7 # Test 1 #
8 # Reported: Ticket [554f44ee74e3d] #
9 ######################################
10
11 repo_init
 
12
13 write_file f1 "line"
14 fossil add f1
15 fossil commit -m "c1"
16 fossil tag add pivot current
@@ -73,20 +59,16 @@
59 test merge_renames-1 0
60 } else {
61 test merge_renames-1 1
62 }
63
 
 
 
64 ######################################
65 # Test 2 #
66 # Reported: Ticket [74413366fe5067] #
67 ######################################
68
69 repo_init
 
70
71 write_file f1 "line"
72 fossil add f1
73 fossil commit -m "base file"
74 fossil tag add pivot current
@@ -125,20 +107,16 @@
107 test merge_renames-2 0
108 } else {
109 test merge_renames-2 1
110 }
111
 
 
 
112 ######################################
113 # Test 3 #
114 # Reported: Ticket [30b28cf351] #
115 ######################################
116
117 repo_init
 
118
119 write_file f1 "line"
120 fossil add f1
121 fossil commit -m "base file"
122 fossil tag add pivot current
@@ -177,13 +155,10 @@
155 test merge_renames-2 0
156 } else {
157 test merge_renames-2 1
158 }
159
 
 
 
160 ######################################
161 # Test 4 #
162 # Reported: Ticket [67176c3aa4] #
163 ######################################
164
165
+5 -38
--- test/revert.test
+++ test/revert.test
@@ -1,36 +1,10 @@
11
#
22
# Tests for 'fossil revert'
33
#
44
#
55
6
-catch {exec $::fossilexe info} res
7
-puts res=$res
8
-if {![regexp {use --repository} $res]} {
9
- puts stderr "Cannot run this test within an open checkout"
10
- return
11
-}
12
-
13
-# Fossil will write data on $HOME, running 'fossil new' here.
14
-# We need not to clutter the $HOME of the test caller.
15
-#
16
-set env(HOME) [pwd]
17
-
18
-
19
-# Normalize file status lists (like those returned by 'fossil changes')
20
-# so they can be compared using simple string comparison
21
-#
22
-proc normalize-status-list {list} {
23
- set normalized [list]
24
- set matches [regexp -all -inline -line {^\s*([A-Z]+)\s+(.*)$} $list]
25
- foreach {_ status file} $matches {
26
- lappend normalized [list $status [string trim $file]]
27
- }
28
- set normalized [lsort -index 1 $normalized]
29
- return $normalized
30
-}
31
-
326
# Test 'fossil revert' against expected results from 'fossil changes' and
337
# 'fossil addremove --test', as well as by verifying the existence of files
348
# on the file system. 'fossil undo' is called after each test
359
#
3610
proc revert-test {testid args} {
@@ -49,17 +23,13 @@
4923
5024
fossil revert {*}$revertArgs
5125
5226
set statusListTests [list -changes changes -addremove {addremove --test}]
5327
foreach {key fossilArgs} $statusListTests {
54
- set expected [normalize-status-list [dict get $args $key]]
55
- set result [normalize-status-list [fossil {*}$fossilArgs]]
56
- if {$result ne $expected} {
57
- set passed 0
58
- protOut " Expected:\n [join $expected "\n "]"
59
- protOut " Got:\n [join $result "\n "]"
60
- }
28
+ set expected [dict get $args $key]
29
+ set result [fossil {*}$fossilArgs]
30
+ test_status_list revert-$testid$key $result $expected
6131
}
6232
6333
set fileExistsTests [list -exists 1 does -notexists 0 should]
6434
foreach {key expected verb} $fileExistsTests {
6535
foreach path [dict get $args $key] {
@@ -66,20 +36,17 @@
6636
if {[file exists $path] != $expected} {
6737
set passed 0
6838
protOut " Failure: File $verb not exist: $path"
6939
}
7040
}
41
+ test revert-$testid$key $passed
7142
}
7243
7344
fossil undo
74
- test revert-$testid $passed
7545
}
7646
77
-# Create the repo
78
-#
79
-fossil new rep.fossil
80
-fossil open rep.fossil
47
+repo_init
8148
8249
# Prepare first commit
8350
#
8451
write_file f1 "f1"
8552
write_file f2 "f2"
8653
--- test/revert.test
+++ test/revert.test
@@ -1,36 +1,10 @@
1 #
2 # Tests for 'fossil revert'
3 #
4 #
5
6 catch {exec $::fossilexe info} res
7 puts res=$res
8 if {![regexp {use --repository} $res]} {
9 puts stderr "Cannot run this test within an open checkout"
10 return
11 }
12
13 # Fossil will write data on $HOME, running 'fossil new' here.
14 # We need not to clutter the $HOME of the test caller.
15 #
16 set env(HOME) [pwd]
17
18
19 # Normalize file status lists (like those returned by 'fossil changes')
20 # so they can be compared using simple string comparison
21 #
22 proc normalize-status-list {list} {
23 set normalized [list]
24 set matches [regexp -all -inline -line {^\s*([A-Z]+)\s+(.*)$} $list]
25 foreach {_ status file} $matches {
26 lappend normalized [list $status [string trim $file]]
27 }
28 set normalized [lsort -index 1 $normalized]
29 return $normalized
30 }
31
32 # Test 'fossil revert' against expected results from 'fossil changes' and
33 # 'fossil addremove --test', as well as by verifying the existence of files
34 # on the file system. 'fossil undo' is called after each test
35 #
36 proc revert-test {testid args} {
@@ -49,17 +23,13 @@
49
50 fossil revert {*}$revertArgs
51
52 set statusListTests [list -changes changes -addremove {addremove --test}]
53 foreach {key fossilArgs} $statusListTests {
54 set expected [normalize-status-list [dict get $args $key]]
55 set result [normalize-status-list [fossil {*}$fossilArgs]]
56 if {$result ne $expected} {
57 set passed 0
58 protOut " Expected:\n [join $expected "\n "]"
59 protOut " Got:\n [join $result "\n "]"
60 }
61 }
62
63 set fileExistsTests [list -exists 1 does -notexists 0 should]
64 foreach {key expected verb} $fileExistsTests {
65 foreach path [dict get $args $key] {
@@ -66,20 +36,17 @@
66 if {[file exists $path] != $expected} {
67 set passed 0
68 protOut " Failure: File $verb not exist: $path"
69 }
70 }
 
71 }
72
73 fossil undo
74 test revert-$testid $passed
75 }
76
77 # Create the repo
78 #
79 fossil new rep.fossil
80 fossil open rep.fossil
81
82 # Prepare first commit
83 #
84 write_file f1 "f1"
85 write_file f2 "f2"
86
--- test/revert.test
+++ test/revert.test
@@ -1,36 +1,10 @@
1 #
2 # Tests for 'fossil revert'
3 #
4 #
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6 # Test 'fossil revert' against expected results from 'fossil changes' and
7 # 'fossil addremove --test', as well as by verifying the existence of files
8 # on the file system. 'fossil undo' is called after each test
9 #
10 proc revert-test {testid args} {
@@ -49,17 +23,13 @@
23
24 fossil revert {*}$revertArgs
25
26 set statusListTests [list -changes changes -addremove {addremove --test}]
27 foreach {key fossilArgs} $statusListTests {
28 set expected [dict get $args $key]
29 set result [fossil {*}$fossilArgs]
30 test_status_list revert-$testid$key $result $expected
 
 
 
 
31 }
32
33 set fileExistsTests [list -exists 1 does -notexists 0 should]
34 foreach {key expected verb} $fileExistsTests {
35 foreach path [dict get $args $key] {
@@ -66,20 +36,17 @@
36 if {[file exists $path] != $expected} {
37 set passed 0
38 protOut " Failure: File $verb not exist: $path"
39 }
40 }
41 test revert-$testid$key $passed
42 }
43
44 fossil undo
 
45 }
46
47 repo_init
 
 
 
48
49 # Prepare first commit
50 #
51 write_file f1 "f1"
52 write_file f2 "f2"
53
--- test/tester.tcl
+++ test/tester.tcl
@@ -120,10 +120,57 @@
120120
regsub -all { +\n} $x \n x
121121
set y [read_file $b]
122122
regsub -all { +\n} $y \n y
123123
return [expr {$x==$y}]
124124
}
125
+
126
+# Create and open a new Fossil repository and clean the checkout
127
+#
128
+proc repo_init {{filename ".rep.fossil"}} {
129
+ if {$::env(HOME) ne [pwd]} {
130
+ catch {exec $::fossilexe info} res
131
+ if {![regexp {use --repository} $res]} {
132
+ error "In an open checkout: cannot initialize a new repository here."
133
+ }
134
+ # Fossil will write data on $HOME, running 'fossil new' here.
135
+ # We need not to clutter the $HOME of the test caller.
136
+ #
137
+ set ::env(HOME) [pwd]
138
+ }
139
+ catch {exec $::fossilexe close -f}
140
+ file delete $filename
141
+ exec $::fossilexe new $filename
142
+ exec $::fossilexe open $filename
143
+ exec $::fossilexe clean -f
144
+}
145
+
146
+# Normalize file status lists (like those returned by 'fossil changes')
147
+# so they can be compared using simple string comparison
148
+#
149
+proc normalize_status_list {list} {
150
+ set normalized [list]
151
+ set matches [regexp -all -inline -line {^\s*([A-Z_]+:?)\x20+(\S.*)$} $list]
152
+ foreach {_ status file} $matches {
153
+ lappend normalized [list $status [string trim $file]]
154
+ }
155
+ set normalized [lsort -index 1 $normalized]
156
+ return $normalized
157
+}
158
+
159
+# Perform a test comparing two status lists
160
+#
161
+proc test_status_list {name result expected} {
162
+ set expected [normalize_status_list $expected]
163
+ set result [normalize_status_list $result]
164
+ if {$result eq $expected} {
165
+ test $name 1
166
+ } else {
167
+ protOut " Expected:\n [join $expected "\n "]"
168
+ protOut " Got:\n [join $result "\n "]"
169
+ test $name 0
170
+ }
171
+}
125172
126173
# Perform a test
127174
#
128175
set test_count 0
129176
proc test {name expr} {
130177
--- test/tester.tcl
+++ test/tester.tcl
@@ -120,10 +120,57 @@
120 regsub -all { +\n} $x \n x
121 set y [read_file $b]
122 regsub -all { +\n} $y \n y
123 return [expr {$x==$y}]
124 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
126 # Perform a test
127 #
128 set test_count 0
129 proc test {name expr} {
130
--- test/tester.tcl
+++ test/tester.tcl
@@ -120,10 +120,57 @@
120 regsub -all { +\n} $x \n x
121 set y [read_file $b]
122 regsub -all { +\n} $y \n y
123 return [expr {$x==$y}]
124 }
125
126 # Create and open a new Fossil repository and clean the checkout
127 #
128 proc repo_init {{filename ".rep.fossil"}} {
129 if {$::env(HOME) ne [pwd]} {
130 catch {exec $::fossilexe info} res
131 if {![regexp {use --repository} $res]} {
132 error "In an open checkout: cannot initialize a new repository here."
133 }
134 # Fossil will write data on $HOME, running 'fossil new' here.
135 # We need not to clutter the $HOME of the test caller.
136 #
137 set ::env(HOME) [pwd]
138 }
139 catch {exec $::fossilexe close -f}
140 file delete $filename
141 exec $::fossilexe new $filename
142 exec $::fossilexe open $filename
143 exec $::fossilexe clean -f
144 }
145
146 # Normalize file status lists (like those returned by 'fossil changes')
147 # so they can be compared using simple string comparison
148 #
149 proc normalize_status_list {list} {
150 set normalized [list]
151 set matches [regexp -all -inline -line {^\s*([A-Z_]+:?)\x20+(\S.*)$} $list]
152 foreach {_ status file} $matches {
153 lappend normalized [list $status [string trim $file]]
154 }
155 set normalized [lsort -index 1 $normalized]
156 return $normalized
157 }
158
159 # Perform a test comparing two status lists
160 #
161 proc test_status_list {name result expected} {
162 set expected [normalize_status_list $expected]
163 set result [normalize_status_list $result]
164 if {$result eq $expected} {
165 test $name 1
166 } else {
167 protOut " Expected:\n [join $expected "\n "]"
168 protOut " Got:\n [join $result "\n "]"
169 test $name 0
170 }
171 }
172
173 # Perform a test
174 #
175 set test_count 0
176 proc test {name expr} {
177

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button