Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Pass command line arguments to hooks via a TH1 list variable. Enhance test suite infrastructure and add tests. Update hook TH_ERROR return code handling comments to reflect reality. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | th1Hooks |
| Files: | files | file ages | folders |
| SHA1: |
b34dbc78b571a53d48638abc4ce21dd8 |
| User & Date: | mistachkin 2014-06-10 04:32:51.275 |
Context
|
2014-06-10
| ||
| 05:02 | Merge updates from trunk. ... (check-in: 0465fecca3 user: mistachkin tags: th1Hooks) | |
| 04:32 | Pass command line arguments to hooks via a TH1 list variable. Enhance test suite infrastructure and add tests. Update hook TH_ERROR return code handling comments to reflect reality. ... (check-in: b34dbc78b5 user: mistachkin tags: th1Hooks) | |
|
2014-06-09
| ||
| 20:07 | Enable TH1 hooks for all web pages, known and unknown. ... (check-in: f90f723010 user: mistachkin tags: th1Hooks) | |
Changes
Changes to src/main.c.
| ︙ | ︙ | |||
696 697 698 699 700 701 702 | atexit( fossil_atexit ); #ifdef FOSSIL_ENABLE_TH1_HOOKS /* ** The TH1 return codes from the hook will be handled as follows: ** ** TH_OK: The xFunc() and the TH1 notification will both be executed. ** | | > > | 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 | atexit( fossil_atexit ); #ifdef FOSSIL_ENABLE_TH1_HOOKS /* ** The TH1 return codes from the hook will be handled as follows: ** ** TH_OK: The xFunc() and the TH1 notification will both be executed. ** ** TH_ERROR: The xFunc() will be executed, the TH1 notification will be ** skipped. If the xFunc() is being hooked, the error message ** will be emitted. ** ** TH_BREAK: The xFunc() and the TH1 notification will both be skipped. ** ** TH_RETURN: The xFunc() will be executed, the TH1 notification will be ** skipped. ** ** TH_CONTINUE: The xFunc() will be skipped, the TH1 notification will be |
| ︙ | ︙ | |||
1587 1588 1589 1590 1591 1592 1593 |
}else{
#ifdef FOSSIL_ENABLE_TH1_HOOKS
/*
** The TH1 return codes from the hook will be handled as follows:
**
** TH_OK: The xFunc() and the TH1 notification will both be executed.
**
| | > > | 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 |
}else{
#ifdef FOSSIL_ENABLE_TH1_HOOKS
/*
** The TH1 return codes from the hook will be handled as follows:
**
** TH_OK: The xFunc() and the TH1 notification will both be executed.
**
** TH_ERROR: The xFunc() will be executed, the TH1 notification will be
** skipped. If the xFunc() is being hooked, the error message
** will be emitted.
**
** TH_BREAK: The xFunc() and the TH1 notification will both be skipped.
**
** TH_RETURN: The xFunc() will be executed, the TH1 notification will be
** skipped.
**
** TH_CONTINUE: The xFunc() will be skipped, the TH1 notification will be
|
| ︙ | ︙ |
Changes to src/th_main.c.
| ︙ | ︙ | |||
1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 |
if( zValue ){
if( g.thTrace ){
Th_Trace("set %h {%h}<br />\n", zName, zValue);
}
Th_SetVar(g.interp, zName, -1, zValue, strlen(zValue));
}
}
/*
** Store an integer value in a variable in the interpreter.
*/
void Th_StoreInt(const char *zName, int iValue){
Blob value;
char *zValue;
| > > > > > > > > > > > > > > > > > > > > > > > > | 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 |
if( zValue ){
if( g.thTrace ){
Th_Trace("set %h {%h}<br />\n", zName, zValue);
}
Th_SetVar(g.interp, zName, -1, zValue, strlen(zValue));
}
}
/*
** Store a list value in a variable in the interpreter.
*/
void Th_StoreList(
const char *zName,
char **pzList,
int nList
){
Th_FossilInit(TH_INIT_DEFAULT);
if( pzList ){
char *zValue = 0;
int nValue = 0;
int i;
for(i=0; i<nList; i++){
Th_ListAppend(g.interp, &zValue, &nValue, pzList[i], -1);
}
if( g.thTrace ){
Th_Trace("set %h {%h}<br />\n", zName, zValue);
}
Th_SetVar(g.interp, zName, -1, zValue, nValue);
Th_Free(g.interp, zValue);
}
}
/*
** Store an integer value in a variable in the interpreter.
*/
void Th_StoreInt(const char *zName, int iValue){
Blob value;
char *zValue;
|
| ︙ | ︙ | |||
1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 |
int Th_CommandHook(
const char *zName,
char cmdFlags
){
int rc = TH_OK;
Th_FossilInit(TH_INIT_HOOK);
Th_Store("cmd_name", zName);
Th_StoreInt("cmd_flags", cmdFlags);
rc = Th_Eval(g.interp, 0, "command_hook", -1);
if( rc==TH_ERROR ){
int nResult = 0;
char *zResult = (char*)Th_GetResult(g.interp, &nResult);
/*
** Make sure that the TH1 script error was not caused by a "missing"
| > | 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 |
int Th_CommandHook(
const char *zName,
char cmdFlags
){
int rc = TH_OK;
Th_FossilInit(TH_INIT_HOOK);
Th_Store("cmd_name", zName);
Th_StoreList("cmd_args", g.argv, g.argc);
Th_StoreInt("cmd_flags", cmdFlags);
rc = Th_Eval(g.interp, 0, "command_hook", -1);
if( rc==TH_ERROR ){
int nResult = 0;
char *zResult = (char*)Th_GetResult(g.interp, &nResult);
/*
** Make sure that the TH1 script error was not caused by a "missing"
|
| ︙ | ︙ | |||
1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 |
int Th_CommandNotify(
const char *zName,
char cmdFlags
){
int rc;
Th_FossilInit(TH_INIT_HOOK);
Th_Store("cmd_name", zName);
Th_StoreInt("cmd_flags", cmdFlags);
rc = Th_Eval(g.interp, 0, "command_notify", -1);
if( g.thTrace ){
Th_Trace("[command_notify {%h}] => %h<br />\n", zName,
Th_ReturnCodeName(rc, 0));
}
return rc;
| > | 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 |
int Th_CommandNotify(
const char *zName,
char cmdFlags
){
int rc;
Th_FossilInit(TH_INIT_HOOK);
Th_Store("cmd_name", zName);
Th_StoreList("cmd_args", g.argv, g.argc);
Th_StoreInt("cmd_flags", cmdFlags);
rc = Th_Eval(g.interp, 0, "command_notify", -1);
if( g.thTrace ){
Th_Trace("[command_notify {%h}] => %h<br />\n", zName,
Th_ReturnCodeName(rc, 0));
}
return rc;
|
| ︙ | ︙ | |||
1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 |
int Th_WebpageHook(
const char *zName,
char cmdFlags
){
int rc = TH_OK;
Th_FossilInit(TH_INIT_HOOK);
Th_Store("web_name", zName);
Th_StoreInt("web_flags", cmdFlags);
rc = Th_Eval(g.interp, 0, "webpage_hook", -1);
if( rc==TH_ERROR ){
int nResult = 0;
char *zResult = (char*)Th_GetResult(g.interp, &nResult);
/*
** Make sure that the TH1 script error was not caused by a "missing"
| > | 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 |
int Th_WebpageHook(
const char *zName,
char cmdFlags
){
int rc = TH_OK;
Th_FossilInit(TH_INIT_HOOK);
Th_Store("web_name", zName);
Th_StoreList("web_args", g.argv, g.argc);
Th_StoreInt("web_flags", cmdFlags);
rc = Th_Eval(g.interp, 0, "webpage_hook", -1);
if( rc==TH_ERROR ){
int nResult = 0;
char *zResult = (char*)Th_GetResult(g.interp, &nResult);
/*
** Make sure that the TH1 script error was not caused by a "missing"
|
| ︙ | ︙ | |||
1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 |
int Th_WebpageNotify(
const char *zName,
char cmdFlags
){
int rc;
Th_FossilInit(TH_INIT_HOOK);
Th_Store("web_name", zName);
Th_StoreInt("web_flags", cmdFlags);
rc = Th_Eval(g.interp, 0, "webpage_notify", -1);
if( g.thTrace ){
Th_Trace("[webpage_notify {%h}] => %h<br />\n", zName,
Th_ReturnCodeName(rc, 0));
}
return rc;
| > | 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 |
int Th_WebpageNotify(
const char *zName,
char cmdFlags
){
int rc;
Th_FossilInit(TH_INIT_HOOK);
Th_Store("web_name", zName);
Th_StoreList("web_args", g.argv, g.argc);
Th_StoreInt("web_flags", cmdFlags);
rc = Th_Eval(g.interp, 0, "webpage_notify", -1);
if( g.thTrace ){
Th_Trace("[webpage_notify {%h}] => %h<br />\n", zName,
Th_ReturnCodeName(rc, 0));
}
return rc;
|
| ︙ | ︙ |
Changes to test/tester.tcl.
| ︙ | ︙ | |||
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
if {[llength $argv]==0} {
foreach f [lsort [glob $testdir/*.test]] {
set base [file root [file tail $f]]
lappend argv $base
}
}
# start protocol
#
proc protInit {cmd} {
if {$::PROT} {
set out [open "prot" w]
fconfigure $out -translation platform
| > > > > > > > | 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
if {[llength $argv]==0} {
foreach f [lsort [glob $testdir/*.test]] {
set base [file root [file tail $f]]
lappend argv $base
}
}
set tempPath [expr {[info exists env(TEMP)] ? \
$env(TEMP) : [file dirname [info script]]}]
if {$tcl_platform(platform) eq "windows"} then {
set tempPath [string map [list \\ /] $tempPath]
}
# start protocol
#
proc protInit {cmd} {
if {$::PROT} {
set out [open "prot" w]
fconfigure $out -translation platform
|
| ︙ | ︙ | |||
166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
test $name 1
} else {
protOut " Expected:\n [join $expected "\n "]"
protOut " Got:\n [join $result "\n "]"
test $name 0
}
}
# Perform a test
#
set test_count 0
proc test {name expr} {
global bad_test test_count
incr test_count
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
test $name 1
} else {
protOut " Expected:\n [join $expected "\n "]"
protOut " Got:\n [join $result "\n "]"
test $name 0
}
}
# Append all arguments into a single value and then returns it.
#
proc appendArgs {args} {
eval append result $args
}
# Return the name of the versioned settings file containing the TH1
# setup script.
#
proc getTh1SetupFileName {} {
#
# NOTE: This uses the "testdir" global variable provided by the
# test suite; alternatively, the root of the source tree
# could be obtained directly from Fossil.
#
return [file normalize [file join [file dirname $::testdir] \
.fossil-settings th1-setup]]
}
# Return the saved name of the versioned settings file containing
# the TH1 setup script.
#
proc getSavedTh1SetupFileName {} {
return [appendArgs [getTh1SetupFileName] . [pid]]
}
# Sets the TH1 setup script to the one provided. Prior to calling
# this, the [saveTh1SetupFile] procedure should be called in order to
# preserve the existing TH1 setup script. Prior to completing the test,
# the [restoreTh1SetupFile] procedure should be called to restore the
# original TH1 setup script.
#
proc writeTh1SetupFile { data } {
return [write_file [getTh1SetupFileName] $data]
}
# Saves the TH1 setup script file by renaming it, based on the current
# process ID.
#
proc saveTh1SetupFile {} {
set oldFileName [getTh1SetupFileName]
if {[file exists $oldFileName]} then {
set newFileName [getSavedTh1SetupFileName]
catch {file delete $newFileName}
file rename $oldFileName $newFileName
file delete $oldFileName
}
}
# Restores the original TH1 setup script file by renaming it back, based
# on the current process ID.
#
proc restoreTh1SetupFile {} {
set oldFileName [getSavedTh1SetupFileName]
if {[file exists $oldFileName]} then {
set newFileName [getTh1SetupFileName]
catch {file delete $newFileName}
file rename $oldFileName $newFileName
file delete $oldFileName
}
}
# Perform a test
#
set test_count 0
proc test {name expr} {
global bad_test test_count
incr test_count
|
| ︙ | ︙ |
Added test/th1-hooks-input.txt.
> > > > | 1 2 3 4 |
GET ${url} HTTP/1.1
Host: localhost
User-Agent: Fossil
|
Added test/th1-hooks.test.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
#
# Copyright (c) 2011 D. Richard Hipp
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the Simplified BSD License (also
# known as the "2-Clause License" or "FreeBSD License".)
#
# This program is distributed in the hope that it will be useful,
# but without any warranty; without even the implied warranty of
# merchantability or fitness for a particular purpose.
#
# Author contact information:
# drh@hwaci.com
# http://www.hwaci.com/drh/
#
############################################################################
#
# TH1 Hooks
#
fossil test-th-eval "hasfeature th1Hooks"
if {$::RESULT ne "1"} then {
puts "Fossil was not compiled with TH1 hooks support."; return
}
###############################################################################
proc fossil_th1_hook_http { repository url } {
set suffix [appendArgs [pid] - [clock seconds] .txt]
set inFileName [file join $::tempPath [appendArgs test-http-in- $suffix]]
set outFileName [file join $::tempPath [appendArgs test-http-out- $suffix]]
set data [subst [read_file [file join $::testdir th1-hooks-input.txt]]]
write_file $inFileName $data
fossil http $repository $inFileName $outFileName 127.0.0.1
set result [expr {[file exists $outFileName] ? [read_file $outFileName] : ""}]
if {1} then {
catch {file delete $inFileName}
catch {file delete $outFileName}
}
return $result
}
proc first_data_line {} {
return [lindex [split [string trim $::RESULT] \r\n] 0]
}
proc second_data_line {} {
return [lindex [split [string trim $::RESULT] \r\n] 1]
}
proc third_data_line {} {
return [lindex [split [string trim $::RESULT] \r\n] 2]
}
proc last_data_line {} {
return [lindex [split [string trim $::RESULT] \r\n] end]
}
proc next_to_last_data_line {} {
return [lindex [split [string trim $::RESULT] \r\n] end-1]
}
###############################################################################
set testTh1Setup {
proc initialize_hook_log {} {
if {![info exists ::hook_log]} {
set ::hook_log ""
}
}
proc append_hook_log { args } {
initialize_hook_log
if {[string length $::hook_log] > 0} {
set ::hook_log "$::hook_log "
}
for {set i 0} {$i < [llength $args]} {set i [expr {$i + 1}]} {
set ::hook_log $::hook_log[lindex $args $i]
}
}
proc emit_hook_log {} {
initialize_hook_log
html "\n<h1><b>$::hook_log</b></h1>\n"
}
proc command_hook {} {
append_hook_log command_hook " " $::cmd_name
if {$::cmd_name eq "test1"} {
puts [repository]; continue
} elseif {$::cmd_name eq "test2"} {
error "unsupported command"
} elseif {$::cmd_name eq "test3"} {
emit_hook_log
break "TH_BREAK return code"
} elseif {$::cmd_name eq "test4"} {
emit_hook_log
return -code 2 "TH_RETURN return code"
} elseif {$::cmd_name eq "timeline"} {
if {$::cmd_args eq "custom"} {
emit_hook_log
return "custom timeline"
} else {
emit_hook_log
error "unsupported timeline"
}
}
}
proc command_notify {} {
append_hook_log command_notify " " $::cmd_name
emit_hook_log
}
proc webpage_hook {} {
append_hook_log webpage_hook " " $::web_name
if {$::web_name eq "test1"} {
puts [repository]; continue
}
}
proc webpage_notify {} {
append_hook_log webpage_notify " " $::web_name
emit_hook_log
}
}
###############################################################################
set data [fossil info]
regexp -line -- {^repository: (.*)$} $data dummy repository
if {[string length $repository] == 0 || ![file exists $repository]} then {
error "unable to locate repository"
}
###############################################################################
saveTh1SetupFile; writeTh1SetupFile $testTh1Setup
###############################################################################
fossil timeline custom; # NOTE: Bad "WHEN" argument.
test th1-cmd-hooks-1a {[string map [list \r\n \n] [string trim $RESULT]] eq {<h1><b>command_hook timeline</b></h1>
ERROR: unsupported timeline
+++ no more data (0) +++
<h1><b>command_hook timeline command_notify timeline</b></h1>}}
###############################################################################
fossil timeline
test th1-cmd-hooks-2a {[first_data_line] eq {<h1><b>command_hook timeline</b></h1>}}
test th1-cmd-hooks-2b {[second_data_line] eq {ERROR: unsupported timeline}}
test th1-cmd-hooks-2c {[regexp -- {=== \d{4}-\d{2}-\d{2} ===} [third_data_line]]}
test th1-cmd-hooks-2d {[last_data_line] eq {<h1><b>command_hook timeline command_notify timeline</b></h1>}}
###############################################################################
fossil test1
test th1-custom-cmd-1a {[next_to_last_data_line] eq $repository}
test th1-custom-cmd-1b {[last_data_line] eq {<h1><b>command_hook test1 command_notify test1</b></h1>}}
###############################################################################
fossil test2
test th1-custom-cmd-2a {[first_data_line] eq {ERROR: unsupported command}}
###############################################################################
fossil test3
test th1-custom-cmd-3a {[string trim $RESULT] eq {<h1><b>command_hook test3</b></h1>}}
###############################################################################
fossil test4
test th1-custom-cmd-4a {[string trim $RESULT] eq {<h1><b>command_hook test4</b></h1>}}
###############################################################################
set RESULT [fossil_th1_hook_http $repository /timeline]
test th1-web-hooks-1a {[regexp {<title>Fossil: Timeline</title>} $RESULT]}
test th1-web-hooks-1b {[regexp {<h1><b>command_hook http webpage_hook timeline webpage_notify timeline</b></h1>} $RESULT]}
###############################################################################
set RESULT [fossil_th1_hook_http $repository /test1]
test th1-custom-web-1a {[next_to_last_data_line] eq $repository}
test th1-custom-web-1b {[last_data_line] eq {<h1><b>command_hook http webpage_hook test1 webpage_notify test1</b></h1>}}
###############################################################################
restoreTh1SetupFile
|
Changes to test/utf.test.
| ︙ | ︙ | |||
14 15 16 17 18 19 20 | # http://www.hwaci.com/drh/ # ############################################################################ # # Test UTF-8/UTF-16 detection # | < < < < | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# http://www.hwaci.com/drh/
#
############################################################################
#
# Test UTF-8/UTF-16 detection
#
proc swap_byte_order {str} {
set result ""
for {set i 0} {$i < [string length $str]} {incr i} {
set c [scan [string index $str $i] %c]
set c [expr {(($c << 8) & 0xFF00) | (($c >> 8) & 0xFF)}]
append result [format %c $c]
}
|
| ︙ | ︙ | |||
313 314 315 316 317 318 319 |
incr fn
}
}
}
flush $f; close $f
}
| < < < < < < < | 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
incr fn
}
}
}
flush $f; close $f
}
createTestFiles $tempPath 100
# createTestResults $tempPath 100
########################### BEGIN GENERATED SECTION ###########################
utf-check 100 utf-check-100-0-0-0.jnk \
{File "%TEMP%/utf-check-100-0-0-0.jnk" has 0 bytes.
Starts with UTF-8 BOM: no
|
| ︙ | ︙ |