| | @@ -29,45 +29,53 @@ |
| 29 | 29 | set env(TH1_ENABLE_HOOKS) 1; # TH1 hooks must be enabled for this test. |
| 30 | 30 | |
| 31 | 31 | ############################################################################### |
| 32 | 32 | |
| 33 | 33 | proc fossil_th1_hook_http { repository url } { |
| 34 | | - set suffix [appendArgs [pid] - [clock seconds] .txt] |
| 34 | + set suffix [appendArgs [pid] - [getSeqNo] - [clock seconds] .txt] |
| 35 | 35 | set inFileName [file join $::tempPath [appendArgs test-http-in- $suffix]] |
| 36 | 36 | set outFileName [file join $::tempPath [appendArgs test-http-out- $suffix]] |
| 37 | 37 | set data [subst [read_file [file join $::testdir th1-hooks-input.txt]]] |
| 38 | 38 | |
| 39 | 39 | write_file $inFileName $data |
| 40 | | - fossil http $repository $inFileName $outFileName 127.0.0.1 |
| 40 | + fossil http $inFileName $outFileName 127.0.0.1 $repository |
| 41 | 41 | set result [expr {[file exists $outFileName] ? [read_file $outFileName] : ""}] |
| 42 | 42 | |
| 43 | 43 | if {1} then { |
| 44 | 44 | catch {file delete $inFileName} |
| 45 | 45 | catch {file delete $outFileName} |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | return $result |
| 49 | 49 | } |
| 50 | + |
| 51 | +proc normalize_result {} { |
| 52 | + return [string map [list \r\n \n] [string trim $::RESULT]] |
| 53 | +} |
| 50 | 54 | |
| 51 | 55 | proc first_data_line {} { |
| 52 | | - return [lindex [split [string trim $::RESULT] \r\n] 0] |
| 56 | + return [lindex [split [normalize_result] \n] 0] |
| 53 | 57 | } |
| 54 | 58 | |
| 55 | 59 | proc second_data_line {} { |
| 56 | | - return [lindex [split [string trim $::RESULT] \r\n] 1] |
| 60 | + return [lindex [split [normalize_result] \n] 1] |
| 57 | 61 | } |
| 58 | 62 | |
| 59 | 63 | proc third_data_line {} { |
| 60 | | - return [lindex [split [string trim $::RESULT] \r\n] 2] |
| 64 | + return [lindex [split [normalize_result] \n] 2] |
| 61 | 65 | } |
| 62 | 66 | |
| 63 | 67 | proc last_data_line {} { |
| 64 | | - return [lindex [split [string trim $::RESULT] \r\n] end] |
| 68 | + return [lindex [split [normalize_result] \n] end] |
| 65 | 69 | } |
| 66 | 70 | |
| 67 | 71 | proc next_to_last_data_line {} { |
| 68 | | - return [lindex [split [string trim $::RESULT] \r\n] end-1] |
| 72 | + return [lindex [split [normalize_result] \n] end-1] |
| 73 | +} |
| 74 | + |
| 75 | +proc third_to_last_data_line {} { |
| 76 | + return [lindex [split [normalize_result] \n] end-2] |
| 69 | 77 | } |
| 70 | 78 | |
| 71 | 79 | ############################################################################### |
| 72 | 80 | |
| 73 | 81 | set testTh1Setup { |
| | @@ -103,13 +111,18 @@ |
| 103 | 111 | break "TH_BREAK return code" |
| 104 | 112 | } elseif {$::cmd_name eq "test4"} { |
| 105 | 113 | emit_hook_log |
| 106 | 114 | return -code 2 "TH_RETURN return code" |
| 107 | 115 | } elseif {$::cmd_name eq "timeline"} { |
| 108 | | - if {$::cmd_args eq "custom"} { |
| 116 | + set length [llength $::cmd_args] |
| 117 | + set length [expr {$length - 1}] |
| 118 | + if {[lindex $::cmd_args $length] eq "custom"} { |
| 109 | 119 | emit_hook_log |
| 110 | 120 | return "custom timeline" |
| 121 | + } elseif {[lindex $::cmd_args $length] eq "now"} { |
| 122 | + emit_hook_log |
| 123 | + return "now timeline" |
| 111 | 124 | } else { |
| 112 | 125 | emit_hook_log |
| 113 | 126 | error "unsupported timeline" |
| 114 | 127 | } |
| 115 | 128 | } |
| | @@ -147,55 +160,79 @@ |
| 147 | 160 | saveTh1SetupFile; writeTh1SetupFile $testTh1Setup |
| 148 | 161 | |
| 149 | 162 | ############################################################################### |
| 150 | 163 | |
| 151 | 164 | fossil timeline custom; # NOTE: Bad "WHEN" argument. |
| 152 | | -test th1-cmd-hooks-1a {[string map [list \r\n \n] [string trim $RESULT]] eq {<h1><b>command_hook timeline</b></h1> |
| 153 | | -ERROR: unsupported timeline |
| 165 | +test th1-cmd-hooks-1a {[normalize_result] eq \ |
| 166 | +{<h1><b>command_hook timeline</b></h1> |
| 154 | 167 | +++ no more data (0) +++ |
| 155 | 168 | |
| 156 | 169 | <h1><b>command_hook timeline command_notify timeline</b></h1>}} |
| 157 | 170 | |
| 158 | 171 | ############################################################################### |
| 159 | 172 | |
| 160 | 173 | fossil timeline |
| 161 | | -test th1-cmd-hooks-2a {[first_data_line] eq {<h1><b>command_hook timeline</b></h1>}} |
| 174 | +test th1-cmd-hooks-2a {[first_data_line] eq \ |
| 175 | + {<h1><b>command_hook timeline</b></h1>}} |
| 176 | + |
| 162 | 177 | test th1-cmd-hooks-2b {[second_data_line] eq {ERROR: unsupported timeline}} |
| 163 | | -test th1-cmd-hooks-2c {[regexp -- {=== \d{4}-\d{2}-\d{2} ===} [third_data_line]]} |
| 164 | | -test th1-cmd-hooks-2d {[last_data_line] eq {<h1><b>command_hook timeline command_notify timeline</b></h1>}} |
| 178 | + |
| 179 | +############################################################################### |
| 180 | + |
| 181 | +fossil timeline now |
| 182 | +test th1-cmd-hooks-3a {[first_data_line] eq \ |
| 183 | + {<h1><b>command_hook timeline</b></h1>}} |
| 184 | + |
| 185 | +test th1-cmd-hooks-3b \ |
| 186 | + {[regexp -- {=== \d{4}-\d{2}-\d{2} ===} [second_data_line]]} |
| 187 | + |
| 188 | +test th1-cmd-hooks-3c \ |
| 189 | + {[regexp -- {--- line limit \(\d+\) reached ---} [third_to_last_data_line]]} |
| 190 | + |
| 191 | +test th1-cmd-hooks-3d {[last_data_line] eq \ |
| 192 | + {<h1><b>command_hook timeline command_notify timeline</b></h1>}} |
| 165 | 193 | |
| 166 | 194 | ############################################################################### |
| 167 | 195 | |
| 168 | 196 | fossil test1 |
| 169 | 197 | test th1-custom-cmd-1a {[next_to_last_data_line] eq $repository} |
| 170 | | -test th1-custom-cmd-1b {[last_data_line] eq {<h1><b>command_hook test1 command_notify test1</b></h1>}} |
| 198 | + |
| 199 | +test th1-custom-cmd-1b {[last_data_line] eq \ |
| 200 | + {<h1><b>command_hook test1 command_notify test1</b></h1>}} |
| 171 | 201 | |
| 172 | 202 | ############################################################################### |
| 173 | 203 | |
| 174 | 204 | fossil test2 |
| 175 | 205 | test th1-custom-cmd-2a {[first_data_line] eq {ERROR: unsupported command}} |
| 176 | 206 | |
| 177 | 207 | ############################################################################### |
| 178 | 208 | |
| 179 | 209 | fossil test3 |
| 180 | | -test th1-custom-cmd-3a {[string trim $RESULT] eq {<h1><b>command_hook test3</b></h1>}} |
| 210 | +test th1-custom-cmd-3a {[string trim $RESULT] eq \ |
| 211 | + {<h1><b>command_hook test3</b></h1>}} |
| 181 | 212 | |
| 182 | 213 | ############################################################################### |
| 183 | 214 | |
| 184 | 215 | fossil test4 |
| 185 | | -test th1-custom-cmd-4a {[string trim $RESULT] eq {<h1><b>command_hook test4</b></h1>}} |
| 216 | +test th1-custom-cmd-4a {[string trim $RESULT] eq \ |
| 217 | + {<h1><b>command_hook test4</b></h1>}} |
| 186 | 218 | |
| 187 | 219 | ############################################################################### |
| 188 | 220 | |
| 189 | 221 | set RESULT [fossil_th1_hook_http $repository /timeline] |
| 190 | 222 | test th1-web-hooks-1a {[regexp {<title>Fossil: Timeline</title>} $RESULT]} |
| 191 | | -test th1-web-hooks-1b {[regexp {<h1><b>command_hook http webpage_hook timeline webpage_notify timeline</b></h1>} $RESULT]} |
| 223 | + |
| 224 | +test th1-web-hooks-1b {[regexp [appendArgs \ |
| 225 | + {<h1><b>command_hook http webpage_hook timeline} " " \ |
| 226 | + {webpage_notify timeline</b></h1>}] $RESULT]} |
| 192 | 227 | |
| 193 | 228 | ############################################################################### |
| 194 | 229 | |
| 195 | 230 | set RESULT [fossil_th1_hook_http $repository /test1] |
| 196 | 231 | test th1-custom-web-1a {[next_to_last_data_line] eq $repository} |
| 197 | | -test th1-custom-web-1b {[last_data_line] eq {<h1><b>command_hook http webpage_hook test1 webpage_notify test1</b></h1>}} |
| 232 | + |
| 233 | +test th1-custom-web-1b {[last_data_line] eq \ |
| 234 | + {<h1><b>command_hook http webpage_hook test1 webpage_notify test1</b></h1>}} |
| 198 | 235 | |
| 199 | 236 | ############################################################################### |
| 200 | 237 | |
| 201 | 238 | restoreTh1SetupFile |
| 202 | 239 | |