Fossil SCM

fossil-scm / test / blob.test
Blame History Raw 1021 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
# The buffer type that all of Fossil's text handling is built on:
15
# src/blob.c. The test commands that run its routines directly
16
# (test-isspace, test-atoi, test-strip-comment-lines, test-compress,
17
# test-compress-2, test-uncompress, test-cycle-compress, test-escaped-arg),
18
# reading and writing files, and the routines that are reached only
19
# through other commands: the string literals of "diff --json" and
20
# "diff --tcl", and the conversions that a commit offers for a file in
21
# another encoding.
22
#
23
24
# The first sections run at every level, and the rest need
25
# -assurance stress.
26
require_no_open_checkout
27
28
test_setup
29
30
# The bytes that the hexadecimal digits in $hex stand for.
31
#
32
proc blob_bytes {hex} {
33
return [binary format H* $hex]
34
}
35
36
# The hexadecimal digits for the bytes in $bytes.
37
#
38
proc blob_hex {bytes} {
39
binary scan $bytes H* hex
40
return $hex
41
}
42
43
###############################################################################
44
# test-isspace checks fossil_isspace() against every byte value.
45
46
fossil test-isspace
47
test_eq blob-isspace-1 [string trim $RESULT] "All 256 characters OK"
48
49
###############################################################################
50
# test-atoi prints, for each argument, whether it is a non-negative
51
# integer of 32 bits and of 64 bits, and the value. Each row: the
52
# argument, then the two answers and values that must be printed.
53
54
foreach {blobName blobArg blobOk32 blobVal32 blobOk64 blobVal64} {
55
zero 0 1 0 1 0
56
one 1 1 1 1 1
57
leading-0 0000000000000000000042 1 42 1 42
58
max32 2147483647 1 2147483647 1 2147483647
59
over32 2147483648 0 0 1 2147483648
60
ten-digits 9999999999 0 0 1 9999999999
61
max64 9223372036854775807 0 0 1 9223372036854775807
62
over64 9223372036854775808 0 0 0 0
63
over64-tens 9223372036854775810 0 0 0 0
64
under64-tens 9223372036854775799 0 0 1 9223372036854775799
65
twenty 10000000000000000000 0 0 0 0
66
very-long 123456789012345678901234567890 0 0 0 0
67
negative -1 0 0 0 0
68
plus +1 0 0 0 0
69
space-first { 1} 0 0 0 0
70
space-last {1 } 0 0 0 0
71
letter-last 12x 0 0 0 0
72
letter-first x12 0 0 0 0
73
hex 0x10 0 0 0 0
74
colon 1: 0 0 0 0
75
slash 1/ 0 0 0 0
76
point 1.5 0 0 0 0
77
} {
78
fossil test-atoi $blobArg
79
set blobGot [regexp {: 32-bit (\d) (\d+) +64-bit (\d) (\d+)$} \
80
[string trim $RESULT] -> blobA blobB blobC blobD]
81
test blob-atoi-$blobName {$blobGot && $blobA == $blobOk32 &&
82
$blobB eq $blobVal32 && $blobC == $blobOk64 && $blobD eq $blobVal64}
83
}
84
85
# With no argument test-atoi prints nothing, and with three it prints
86
# three lines.
87
fossil test-atoi
88
test blob-atoi-none {$RESULT eq ""}
89
fossil test-atoi 1 2 3
90
test blob-atoi-three {[llength [split [string trim $RESULT] \n]] == 3}
91
92
###############################################################################
93
# test-strip-comment-lines removes the lines that begin with "#" and
94
# takes the backslash from the lines that begin with "\#". Each row: the
95
# content of the file and what must be printed.
96
97
foreach {blobName blobIn blobOut} {
98
empty {} {}
99
plain "a\nb\n" "a\nb\n"
100
no-newline "a\nb" "a\nb"
101
comment "a\n#b\nc\n" "a\nc\n"
102
comment-first "#a\nb\n" "b\n"
103
comment-last "a\n#b" "a\n"
104
comment-only "#a" {}
105
comments-only "#a\n#b\n" {}
106
hash-inside "a#b\n #c\n" "a#b\n #c\n"
107
escaped "\\#a\nb\n" "#a\nb\n"
108
escaped-last "a\n\\#b" "a\n#b"
109
escaped-only "\\#" "#"
110
backslash "\\a\n\\\n" "\\a\n\\\n"
111
backslash-end "a\n\\" "a\n\\"
112
two-backslash "\\\\#a\n" "\\\\#a\n"
113
blank-lines "\n\n#\n\n" "\n\n\n"
114
crlf "a\r\n#b\r\nc\r\n" "a\r\nc\r\n"
115
nul-bytes "a\x00#b\n#c\x00\nd" "a\x00#b\nd"
116
only-newlines "\n\n" "\n\n"
117
} {
118
write_file strip-$blobName.txt $blobIn
119
fossil_raw test-strip-comment-lines strip-$blobName.txt
120
test blob-strip-$blobName {$CODE == 0 && $RESULT eq $blobOut}
121
}
122
123
# A line of 100,000 bytes is kept whole, and a comment of that length is
124
# removed whole.
125
set blobLong [string repeat x 100000]
126
write_file strip-long.txt "$blobLong\n#$blobLong\n\\#$blobLong"
127
fossil_raw test-strip-comment-lines strip-long.txt
128
test blob-strip-long {$CODE == 0 && $RESULT eq "$blobLong\n#$blobLong"}
129
130
# The file is read from standard input when its name is "-" or empty.
131
fossil_raw -input "a\n#b\nc\n" test-strip-comment-lines -
132
test blob-strip-stdin-dash {$CODE == 0 && $RESULT eq "a\nc\n"}
133
fossil_raw -input "#b\nc" test-strip-comment-lines {}
134
test blob-strip-stdin-empty-name {$CODE == 0 && $RESULT eq "c"}
135
fossil_raw -input "" test-strip-comment-lines -
136
test blob-strip-stdin-nothing {$CODE == 0 && $RESULT eq ""}
137
set blobBig [string repeat "line of text\n" 2000]
138
fossil_raw -input "#x\n$blobBig" test-strip-comment-lines -
139
test blob-strip-stdin-big {$CODE == 0 && $RESULT eq $blobBig}
140
141
# --side-by-side shows the file beside what is left of it, and --width
142
# sets the width of each side. A width that is not positive is ignored.
143
write_file strip-sbs.txt "keep\n#drop\n\\#bare\n"
144
fossil_raw test-strip-comment-lines --side-by-side strip-sbs.txt
145
test blob-strip-sbs {$CODE == 0 &&
146
[regexp {1 keep +1 keep} $RESULT] && [regexp {2 #drop +<} $RESULT] &&
147
[regexp {3 \\#bare +\| +2 #bare} $RESULT]}
148
set blobWide [string length [lindex [split $RESULT \n] 0]]
149
fossil_raw test-strip-comment-lines -y -W 20 strip-sbs.txt
150
set blobNarrow [string length [lindex [split $RESULT \n] 0]]
151
test blob-strip-sbs-width {$CODE == 0 && $blobNarrow < $blobWide &&
152
[regexp {1 keep +1 keep} $RESULT]}
153
foreach blobWidth {0 -5 x} {
154
fossil_raw test-strip-comment-lines -y -W $blobWidth strip-sbs.txt
155
test blob-strip-sbs-width-$blobWidth {$CODE == 0 &&
156
[string length [lindex [split $RESULT \n] 0]] == $blobWide}
157
}
158
159
# The command takes exactly one file.
160
fossil_raw test-strip-comment-lines
161
test blob-strip-usage-none \
162
{$CODE == 1 && [string match "Usage:*INPUTFILE*" $RESULT]}
163
fossil_raw test-strip-comment-lines strip-sbs.txt strip-sbs.txt
164
test blob-strip-usage-two {$CODE == 1 && [string match "Usage:*INPUTFILE*" \
165
$RESULT]}
166
167
###############################################################################
168
# Reading a file. A file that is not there and a file that cannot be
169
# opened are errors that name the file.
170
171
fossil_raw test-strip-comment-lines no-such-file.txt
172
test blob-read-missing {$CODE == 1 &&
173
[string match "*no such file: no-such-file.txt*" $RESULT]}
174
175
if {$::tcl_platform(platform) eq "unix" && $::tcl_platform(user) ne "root"} {
176
write_file read-closed.txt "text\n"
177
file attributes read-closed.txt -permissions 0000
178
fossil_raw test-strip-comment-lines read-closed.txt
179
test blob-read-unreadable {$CODE == 1 &&
180
[string match "*cannot open read-closed.txt for reading*" $RESULT]}
181
file attributes read-closed.txt -permissions 0644
182
}
183
184
# Outside a repository a symbolic link is followed to its file.
185
if {$::tcl_platform(platform) eq "unix"} {
186
write_file read-target.txt "target\n#gone\n"
187
file link -symbolic read-link.txt read-target.txt
188
fossil_raw test-strip-comment-lines read-link.txt
189
test blob-read-link-followed {$CODE == 0 && $RESULT eq "target\n"}
190
write_file read-gone.txt "soon gone\n"
191
file link -symbolic read-dangling.txt read-gone.txt
192
file delete read-gone.txt
193
fossil_raw test-strip-comment-lines read-dangling.txt
194
test blob-read-link-dangling {$CODE == 1 &&
195
[string match "*no such file: read-dangling.txt*" $RESULT]}
196
}
197
198
# A name that begins with "-" and is longer is the name of a file.
199
write_file -dash.txt "dash\n#gone\n"
200
fossil_raw test-cycle-compress -dash.txt
201
test blob-read-dash-name {$CODE == 0 && $RESULT eq "ok\n"}
202
fossil_raw test-compress -dash.txt -dash.z
203
test blob-write-dash-name {$CODE == 0 && $RESULT eq "" &&
204
[zlib decompress [string range [read_file -dash.z] 4 end]] eq
205
"dash\n#gone\n"}
206
207
# A directory read as a file has no content.
208
if {$::tcl_platform(platform) eq "unix"} {
209
file mkdir read-directory
210
fossil_raw test-strip-comment-lines read-directory
211
test blob-read-directory {$CODE == 0 && $RESULT eq ""}
212
}
213
214
# test-safe-html prints an empty file as an empty line.
215
write_file read-empty.html ""
216
fossil_raw test-safe-html read-empty.html
217
test blob-read-empty-terminated {$CODE == 0 && $RESULT eq "\n"}
218
219
###############################################################################
220
# test-compress writes the size of the content as four bytes, high byte
221
# first, and then the content as zlib compresses it. test-uncompress
222
# turns that back into the content. Each row: a name and the content.
223
224
foreach {blobName blobContent} [list \
225
empty {} \
226
one-byte x \
227
text "some text\nwith two lines\n" \
228
nul-bytes "a\x00b\x00\x00c" \
229
repeats [string repeat "0123456789" 30000] \
230
bytes [blob_bytes [string repeat 00ff7f80c3a9 500]] \
231
] {
232
set blobSize [string length $blobContent]
233
write_file z-$blobName.in $blobContent
234
fossil_raw test-compress z-$blobName.in z-$blobName.z
235
set blobZ [read_file z-$blobName.z]
236
test blob-compress-$blobName {$CODE == 0 && $RESULT eq "" &&
237
[string range $blobZ 0 3] eq [binary format I $blobSize] &&
238
[zlib decompress [string range $blobZ 4 end]] eq $blobContent}
239
fossil_raw test-uncompress z-$blobName.z z-$blobName.out
240
test blob-uncompress-$blobName {$CODE == 0 && $RESULT eq "" &&
241
[read_file z-$blobName.out] eq $blobContent}
242
}
243
244
# The 300,000 bytes of repeated digits compress to less than a hundredth.
245
test blob-compress-shrinks {[file size z-repeats.z] < 3000}
246
247
# test-compress-2 compresses two files as one. Each row: the two
248
# contents.
249
foreach {blobName blobOne blobTwo} [list \
250
both-empty {} {} \
251
first-empty {} "second\n" \
252
second-empty "first\n" {} \
253
text "first\n" "second\n" \
254
large [string repeat "abc\n" 50000] [string repeat "xyz\n" 50000] \
255
] {
256
write_file z2-$blobName.1 $blobOne
257
write_file z2-$blobName.2 $blobTwo
258
set blobSize [string length $blobOne$blobTwo]
259
fossil_raw test-compress-2 z2-$blobName.1 z2-$blobName.2 z2-$blobName.z
260
set blobZ [read_file z2-$blobName.z]
261
test blob-compress2-$blobName {$CODE == 0 && $RESULT eq "" &&
262
[string range $blobZ 0 3] eq [binary format I $blobSize] &&
263
[zlib decompress [string range $blobZ 4 end]] eq "$blobOne$blobTwo"}
264
fossil_raw test-uncompress z2-$blobName.z z2-$blobName.out
265
test blob-uncompress2-$blobName {$CODE == 0 &&
266
[read_file z2-$blobName.out] eq "$blobOne$blobTwo"}
267
}
268
269
# test-cycle-compress compresses each file, uncompresses the result and
270
# compares it with the file.
271
fossil_raw test-cycle-compress z-text.in z-nul-bytes.in z-repeats.in z-bytes.in
272
test blob-cycle-compress {$CODE == 0 && $RESULT eq "ok\n"}
273
fossil_raw test-cycle-compress
274
test blob-cycle-compress-none {$CODE == 0 && $RESULT eq "ok\n"}
275
fossil_raw test-cycle-compress z-text.in no-such-file.txt
276
test blob-cycle-compress-missing {$CODE == 1 &&
277
[string match "*no such file: no-such-file.txt*" $RESULT]}
278
279
# Each of the three commands wants an exact number of file names.
280
foreach {blobName blobCommand blobUsage} {
281
compress-0 {test-compress} "INPUTFILE OUTPUTFILE"
282
compress-1 {test-compress z-text.in} "INPUTFILE OUTPUTFILE"
283
compress-3 {test-compress z-text.in a b} "INPUTFILE OUTPUTFILE"
284
compress2-0 {test-compress-2}
285
"INPUTFILE1 INPUTFILE2 OUTPUTFILE"
286
compress2-2 {test-compress-2 z-text.in a}
287
"INPUTFILE1 INPUTFILE2 OUTPUTFILE"
288
compress2-4 {test-compress-2 z-text.in a b c}
289
"INPUTFILE1 INPUTFILE2 OUTPUTFILE"
290
uncompress-0 {test-uncompress} "INPUTFILE OUTPUTFILE"
291
uncompress-1 {test-uncompress z-text.z} "INPUTFILE OUTPUTFILE"
292
uncompress-3 {test-uncompress z-text.z a b} "INPUTFILE OUTPUTFILE"
293
} {
294
fossil_raw {*}$blobCommand
295
test blob-usage-$blobName {$CODE == 1 &&
296
[string match "Usage:*$blobUsage*" $RESULT] &&
297
![file exists a] && ![file exists b] && ![file exists c]}
298
}
299
300
###############################################################################
301
# Writing a file. The output goes to standard output when the name is
302
# "-" or empty, directories on the way to the file are made, and a file
303
# that cannot be made is an error that names it.
304
305
fossil_raw test-compress z-text.in -
306
test blob-write-stdout-dash {$CODE == 0 && $RESULT eq [read_file z-text.z]}
307
fossil_raw test-compress z-text.in {}
308
test blob-write-stdout-empty-name \
309
{$CODE == 0 && $RESULT eq [read_file z-text.z]}
310
fossil_raw test-uncompress z-empty.z -
311
test blob-write-stdout-nothing {$CODE == 0 && $RESULT eq ""}
312
fossil_raw test-uncompress z-empty.z write-empty.out
313
test blob-write-empty-file {$CODE == 0 && [file exists write-empty.out] &&
314
[file size write-empty.out] == 0}
315
316
fossil_raw test-compress z-text.in write-dir/sub/dir/out.z
317
test blob-write-makes-directories {$CODE == 0 &&
318
[read_file write-dir/sub/dir/out.z] eq [read_file z-text.z]}
319
320
file mkdir write-is-dir
321
fossil_raw test-compress z-text.in write-is-dir
322
test blob-write-onto-directory {$CODE == 1 &&
323
[string match "*unable to open file \"write-is-dir\" for writing*" $RESULT]}
324
325
if {$::tcl_platform(platform) eq "unix" && $::tcl_platform(user) ne "root"} {
326
file mkdir write-closed
327
file attributes write-closed -permissions 0555
328
fossil_raw test-compress z-text.in write-closed/out.z
329
test blob-write-closed-directory {$CODE == 1 &&
330
[string match "*unable to open file \"write-closed/out.z\" for writing*" \
331
$RESULT]}
332
file attributes write-closed -permissions 0755
333
}
334
335
if {[test_assurance] ne "stress"} {
336
test_skip "the tests after the first sections need -assurance stress"
337
}
338
339
###############################################################################
340
# test-escaped-arg quotes each argument for the shell, shows the command
341
# line it made, and runs "fossil test-echo" with it, which prints the
342
# argument as it arrived. With --hex the argument is given as hexadecimal
343
# digits. Each row: the argument in hexadecimal, the quoted form that
344
# must end the command line when the argument is a file name and when it
345
# is not. The argument must arrive as it was given, after "./" if it
346
# is a file name that begins with "-". Bytes outside ASCII are written
347
# in the quoted forms as hexadecimal digits between "<" and ">". The
348
# quoted forms are those of a Unix shell.
349
350
proc blob_escaped {isFilename hex} {
351
fossil_raw test-escaped-arg --filename-args $isFilename --hex $hex
352
}
353
354
if {$::tcl_platform(platform) eq "unix"} {
355
foreach {blobName blobArgHex blobFile blobOther} {
356
word 616263 {abc} {abc}
357
safe-marks 2b2c2e2f3a3d5f {+,./:=_} {+,./:=_}
358
at-sign 614062 {'a@b'} {'a@b'}
359
dash 2d78 {./-x} {-x}
360
dash-only 2d {./-} {-}
361
two-dashes 2d2d782079 {'./--x y'} {'--x y'}
362
space 612062 {'a b'} {'a b'}
363
dash-space 2d612062 {'./-a b'} {'-a b'}
364
quote 69742773 {it\'s} {it\'s}
365
dash-quote 2d69742773 {./-it\'s} {-it\'s}
366
quote-space 61202762 {a\ \'b} {a\ \'b}
367
quote-marks 2724603b7c {\'\$\`\;\|} {\'\$\`\;\|}
368
dollar 612462 {'a$b'} {'a$b'}
369
backquote 606960 {'`i`'} {'`i`'}
370
backslash 615c62 {'a\b'} {'a\b'}
371
double-quote 612262 {'a"b'} {'a"b'}
372
tilde 7e {'~'} {'~'}
373
bang 2161 {'!a'} {'!a'}
374
star 2a3f5b5d {'*?[]'} {'*?[]'}
375
semicolon 613b62 {'a;b'} {'a;b'}
376
redirect 3c3e7c26 {'<>|&'} {'<>|&'}
377
braces 7b7d2829 {'{}()'} {'{}()'}
378
hash-percent 23255e {'#%^'} {'#%^'}
379
delete 617f {'a<7f>'} {'a<7f>'}
380
two-byte c3a9 {'<c3a9>'} {'<c3a9>'}
381
three-byte e282ac {'<e282ac>'} {'<e282ac>'}
382
four-byte f09f9880 {'<f09f9880>'} {'<f09f9880>'}
383
mixed 61c3a962e282ac63 {'a<c3a9>b<e282ac>c'} {'a<c3a9>b<e282ac>c'}
384
two-byte-quote c3a927 {\<c3a9>\'} {\<c3a9>\'}
385
dash-two-byte 2dc3a9 {'./-<c3a9>'} {'-<c3a9>'}
386
} {
387
set blobArg [blob_bytes $blobArgHex]
388
foreach {blobKind blobFlag blobQuoted} \
389
[list file 1 $blobFile other 0 $blobOther] {
390
while {[regexp {<([0-9a-f]+)>} $blobQuoted -> blobPart]} {
391
regsub {<[0-9a-f]+>} $blobQuoted [blob_bytes $blobPart] blobQuoted
392
}
393
set blobArrives $blobArg
394
if {$blobFlag && [string index $blobArg 0] eq "-"} {
395
set blobArrives ./$blobArg
396
}
397
blob_escaped $blobFlag $blobArgHex
398
test blob-escaped-$blobName-$blobKind {$CODE == 0 &&
399
[holds_strings $RESULT [list " test-echo $blobQuoted\n" \
400
"argv\[2\] = \[$blobArrives\]\n"]]}
401
}
402
}
403
}
404
405
# An argument that holds a control character, a byte that can only
406
# continue a UTF-8 character, or a UTF-8 character that is cut short is
407
# refused, and no command is run. Each row: the argument in hexadecimal
408
# and what the message must say.
409
foreach {blobName blobArgHex blobWhy} {
410
control-01 01 "ascii 0x01"
411
tab 6109 "ascii 0x09"
412
newline 610a62 "ascii 0x0a"
413
return 0d "ascii 0x0d"
414
escape 1b5b "ascii 0x1b"
415
unit-sep 1f "ascii 0x1f"
416
continuation 80 "ascii 0x80"
417
continuation-bf 61bf "ascii 0xbf"
418
two-cut c3 "illegal UTF-8"
419
two-then-ascii c341 "illegal UTF-8"
420
two-then-lead c3c3a9 "illegal UTF-8"
421
three-cut-1 e2 "illegal UTF-8"
422
three-cut-2 e282 "illegal UTF-8"
423
three-bad-2 e241ac "illegal UTF-8"
424
three-bad-3 e28241 "illegal UTF-8"
425
four-cut-1 f0 "illegal UTF-8"
426
four-cut-2 f09f "illegal UTF-8"
427
four-cut-3 f09f98 "illegal UTF-8"
428
four-bad-2 f0419880 "illegal UTF-8"
429
four-bad-3 f09f4180 "illegal UTF-8"
430
four-bad-4 f09f9841 "illegal UTF-8"
431
ff-alone ff "illegal UTF-8"
432
quote-then-cut 27c3 "illegal UTF-8"
433
quote-control 2701 "ascii 0x01"
434
late-control 616263202701 "ascii 0x01"
435
} {
436
foreach blobFlag {1 0} {
437
blob_escaped $blobFlag $blobArgHex
438
test blob-escaped-refused-$blobName-$blobFlag {$CODE == 1 &&
439
[holds_strings $RESULT [list $blobWhy "!argv\["]]}
440
}
441
}
442
443
if {$::tcl_platform(platform) eq "unix"} {
444
# Several arguments make several command lines, numbered by their place
445
# on the command line, and --filename-args switches between the two
446
# kinds of argument. A --filename-args that ends the command line is
447
# skipped.
448
fossil_raw test-escaped-arg -a --filename-args no -b --filename-args yes -c \
449
--filename-args
450
test blob-escaped-several {$CODE == 0 &&
451
[holds_strings $RESULT [list "argv\[2\] = \[./-a\]" \
452
"argv\[2\] = \[-b\]" "argv\[2\] = \[./-c\]"]] &&
453
[regexp -line {^ 2 \[-a\]: } $RESULT] &&
454
[regexp -line {^ 5 \[-b\]: } $RESULT] &&
455
[regexp -line {^ 8 \[-c\]: } $RESULT] &&
456
[regexp -all {argv\[2\]} $RESULT] == 3}
457
458
# --hex, --compare and --fuzz without the arguments they need are taken
459
# as file names.
460
foreach blobOption {--hex --fuzz} {
461
fossil_raw test-escaped-arg $blobOption
462
test blob-escaped-bare$blobOption {$CODE == 0 &&
463
[string first "argv\[2\] = \[./$blobOption\]" $RESULT] >= 0}
464
}
465
fossil_raw test-escaped-arg --compare 61
466
test blob-escaped-bare--compare {$CODE == 0 &&
467
[holds_strings $RESULT [list "argv\[2\] = \[./--compare\]" \
468
"argv\[2\] = \[61\]"]]}
469
}
470
471
# --hex takes up to 196 digits.
472
set blobDigits [string repeat 41 98]
473
fossil_raw test-escaped-arg --hex $blobDigits
474
test blob-escaped-hex-longest {$CODE == 0 &&
475
[string first "argv\[2\] = \[[string repeat A 98]\]" $RESULT] >= 0}
476
fossil_raw test-escaped-arg --hex ${blobDigits}41
477
test blob-escaped-hex-too-long {$CODE == 1 &&
478
[string match "*Argument to --hex is too big*" $RESULT]}
479
480
# --compare HEX TEXT succeeds without output when TEXT is the bytes that
481
# HEX stands for. A "./" before a TEXT whose bytes begin with "-" is not
482
# counted.
483
set blobDot [expr {$::tcl_platform(platform) eq "windows" ? ".\\" : "./"}]
484
foreach {blobName blobHex blobText blobCode blobSays} {
485
same 616263 abc 0 {}
486
differs 616263 abd 1
487
"argument disagree: \"abc\" (616263) versus \"abd\""
488
shorter 616263 ab 1 "argument disagree"
489
dash-prefixed 2d61 ./-a 0 {}
490
dash-bare 2d61 -a 1 "filename argument \"-a\" begins with \"-\""
491
dot-slash-kept 61 ./a 1 "argument disagree: \"a\" (61)"
492
dash-dot-only 2d61 .-a 1 "argument disagree"
493
dash-no-slash 2d61 .x-a 1 "argument disagree"
494
dash-no-dot 2d61 x-a 1 "argument disagree"
495
bad-hex zz a 1 "HEX decode of zz failed"
496
odd-hex 616 a 1 "HEX decode of 616 failed"
497
} {
498
set blobText [string map [list ./ $blobDot] $blobText]
499
fossil_raw test-escaped-arg --compare $blobHex $blobText
500
test blob-escaped-compare-$blobName {$CODE == $blobCode &&
501
($blobSays eq "" ? $RESULT eq "" : [string first $blobSays $RESULT] >= 0)}
502
}
503
fossil_raw test-escaped-arg --compare ${blobDigits}41 a
504
test blob-escaped-compare-too-long {$CODE == 1 &&
505
[string match "*HEX argument to --compare is too big*" $RESULT]}
506
fossil_raw test-escaped-arg --compare 61 a --compare 62 b --compare 63 x
507
test blob-escaped-compare-third {$CODE == 1 &&
508
[string first "\"c\" (63) versus \"x\"" $RESULT] >= 0}
509
510
# --fuzz N quotes N arguments made of random printable and multi-byte
511
# characters, passes each through the shell to "test-escaped-arg
512
# --compare", and stops at the first one that does not arrive unchanged.
513
fossil_raw -seconds 300 test-escaped-arg --fuzz 150
514
test blob-escaped-fuzz {$CODE == 0 && $RESULT eq ""}
515
fossil_raw test-escaped-arg --fuzz 0
516
test blob-escaped-fuzz-none {$CODE == 0 && $RESULT eq ""}
517
518
###############################################################################
519
# "diff --json" and "diff --tcl" write each piece of a line as a string
520
# literal. The JSON literal escapes the double quote, the backslash and
521
# every control character; the Tcl literal escapes the double quote, the
522
# backslash, the carriage return, the brackets and the dollar sign.
523
# Each row: the bytes of a line, in hexadecimal, and the JSON and Tcl
524
# literals for it.
525
526
foreach {blobName blobLineHex blobJson blobTcl} {
527
plain 616263 {"abc"} {"abc"}
528
quote 612262 {"a\"b"} {"a\"b"}
529
backslash 615c62 {"a\\b"} {"a\\b"}
530
brackets 5b615d {"[a]"} {"\[a\]"}
531
dollar 2461 {"$a"} {"\$a"}
532
return 610d62 {"a\rb"} {"a\rb"}
533
tab 610962 {"a\tb"} {"a<09>b"}
534
backspace 610862 {"a\bb"} {"a<08>b"}
535
formfeed 610c62 {"a\fb"} {"a<0c>b"}
536
ctl-01 0161 {"\u0001a"} {"<01>a"}
537
ctl-02-07 020304050607 {"\u0002\u0003\u0004\u0005\u0006\u0007"}
538
{"<020304050607>"}
539
ctl-0b 0b {"\u000b"} {"<0b>"}
540
ctl-0e-0f 0e0f {"\u000e\u000f"} {"<0e0f>"}
541
ctl-10-19 10111213141516171819
542
{"\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019"}
543
{"<10111213141516171819>"}
544
ctl-1a-1f 1a1b1c1d1e1f {"\u001a\u001b\u001c\u001d\u001e\u001f"}
545
{"<1a1b1c1d1e1f>"}
546
delete 7f {"<7f>"} {"<7f>"}
547
two-byte c3a9 {"<c3a9>"} {"<c3a9>"}
548
empty {} {""} {""}
549
} {
550
foreach blobVar {blobJson blobTcl} {
551
while {[regexp {<([0-9a-f]+)>} [set $blobVar] -> blobPart]} {
552
regsub {<[0-9a-f]+>} [set $blobVar] [blob_bytes $blobPart] $blobVar
553
}
554
}
555
write_file lit-$blobName.1 "same\n"
556
write_file lit-$blobName.2 "same\n[blob_bytes $blobLineHex]\n"
557
fossil_raw test-diff --json lit-$blobName.1 lit-$blobName.2
558
test blob-json-literal-$blobName {$CODE == 0 &&
559
[string first "\n\[2,\"same\",\n3,$blobJson,\n0\]" $RESULT] >= 0}
560
fossil_raw test-diff --tcl lit-$blobName.1 lit-$blobName.2
561
test blob-tcl-literal-$blobName {$CODE == 0 &&
562
[string first "\nCOM \"same\"\nINS $blobTcl\n" $RESULT] >= 0}
563
}
564
565
# The names of the two files are written as literals of the same kind.
566
write_file {lit [n]$.1} "one\n"
567
write_file {lit [n]$.2} "two\n"
568
fossil_raw test-diff --tcl {lit [n]$.1} {lit [n]$.2}
569
test blob-tcl-literal-filenames {$CODE == 0 &&
570
[string first {FILE "lit \[n\]\$.1" "lit \[n\]\$.2"} $RESULT] >= 0}
571
572
# In a checkout "diff --tcl" prints the same literals without collecting
573
# them first.
574
commit_file lit-checkout.txt "first\n" "lit checkout" --no-warnings \
575
lit-checkout.txt
576
write_file lit-checkout.txt "\[second\] \$x\n"
577
fossil_raw diff --tcl lit-checkout.txt
578
test blob-tcl-literal-checkout {$CODE == 0 &&
579
[holds_strings $RESULT [list \
580
"FILE \"lit-checkout.txt\" \"lit-checkout.txt\"\n" \
581
{EDIT "" "first" "\[second\] \$x"}]]}
582
fossil revert lit-checkout.txt
583
584
# "diff --webpage" without --side-by-side builds four columns at once:
585
# the line numbers of each file, the marks, and the text.
586
write_file web.1 "one\ntwo\nthree\n"
587
write_file web.2 "one\n2\nthree\nfour\n"
588
fossil_raw test-diff --webpage web.1 web.2
589
test blob-webpage-diff-columns {$CODE == 0 && [regexp \
590
{<td class="diffln difflnl"><pre>\n1\n<del>2\n</del>\n3\n\n</pre></td><td class="diffln difflnr"><pre>\n1\n\n<ins>2\n</ins>3\n<ins>4\n</ins></pre></td><td class="diffsep"><pre>\n\n-\n\+\n\n\+\n</pre></td><td class="difftxt difftxtu"><pre>\none\n<del><del>two</del>\n</del><ins><ins>2</ins>\n</ins>three\n<ins><ins>four</ins>\n</ins></pre></td>} \
591
$RESULT]}
592
593
###############################################################################
594
# Line ends. "test-ci-mini" checks a file in, and with --convert-eol-unix
595
# or --convert-eol-windows it gives the content the line ends of that
596
# system first; with --convert-eol-inherit it gives it the line ends of
597
# the version before. Each row: the option, the content before, the
598
# content given, and the content that must be checked in.
599
600
commit_file eol.txt "start\n" "eol start" --no-warnings
601
602
# Check in eol.txt with the content $before, then with $given and the
603
# option $option. Returns the content of eol.txt in the last check-in.
604
proc blob_eol {before given option} {
605
global RESULT
606
foreach {content opt} [list $before {} $given $option] {
607
write_file eol.txt $content
608
fossil test-ci-mini -m eol -r tip --wet-run --allow-older {*}$opt eol.txt
609
}
610
fossil_raw cat eol.txt -r tip
611
return $RESULT
612
}
613
614
foreach {blobName blobOption blobBefore blobGiven blobStored} {
615
to-windows --convert-eol-windows "s\n" "one\ntwo\n\nlast"
616
"one\r\ntwo\r\n\r\nlast"
617
to-windows-only-nl --convert-eol-windows "s\n" "\n\n\n" "\r\n\r\n\r\n"
618
to-windows-no-nl --convert-eol-windows "s\n" "word" "word"
619
to-windows-already --convert-eol-windows "s\n" "a\r\nb\r\n" "a\r\nb\r\n"
620
to-unix --convert-eol-unix "s\n" "a\r\nb\rc\r\n\r"
621
"a\nb\nc\n\n"
622
to-unix-already --convert-eol-unix "s\n" "a\nb\n" "a\nb\n"
623
to-unix-end-cr --convert-eol-unix "s\n" "a\r\nb\r" "a\nb\n"
624
inherit-unix --convert-eol-inherit "p\nq\n" "x\r\ny\r\nz\r\n"
625
"x\ny\nz\n"
626
inherit-windows --convert-eol-inherit "p\r\nq\r\n" "x\ny\nz\n"
627
"x\r\ny\r\nz\r\n"
628
inherit-same --convert-eol-inherit "p\nq\n" "x\ny\n" "x\ny\n"
629
} {
630
test_eq blob-eol-$blobName [blob_eol $blobBefore $blobGiven $blobOption] \
631
$blobStored
632
}
633
634
# Content with a zero byte after its lines keeps the bytes that follow
635
# the zero byte. With --convert-eol-unix Fossil stores only the lines
636
# before the zero byte.
637
test_eq blob-eol-to-unix-nul [blob_eol "s\n" "x\r\ny\r\n\x00tail\r\nmore\r\n" \
638
--convert-eol-unix] \
639
"x\ny\n\x00tail\nmore\n" knownBug
640
641
# test-ci-mini leaves the checkout as it was.
642
fossil revert eol.txt
643
fossil update tip
644
645
###############################################################################
646
# A commit warns about a file that is not UTF-8 and offers to convert it.
647
# With the answer "c" the file is rewritten as UTF-8 with Unix line ends,
648
# the bytes it had are kept in a file named FILE-original, and the commit
649
# stops. Each row: the bytes of the file and the bytes after conversion,
650
# both in hexadecimal.
651
#
652
# utf16-le, utf16-be: "h", e-acute, CR LF, the euro sign, LF, after a
653
# byte-order mark. The result begins with the UTF-8 byte-order mark.
654
# utf16-le-short, utf16-be-short: a mark and one character.
655
# cp1252: bytes 0x80 to 0x9f stand for the characters of code page
656
# 1252, three bytes long in UTF-8 (0x80, 0x99) or two (0x81, 0x9f),
657
# and bytes from 0xa0 for the characters of ISO 8859-1.
658
659
foreach {blobName blobBefore blobAfter} {
660
utf16-le fffe6800e9000d000a00ac200a00 efbbbf68c3a90ae282ac0a
661
utf16-be feff006800e9000d000a20ac000a efbbbf68c3a90ae282ac0a
662
utf16-le-short fffe6800 efbbbf68
663
utf16-be-short feff0068 efbbbf68
664
cp1252 63e920802081209920a020ff0d0a61
665
63c3a920e282ac20c28120e284a220c2a020c3bf0a61
666
cp1252-9f 9f8a0a c5b8c5a00a
667
cp1252-plain e90a c3a90a
668
cp1252-long __long__ __long__
669
} {
670
if {$blobBefore eq "__long__"} {
671
set blobBefore [string repeat 80e941 3000]0a
672
set blobAfter [string repeat e282acc3a941 3000]0a
673
}
674
write_file conv-$blobName.txt [blob_bytes $blobBefore]
675
fossil add conv-$blobName.txt
676
fossil_raw -input "c\n" commit -m "convert $blobName" conv-$blobName.txt
677
test blob-convert-$blobName {$CODE == 1 &&
678
[string match "*Commit anyhow (a=all/c=convert/y/N)?*files were\
679
converted on your request*" $RESULT] &&
680
[blob_hex [read_file conv-$blobName.txt]] eq $blobAfter &&
681
[blob_hex [read_file conv-$blobName.txt-original]] eq $blobBefore}
682
fossil forget conv-$blobName.txt
683
}
684
685
###############################################################################
686
# A check-in comment read from a file with -M is stored as UTF-8: a
687
# byte-order mark is taken off, UTF-16 with a mark is converted, and
688
# bytes that are not UTF-8 are read as code page 1252. Each row: the
689
# bytes of the file and the bytes of the comment that must be stored,
690
# both in hexadecimal.
691
692
commit_file comment-subject.txt "0\n" "comment subject" --no-warnings \
693
comment-subject.txt
694
foreach {blobName blobFile blobComment} {
695
ascii 706c61696e 706c61696e
696
utf8 636166c3a920e282ac 636166c3a920e282ac
697
utf8-bom efbbbf636166c3a9 636166c3a9
698
utf16-le fffe63006100e900 6361c3a9
699
utf16-be feff0063006120ac 6361e282ac
700
cp1252 636166e92080 636166c3a920e282ac
701
cp1252-two 81a0ff c281c2a0c3bf
702
cp1252-three 808599 e282ace280a6e284a2
703
} {
704
write_file comment-$blobName.txt [blob_bytes $blobFile]
705
write_file comment-subject.txt "$blobName\n"
706
fossil commit -M comment-$blobName.txt --no-warnings \
707
--no-verify-comment comment-subject.txt
708
fossil sql "SELECT lower(hex(comment)) FROM event
709
ORDER BY mtime DESC, objid DESC LIMIT 1"
710
test_eq blob-comment-file-$blobName [string trim $RESULT] $blobComment
711
}
712
713
# A comment typed in an editor is converted in the same way, after it
714
# is cut at a row of ten "#". The editor here is a script that writes
715
# the given bytes as the comment.
716
fossil settings editor [fake_editor_command]
717
foreach {blobName blobTyped blobComment} {
718
utf8 636166c3a90a 636166c3a9
719
cp1252 636166e920800a 636166c3a920e282ac
720
cp1252-cut 63e90a232323232323232323232063757420800a 63c3a9
721
utf8-cut 63c3a90a232323232323232323232063757420800a 63c3a9
722
} {
723
write_file comment-subject.txt "editor $blobName\n"
724
set ::env(FAKE_EDITOR_SCRIPT) [list set data [blob_bytes $blobTyped]]
725
fossil commit --no-warnings --no-verify-comment comment-subject.txt
726
unset ::env(FAKE_EDITOR_SCRIPT)
727
fossil sql "SELECT lower(hex(comment)) FROM event
728
ORDER BY mtime DESC, objid DESC LIMIT 1"
729
test_eq blob-comment-editor-$blobName [string trim $RESULT] $blobComment
730
}
731
fossil unset editor
732
733
###############################################################################
734
# A diff does not show a byte-order mark, and reads UTF-16 text that has
735
# one. Each row: the bytes of the second file, in hexadecimal. The first
736
# file is "one" and "two" on two lines, and the diff must say that "2"
737
# replaces the second line.
738
739
commit_file bom-plain.txt "one\ntwo\n" "bom plain" --no-warnings bom-plain.txt
740
foreach {blobName blobSecond} {
741
none 6f6e650a320a
742
utf8 efbbbf6f6e650a320a
743
utf16-le fffe6f006e0065000a0032000a00
744
utf16-be feff006f006e0065000a0032000a
745
} {
746
write_file bom-plain.txt [blob_bytes $blobSecond]
747
fossil_raw diff bom-plain.txt
748
test blob-bom-diff-$blobName {$CODE == 0 &&
749
[string first "\n one\n-two\n+2\n" $RESULT] >= 0}
750
}
751
# A file that is only a byte-order mark is a file without lines.
752
foreach {blobName blobSecond} {
753
utf8-only efbbbf
754
utf16-le-only fffe
755
utf16-be-only feff
756
} {
757
write_file bom-plain.txt [blob_bytes $blobSecond]
758
fossil_raw diff bom-plain.txt
759
test blob-bom-diff-$blobName {$CODE == 0 &&
760
[string first "\n-one\n-two\n" $RESULT] >= 0 &&
761
![regexp -line {^\+[^+]} $RESULT]}
762
}
763
fossil revert bom-plain.txt
764
765
# Two files with a byte-order mark and a zero byte differ after the zero
766
# byte. They are binary files, which a diff does not compare. Fossil prints
767
# an empty diff and exits 0 without the message.
768
write_file bom-nul.1 [blob_bytes efbbbf]a\x00b\n
769
write_file bom-nul.2 [blob_bytes efbbbf]a\x00c\n
770
fossil_raw test-diff bom-nul.1 bom-nul.2
771
test blob-bom-diff-nul {$CODE == 0 &&
772
[string first "cannot compute difference between binary files" $RESULT] >= 0
773
} knownBug
774
775
###############################################################################
776
# Web pages. The page PATH of the repository of this checkout, asked for
777
# by a local administrator with the header lines in HEADERS.
778
779
proc blob_page {path {headers {}}} {
780
return [fossil_http .rep.fossil [request_get $path $headers] \
781
--ipaddr 127.0.0.1 --localauth]
782
}
783
784
# /test-bgcolor takes a colour as "#" and three or six hexadecimal
785
# digits in lower case. Each row: what follows the "#" and whether it is
786
# a colour.
787
foreach {blobName blobColor blobOk} {
788
three-digits abc 1
789
six-digits 09afbc 1
790
seven-digits 09afbca 1
791
two-digits 12 0
792
four-digits 1234 0
793
five-digits 12345 0
794
upper-case ABC 0
795
letter-g ggg 0
796
sixth-g abcdeg 0
797
slash ab/ 0
798
colon 9:1 0
799
backquote `ab 0
800
brace ab\{ 0
801
nothing {} 0
802
} {
803
set blobReply [blob_page /test-bgcolor?ba=%23[string map \
804
{/ %2F : %3A ` %60 \{ %7B} $blobColor]]
805
test blob-xdigit-color-$blobName {$CODE == 0 && ($blobOk
806
? [string first "Requested color \"#$blobColor\"" $blobReply] >= 0
807
: [string first "is not a recognized color name" $blobReply] >= 0)}
808
}
809
810
# /cookies calls a cookie the login cookie of another repository when
811
# its name is "fossil-" and 16 hexadecimal digits and its value begins
812
# with more than 24 of them, in either case. Each row: the value and
813
# whether it is such a cookie.
814
foreach {blobName blobValue blobOk} {
815
digits 0123456789012345678901234 1
816
lower abcdefabcdefabcdefabcdefa 1
817
upper ABCDEFABCDEFABCDEFABCDEFA 1
818
mixed 09afAF09afAF09afAF09afAFx 0
819
mixed-25 09afAF09afAF09afAF09afAF0x 1
820
short 0123456789abcdefABCDEF01 0
821
upper-g 0123456789abcdefABCDEF01G 0
822
lower-g 0123456789abcdefABCDEF01g 0
823
slash 0123456789abcdefABCDEF01/ 0
824
colon 0123456789abcdefABCDEF01: 0
825
at-sign 0123456789abcdefABCDEF01@ 0
826
backquote 0123456789abcdefABCDEF01` 0
827
} {
828
set blobReply [blob_page /cookies \
829
[list "Cookie: fossil-0123456789abcDEF=$blobValue"]]
830
test blob-xdigit-cookie-$blobName {$CODE == 0 && ($blobOk
831
? [string first "login cookie for another Fossil repository" \
832
$blobReply] >= 0
833
: [string first "This cookie was not generated by Fossil" \
834
$blobReply] >= 0)}
835
}
836
set blobReply [blob_page /cookies \
837
[list "Cookie: fossil-0123456789abcdeg=0123456789012345678901234"]]
838
test blob-xdigit-cookie-name-g {$CODE == 0 &&
839
[string first "This cookie was not generated by Fossil" $blobReply] >= 0}
840
841
# A request that announces more content than a buffer may hold is ended
842
# with "out of memory" before any of the content is read.
843
write_file page-request.txt \
844
"POST /test-env HTTP/1.1\r\nHost: x\r\nContent-Type:\
845
text/plain\r\nContent-Length: 2147483647\r\n\r\nabc"
846
file delete page-reply.txt
847
fossil_raw -seconds 60 http .rep.fossil --in page-request.txt \
848
--out page-reply.txt --ipaddr 127.0.0.1 --localauth
849
test blob-too-large-request {$CODE == 1 && $RESULT eq "out of memory\n" &&
850
(![file exists page-reply.txt] || [file size page-reply.txt] == 0)}
851
852
# The timeline cuts a comment that is longer than the timeline-max-comment
853
# setting and puts "..." after it. It does not cut inside a UTF-8
854
# character. The comment is "utf caf", then characters of two, three and
855
# four bytes, then " tail". Each row: the setting and the bytes of the
856
# characters that must be left after "utf caf", in hexadecimal.
857
write_file tl.txt "timeline\n"
858
fossil add tl.txt
859
write_file tl-comment.txt "utf caf[blob_bytes c3a9e282acf09f9880] tail"
860
fossil commit -M tl-comment.txt --no-warnings --no-verify-comment tl.txt
861
foreach {blobLimit blobLeft} {
862
7 {}
863
8 {}
864
9 c3a9
865
10 c3a9
866
11 c3a9
867
12 c3a9e282ac
868
13 c3a9e282ac
869
15 c3a9e282ac
870
16 c3a9e282acf09f9880
871
17 c3a9e282acf09f988020
872
} {
873
fossil sql "REPLACE INTO config(name,value,mtime)
874
VALUES('timeline-max-comment',$blobLimit,now())"
875
set blobReply [blob_page /timeline?n=1]
876
test blob-truncate-utf8-$blobLimit {$CODE == 0 &&
877
[regexp {utf caf([^<.]*)\.\.\.\n} $blobReply -> blobGot] &&
878
[blob_hex $blobGot] eq $blobLeft}
879
}
880
# A setting of 0, a negative one, and one longer than the comment leave
881
# the comment whole.
882
foreach blobLimit {0 -1 21 22 500} {
883
fossil sql "REPLACE INTO config(name,value,mtime)
884
VALUES('timeline-max-comment',$blobLimit,now())"
885
set blobReply [blob_page /timeline?n=1]
886
test blob-truncate-utf8-whole-$blobLimit {$CODE == 0 &&
887
[regexp {utf caf([^<]*) tail\n} $blobReply -> blobGot] &&
888
[blob_hex $blobGot] eq "c3a9e282acf09f9880"}
889
}
890
fossil sql "DELETE FROM config WHERE name='timeline-max-comment'"
891
892
###############################################################################
893
# "fossil clean --prompt" asks about each unmanaged file and takes the
894
# first letter of the answer in either case: "n" keeps the file, "a"
895
# removes it and all the others without asking again, "y" removes it.
896
# Each row: the answer given to every question, and the files that must
897
# be left.
898
899
proc blob_clean {answer} {
900
foreach name {clean-1.tmp clean-2.tmp} { write_file $name "tmp\n" }
901
fossil_raw -input "$answer\n$answer\n$answer\n" clean --prompt \
902
--clean "" --ignore "*" --keep "" clean-1.tmp clean-2.tmp
903
set left [lsort [glob -nocomplain clean-*.tmp]]
904
file delete clean-1.tmp clean-2.tmp
905
return $left
906
}
907
foreach {blobName blobAnswer blobLeft} {
908
lower-n n {clean-1.tmp clean-2.tmp}
909
upper-n N {clean-1.tmp clean-2.tmp}
910
word-no no {clean-1.tmp clean-2.tmp}
911
lower-y y {}
912
upper-y Y {}
913
lower-a a {}
914
upper-a A {}
915
} {
916
set blobGot [blob_clean $blobAnswer]
917
test blob-clean-prompt-$blobName {$CODE == 0 && $blobGot eq $blobLeft &&
918
[string first "Remove unmanaged file \"clean-1.tmp\" (a=all/y/N)?" \
919
$RESULT] >= 0}
920
}
921
# After "a" the second file is removed without a question.
922
blob_clean a
923
test blob-clean-prompt-all-asks-once {$CODE == 0 &&
924
[string first "\"clean-2.tmp\"" $RESULT] < 0}
925
# An empty answer, and an answer that is none of the letters offered,
926
# keep the file. Fossil removes both files for each of these answers.
927
foreach {blobName blobAnswer} {
928
empty {}
929
brace \{
930
tilde ~
931
letter-q q
932
} {
933
test_eq blob-clean-prompt-$blobName [blob_clean $blobAnswer] \
934
{clean-1.tmp clean-2.tmp} knownBug
935
}
936
937
###############################################################################
938
# A comment is broken into lines at a space, or after a hyphen that
939
# follows a letter. Each row: the character before the hyphen in
940
# "aaaa bbbbX-ccccc" and whether a line 13 wide, 9 of which are margin,
941
# may end after the hyphen.
942
943
foreach {blobName blobChar blobBreaks} {
944
lower-a a 1
945
lower-z z 1
946
upper-a A 1
947
upper-z Z 1
948
digit 1 0
949
at-sign @ 0
950
bracket \[ 0
951
underscore _ 0
952
backquote ` 0
953
brace \{ 0
954
tilde ~ 0
955
} {
956
fossil_raw test-comment-format -W 13 "aaaa bbbb${blobChar}-ccccc"
957
test blob-isalpha-$blobName {$CODE == 0 && ($blobBreaks
958
? [string first "\n ${blobChar}-\n" $RESULT] >= 0
959
: [string first "\n ${blobChar}-cc\n" $RESULT] >= 0)}
960
}
961
962
###############################################################################
963
# A three-way merge of files whose last line has no line end.
964
965
# Merge the contents $one and $two, which both come from $base. Returns
966
# the merged content; CODE is the exit status of the merge.
967
proc blob_merge {base one two} {
968
write_file merge.0 $base
969
write_file merge.1 $one
970
write_file merge.2 $two
971
file delete merge.out
972
fossil_raw 3-way-merge merge.0 merge.1 merge.2 merge.out
973
return [read_file merge.out]
974
}
975
976
test blob-merge-no-final-newline-edit \
977
{[blob_merge "a\nb\nc" "A\nb\nc" "a\nb\nC"] eq "A\nb\nC" && $CODE == 0}
978
test blob-merge-no-final-newline-same \
979
{[blob_merge "a\nb\nc" "a\nB\nc" "a\nB\nc"] eq "a\nB\nc" && $CODE == 0}
980
test blob-merge-empty {[blob_merge "" "" ""] eq "" && $CODE == 0}
981
982
# Both sides change the last line, which has no line end: a conflict,
983
# with each side's line whole between the marks.
984
set blobMerged [blob_merge "a\nb" "a\nONE" "a\nTWO"]
985
test blob-merge-no-final-newline-conflict {$CODE == 0 &&
986
[string first "1 merge conflicts" $RESULT] >= 0 &&
987
[regexp {<<<<<<<[^\n]*\nONE\n#######} $blobMerged] &&
988
[regexp {=======[^\n]*\nTWO\n>>>>>>>} $blobMerged]}
989
990
# One side changes a line and the other adds a line after the last one,
991
# which had no line end. The added line is a line of its own. Fossil
992
# joins it to that line: "a\nB\ncd".
993
test_eq blob-merge-no-final-newline-append \
994
[blob_merge "a\nb\nc" "a\nB\nc" "a\nb\nc\nd"] \
995
"a\nB\nc\nd" knownBug
996
997
###############################################################################
998
# With the allow-symlinks setting on, a symbolic link is checked in as the
999
# name it points to. With the setting off, the file it points to is
1000
# checked in.
1001
1002
if {$::tcl_platform(platform) eq "unix"} {
1003
write_file link-target.txt "content of the target\n"
1004
file link -symbolic link-on.lnk link-target.txt
1005
fossil settings allow-symlinks on
1006
fossil add link-on.lnk
1007
fossil commit -m "link, symlinks on" --no-warnings link-on.lnk
1008
fossil_raw cat link-on.lnk -r tip
1009
test blob-read-link-as-name {$CODE == 0 && $RESULT eq "link-target.txt"}
1010
fossil settings allow-symlinks off
1011
file link -symbolic link-off.lnk link-target.txt
1012
fossil add link-off.lnk
1013
fossil commit -m "link, symlinks off" --no-warnings link-off.lnk
1014
fossil_raw cat link-off.lnk -r tip
1015
test blob-read-link-as-file {$CODE == 0 &&
1016
$RESULT eq "content of the target\n"}
1017
}
1018
1019
###############################################################################
1020
test_cleanup
1021

Keyboard Shortcuts

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