Fossil SCM

fossil-scm / test / th1-hooks.test
Blame History Raw 238 lines
1
#
2
# Copyright (c) 2011 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
# TH1 Hooks
19
#
20
21
fossil test-th-eval "hasfeature th1Hooks"
22
23
if {[normalize_result] ne "1"} {
24
puts "Fossil was not compiled with TH1 hooks support."
25
test_cleanup_then_return
26
}
27
28
###############################################################################
29
30
test_setup
31
32
###############################################################################
33
34
write_file f1 "f1"; fossil add f1; fossil commit -m "c1"
35
36
###############################################################################
37
38
set env(TH1_ENABLE_HOOKS) 1; # TH1 hooks must be enabled for this test.
39
40
###############################################################################
41
42
set testTh1Setup {
43
proc initialize_hook_log {} {
44
if {![info exists ::hook_log]} {
45
set ::hook_log ""
46
}
47
}
48
49
proc append_hook_log { args } {
50
initialize_hook_log
51
if {[string length $::hook_log] > 0} {
52
set ::hook_log "$::hook_log "
53
}
54
for {set i 0} {$i < [llength $args]} {set i [expr {$i + 1}]} {
55
set ::hook_log $::hook_log[lindex $args $i]
56
}
57
}
58
59
proc emit_hook_log {} {
60
initialize_hook_log
61
html "\n<h1><b>$::hook_log</b></h1>\n"
62
}
63
64
proc command_hook {} {
65
append_hook_log command_hook " " $::cmd_name
66
if {$::cmd_name eq "test1"} {
67
puts [repository]; continue
68
} elseif {$::cmd_name eq "test2"} {
69
error "unsupported command"
70
} elseif {$::cmd_name eq "test3"} {
71
emit_hook_log
72
break "TH_BREAK return code"
73
} elseif {$::cmd_name eq "test4"} {
74
emit_hook_log
75
return -code 5 "TH_RETURN return code"
76
} elseif {$::cmd_name eq "timeline"} {
77
set length [llength $::cmd_args]
78
set length [expr {$length - 1}]
79
if {[lindex $::cmd_args $length] eq "custom"} {
80
append_hook_log "CUSTOM TIMELINE"
81
emit_hook_log
82
return "custom timeline"
83
} elseif {[lindex $::cmd_args $length] eq "custom2"} {
84
emit_hook_log
85
puts "+++ some stuff here +++"
86
continue "custom2 timeline"
87
} elseif {[lindex $::cmd_args $length] eq "custom3"} {
88
emit_hook_log
89
return -code 5 "TH_RETURN return code"
90
} elseif {[lindex $::cmd_args $length] eq "now"} {
91
emit_hook_log
92
return "now timeline"
93
} else {
94
emit_hook_log
95
error "unsupported timeline"
96
}
97
}
98
}
99
100
proc command_notify {} {
101
append_hook_log command_notify " " $::cmd_name
102
emit_hook_log
103
}
104
105
proc webpage_hook {} {
106
append_hook_log webpage_hook " " $::web_name
107
if {$::web_name eq "test1"} {
108
puts [repository]; continue
109
}
110
}
111
112
proc webpage_notify {} {
113
append_hook_log webpage_notify " " $::web_name
114
emit_hook_log
115
}
116
}
117
118
###############################################################################
119
120
set data [fossil info]
121
regexp -line -- {^repository: (.*)$} $data dummy repository
122
123
if {[string length $repository] == 0 || ![file exists $repository]} {
124
error "unable to locate repository"
125
}
126
127
set dataFileName [file join $::testdir th1-hooks-input.txt]
128
129
###############################################################################
130
131
set savedTh1Setup [fossil settings th1-setup]
132
fossil settings th1-setup $testTh1Setup
133
134
###############################################################################
135
136
fossil timeline custom -expectError; # NOTE: Bad "WHEN" argument.
137
test th1-cmd-hooks-1a {[normalize_result] eq \
138
{<h1><b>command_hook timeline CUSTOM TIMELINE</b></h1>
139
unknown check-in or invalid date: custom}}
140
141
###############################################################################
142
143
fossil timeline custom2; # NOTE: Bad "WHEN" argument.
144
test th1-cmd-hooks-1b {[normalize_result] eq \
145
{<h1><b>command_hook timeline</b></h1>
146
+++ some stuff here +++
147
<h1><b>command_hook timeline command_notify timeline</b></h1>}}
148
149
###############################################################################
150
151
fossil timeline custom3 -expectError; # NOTE: Bad "WHEN" argument.
152
153
test th1-cmd-hooks-1c {[normalize_result] eq \
154
{<h1><b>command_hook timeline</b></h1>
155
unknown check-in or invalid date: custom3}}
156
157
###############################################################################
158
159
fossil timeline
160
test th1-cmd-hooks-2a {[first_data_line] eq \
161
{<h1><b>command_hook timeline</b></h1>}}
162
163
test th1-cmd-hooks-2b {[second_data_line] eq {ERROR: unsupported timeline}}
164
165
###############################################################################
166
167
fossil timeline -n -1 now
168
test th1-cmd-hooks-3a {[first_data_line] eq \
169
{<h1><b>command_hook timeline</b></h1>}}
170
171
test th1-cmd-hooks-3b \
172
{[regexp -- {=== \d{4}-\d{2}-\d{2} ===} [second_data_line]]}
173
174
test th1-cmd-hooks-3c \
175
{[regexp -- {--- line limit \(\d+\) reached ---} [third_to_last_data_line]]}
176
177
test th1-cmd-hooks-3d {[last_data_line] eq \
178
{<h1><b>command_hook timeline command_notify timeline</b></h1>}}
179
180
###############################################################################
181
182
fossil test1
183
test th1-custom-cmd-1a {[next_to_last_data_line] eq $repository}
184
185
test th1-custom-cmd-1b {[last_data_line] eq \
186
{<h1><b>command_hook test1 command_notify test1</b></h1>}}
187
188
###############################################################################
189
190
fossil test2
191
test th1-custom-cmd-2a {[first_data_line] eq {ERROR: unsupported command}}
192
193
###############################################################################
194
195
fossil test3
196
test th1-custom-cmd-3a {[string trim $RESULT] eq \
197
{<h1><b>command_hook test3</b></h1>}}
198
199
###############################################################################
200
201
fossil test4 -expectError
202
203
test th1-custom-cmd-4a {[first_data_line] eq \
204
{<h1><b>command_hook test4</b></h1>}}
205
206
test th1-custom-cmd-4b {[regexp -- \
207
{: unknown command: test4$} [second_data_line]]}
208
209
test th1-custom-cmd-4d {[regexp -- \
210
{: use "help" for more information$} [third_data_line]]}
211
212
###############################################################################
213
214
set RESULT [test_fossil_http $repository $dataFileName /timeline]
215
216
test th1-web-hooks-1a {[regexp \
217
{<title>Unnamed Fossil Project: Timeline</title>} $RESULT]}
218
219
test th1-web-hooks-1b {[regexp [appendArgs \
220
{<h1><b>command_hook http webpage_hook timeline} " " \
221
{webpage_notify timeline</b></h1>}] $RESULT]}
222
223
###############################################################################
224
225
set RESULT [test_fossil_http $repository $dataFileName /test1]
226
test th1-custom-web-1a {[next_to_last_data_line] eq $repository}
227
228
test th1-custom-web-1b {[last_data_line] eq \
229
{<h1><b>command_hook http webpage_hook test1 webpage_notify test1</b></h1>}}
230
231
###############################################################################
232
233
fossil settings th1-setup $savedTh1Setup
234
235
###############################################################################
236
237
test_cleanup
238

Keyboard Shortcuts

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