Fossil SCM

fossil-scm / test / regress.test
Blame History Raw 287 lines
1
#
2
# Copyright (c) 2026 Dan Mestas
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
############################################################################
13
#
14
# Tests of single faults that have no better home.
15
#
16
17
require_no_open_checkout
18
19
test_setup
20
21
write_file a.txt "a\n"
22
fossil add a.txt
23
fossil commit -m "regress-c1"
24
25
###############################################################################
26
# "fossil test-dir-list" on an empty directory, and on one that does not
27
# exist.
28
29
file mkdir empty-directory
30
fossil test-dir-list empty-directory
31
test regress-dir-list-empty {$CODE == 0}
32
fossil test-dir-list no-such-directory
33
test regress-dir-list-missing {$CODE == 0}
34
35
###############################################################################
36
# "fossil test-xfer" answers a request, with no robot captcha.
37
38
write_file request.txt $CLIENT_VERSION_CARD
39
fossil test-xfer request.txt
40
test regress-test-xfer {$CODE == 0}
41
test_match regress-test-xfer-reply $RESULT {# timestamp}
42
43
###############################################################################
44
# A branch name shorter than "date:" is looked up without reading past its
45
# end. A fault here shows only in a build with run-time checking.
46
47
fossil branch new br trunk
48
fossil update br
49
test regress-short-branch-name {$CODE == 0}
50
fossil update trunk
51
52
###############################################################################
53
# An HTML comment or an HR tag followed by spaces and no newline. The
54
# Markdown translator must not copy a byte from past the end of its input,
55
# so the output has no NUL.
56
57
foreach {regressName regressText} {
58
hr "<hr> "
59
comment "<!-- x --> "
60
quoted "> <hr> "
61
} {
62
write_file md-$regressName.md $regressText
63
fossil_raw test-markdown-render md-$regressName.md
64
test regress-markdown-html-block-$regressName \
65
{$CODE == 0 && [string first \x00 $RESULT] < 0}
66
}
67
68
###############################################################################
69
# "fossil import --svn" with property blocks whose lengths do not fit the
70
# dump file: a block too short for its end marker, negative lengths and
71
# oversized ones. Each import must stop with an error about the svn-dump
72
# data, and a sound dump must import.
73
74
proc regress_svn_rev {number props} {
75
set length [string length $props]
76
set head "Revision-number: $number\nProp-content-length: $length\n"
77
return "${head}Content-length: $length\n\n$props\n"
78
}
79
80
proc regress_svn_props {props} {
81
set block ""
82
foreach {name value} $props {
83
append block "K [string length $name]\n$name\n"
84
append block "V [string length $value]\n$value\n"
85
}
86
return "${block}PROPS-END\n"
87
}
88
89
# Each import has a time limit of 60 seconds, so that an endless loop
90
# fails the test.
91
set regressSvnHead "SVN-fs-dump-format-version: 2\n\nUUID: 0\n\n"
92
foreach {regressName regressProps} {
93
short-block "abcd\n"
94
negative-delete "D -6\nxxxxxxxxxxxxxxxx\nPROPS-END\n"
95
oversized-key "K 5000\nab\nV 1\nx\nPROPS-END\n"
96
oversized-value "K 2\nab\nV 99999\nx\nPROPS-END\n"
97
negative-value "K 2\nab\nV -40\nx\nPROPS-END\n"
98
} {
99
write_file svn-$regressName.dump \
100
$regressSvnHead[regress_svn_rev 0 $regressProps]
101
fossil_raw -seconds 60 import --svn svn-$regressName.fossil \
102
svn-$regressName.dump
103
test regress-svn-import-$regressName \
104
{$CODE == 1 && [string match "*svn-dump data*" $RESULT]}
105
}
106
107
set regressSvnDate {svn:date 2026-01-01T00:00:00.000000Z}
108
set regressSvnSound $regressSvnHead
109
append regressSvnSound [regress_svn_rev 0 [regress_svn_props $regressSvnDate]]
110
append regressSvnSound [regress_svn_rev 1 [regress_svn_props \
111
[concat {svn:log first svn:author dan} $regressSvnDate]]]
112
write_file svn-sound.dump $regressSvnSound
113
fossil import --svn svn-sound.fossil svn-sound.dump
114
test regress-svn-import-sound {$CODE == 0}
115
116
###############################################################################
117
# Two more malformed property blocks for "fossil import --svn": one with a
118
# NUL byte in it, and one whose length is negative. Each is refused.
119
120
write_file svn-nul-in-block.dump \
121
$regressSvnHead[regress_svn_rev 0 "K\x00\x00\x00PROPS-END\n"]
122
set regressSvnNegative "Revision-number: 0\nProp-content-length: -5\n"
123
append regressSvnNegative "Content-length: 10\n\nPROPS-END\n\n"
124
write_file svn-negative-block.dump $regressSvnHead$regressSvnNegative
125
foreach regressName {nul-in-block negative-block} {
126
fossil_raw -seconds 60 import --svn svn-$regressName.fossil \
127
svn-$regressName.dump
128
test regress-svn-import-$regressName \
129
{$CODE == 1 && [string match "*svn-dump data format broken*" $RESULT]}
130
}
131
132
###############################################################################
133
# A Markdown header that holds an HTML comment is read within its bounds
134
# when its id is made. A fault here shows only in a build with run-time
135
# checking.
136
137
write_file md-header.md "intro\n\n# a <!-- -->\n"
138
fossil test-markdown-render md-header.md
139
test regress-markdown-header-comment \
140
{$CODE == 0 && [string first {<h1 id="a">} $RESULT] >= 0}
141
142
###############################################################################
143
# The name of a file in a sibling directory, relative to the current
144
# directory. A fault here shows only in a build with run-time checking.
145
146
file mkdir rel/b rel/c-with-a-longer-name/sub
147
fossil test-relative-name --chdir rel/b ../c-with-a-longer-name/sub/file.txt
148
test regress-relative-name-sibling \
149
{$CODE == 0
150
&& [string trim $RESULT] eq "../c-with-a-longer-name/sub/file.txt"}
151
fossil test-relative-name --slash --chdir rel/b ../c-with-a-longer-name/sub/
152
test regress-relative-name-sibling-slash \
153
{$CODE == 0 && [string trim $RESULT] eq "../c-with-a-longer-name/sub/"}
154
155
###############################################################################
156
# The names of the files in a merge conflict are put into the
157
# gmerge-command as they are, inside the double quotes that the setting
158
# has around them. For a name with a double quote, a dollar sign or a
159
# backquote the tool is left out, with a warning, and the conflict stays
160
# marked in the file. The merge tool here is
161
# standin/log-args.sh, which records its arguments and resolves nothing.
162
163
if {$::tcl_platform(platform) ne "windows"} {
164
set regressTop [pwd]
165
set regressTool [test_standin log-args.sh [file join $regressTop gmerge.sh]]
166
set regressToolLog [file join $regressTop gmerge-args.txt]
167
set ::env(ARGS_LOG) $regressToolLog
168
foreach {regressName regressFile regressRuns} {
169
plain plain.txt 1
170
space {sp ace.txt} 1
171
quote {a" "b.txt} 0
172
dollar {a$b.txt} 0
173
backquote {a`x`b.txt} 0
174
} {
175
file mkdir gmerge-$regressName
176
cd gmerge-$regressName
177
fossil init r.fossil
178
fossil open r.fossil --nested
179
write_file $regressFile "one\ntwo\nthree\n"
180
fossil add $regressFile
181
fossil commit -m base --no-warnings
182
write_file $regressFile "one\nTWO-branch\nthree\n"
183
fossil commit -m branch --branch br --no-warnings
184
fossil update trunk
185
write_file $regressFile "one\nTWO-trunk\nthree\n"
186
fossil commit -m trunk --no-warnings
187
fossil settings gmerge-command \
188
"$regressTool \"%baseline\" \"%original\" \"%merge\" \"%output\""
189
file delete $regressToolLog
190
fossil_raw merge br
191
set regressArgs 0
192
if {[file exists $regressToolLog]} {
193
set regressArgs \
194
[llength [split [string trim [read_file $regressToolLog]] \n]]
195
}
196
set regressMarked \
197
[expr {[string first "<<<<<<<" [read_file $regressFile]] >= 0}]
198
set regressWarned \
199
[expr {[string first "not running the gmerge-command" $RESULT] >= 0}]
200
test regress-gmerge-$regressName \
201
{$CODE == 0 && $regressMarked && $regressArgs == 4*$regressRuns
202
&& $regressWarned != $regressRuns}
203
fossil close --force
204
cd $regressTop
205
}
206
unset ::env(ARGS_LOG)
207
}
208
209
###############################################################################
210
# A port number above 65535 in a URL is refused with an error.
211
212
fossil remote http://example.invalid:99999999999/x -expectError
213
test regress-url-port-too-large {$CODE != 0
214
&& [string match "*port number too large*" $RESULT]}
215
fossil remote http://example.invalid:65535/x
216
test regress-url-port-largest {$CODE == 0}
217
fossil remote off
218
219
###############################################################################
220
# "fossil ticket add" and "ticket set" with plain fields, a field to
221
# append to, and a private field. The change artifact lists the cards that
222
# append before the cards that assign, and the private value is stored
223
# concealed.
224
225
fossil ticket add title "A ticket" status Open comment first
226
test regress-ticket-add {$CODE == 0}
227
fossil sql "SELECT tkt_uuid FROM ticket WHERE title='A ticket'"
228
set regressTkt [string trim $RESULT]
229
fossil ticket set $regressTkt status Closed +comment " second" \
230
private_contact [email protected]
231
test regress-ticket-set {$CODE == 0}
232
fossil sql "SELECT status, comment FROM ticket WHERE tkt_uuid='$regressTkt'"
233
test_eq regress-ticket-set-fields [string trim $RESULT] "Closed|first second"
234
fossil sql "SELECT private_contact FROM ticket WHERE tkt_uuid='$regressTkt'"
235
test regress-ticket-private-concealed \
236
{[string trim $RESULT] ne "" && ![string match "*someone*" $RESULT]}
237
fossil sql "SELECT uuid FROM blob, event WHERE objid=rid AND type='t'
238
ORDER BY mtime DESC LIMIT 1"
239
fossil artifact [string trim $RESULT]
240
set regressTktCards [regexp -all -inline -line {^J \+?\S+} $RESULT]
241
test regress-ticket-append-first \
242
{[lindex $regressTktCards 0] eq "J +comment"
243
&& "J status" in $regressTktCards
244
&& "J private_contact" in $regressTktCards}
245
246
###############################################################################
247
# A push into a clone that already holds a wiki attachment succeeds, and
248
# the clone keeps one attachment row for it.
249
250
write_file attach.txt "attached\n"
251
write_file wiki.txt "wiki\n"
252
fossil wiki create AttachPage wiki.txt
253
fossil attachment add AttachPage attach.txt
254
fossil clone .rep.fossil regress-attach-clone.fossil
255
fossil push regress-attach-clone.fossil --once
256
test regress-push-held-attachment {$CODE == 0
257
&& ![string match "*UNIQUE constraint*" $RESULT]}
258
fossil sql -R regress-attach-clone.fossil \
259
"SELECT count(*) FROM attachment WHERE target='AttachPage'"
260
test_eq regress-push-held-attachment-rows [string trim $RESULT] 1
261
262
###############################################################################
263
# The TH1 command styleHeader run from the command line writes the page
264
# header, whatever the robot-restrict setting.
265
266
foreach {regressName regressRobot} {unset {} list timelineX,diff all *} {
267
fossil settings robot-restrict $regressRobot
268
fossil_raw test-th-eval --open-config {styleHeader {Page Title}}
269
test regress-styleheader-cli-$regressName \
270
{$CODE == 0 && [string match "*<title>*: Page Title</title>*" $RESULT]}
271
}
272
fossil settings robot-restrict ""
273
274
###############################################################################
275
# A base URL given with --baseurl and no path, with or without a slash after
276
# the host, serves pages at the root. A fault here shows only in a build
277
# with run-time checking.
278
279
write_file baseurl-req.txt "GET /robots.txt HTTP/1.1\r\nHost: x\r\n\r\n"
280
foreach {regressName regressUrl} {bare https://x slash https://x/} {
281
fossil_raw http .rep.fossil --in baseurl-req.txt --baseurl $regressUrl
282
test regress-baseurl-no-path-$regressName \
283
{$CODE == 0 && [string match "HTTP/1.0 200*" $RESULT]}
284
}
285
286
test_cleanup
287

Keyboard Shortcuts

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