summary refs log tree commit diff
path: root/posix/globtest.sh
blob: ad47508a665bdb905b9c5075e12bcea7d417cfb1 (plain) (blame)
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
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
#! /bin/sh

common_objpfx=$1; shift
elf_objpfx=$1; shift
rtld_installed_name=$1; shift
logfile=$common_objpfx/posix/globtest.out

#CMP=cmp
CMP="diff -u"

# We have to make the paths `common_objpfx' absolute.
case "$common_objpfx" in
  .*)
    common_objpfx="`pwd`/$common_objpfx"
    ;;
  *)
    ;;
esac

# We have to find the libc and the NSS modules.
library_path=${common_objpfx}:${common_objpfx}nss:${common_objpfx}nis:${common_objpfx}db2:${common_objpfx}hesiod

# Since we use `sort' we must make sure to use the same locale everywhere.
LC_ALL=C
export LC_ALL
LANG=C
export LANG

# Create the arena
: ${TMPDIR=/tmp}
testdir=$TMPDIR/globtest-dir
testout=$TMPDIR/globtest-out

trap 'chmod 777 $testdir/noread; rm -fr $testdir $testout' 1 2 3 15

test -d $testdir/noread && chmod 777 $testdir/noread
rm -fr $testdir 2>/dev/null
mkdir $testdir
echo 1 > $testdir/file1
echo 2 > $testdir/file2
echo 3 > $testdir/-file3
echo 4 > $testdir/~file4
echo 5 > $testdir/.file5
echo 6 > $testdir/'*file6'
echo 7 > $testdir/'{file7,}'
echo 8 > $testdir/'\{file8\}'
echo 9 > $testdir/'\{file9\,file9b\}'
echo 9 > $testdir/'\file9b\' #'
echo a > $testdir/'filea,'
echo a > $testdir/'fileb}c'
mkdir $testdir/dir1
mkdir $testdir/dir2
test -d $testdir/noread || mkdir $testdir/noread
chmod a-r $testdir/noread
echo 1_1 > $testdir/dir1/file1_1
echo 1_2 > $testdir/dir1/file1_2
ln -fs dir1 $testdir/link1

# Run some tests.
result=0
rm -f $logfile

# Normal test
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest "$testdir" "*" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
`*file6'
`-file3'
`\file9b\'
`\{file8\}'
`\{file9\,file9b\}'
`dir1'
`dir2'
`file1'
`file2'
`filea,'
`fileb}c'
`link1'
`noread'
`{file7,}'
`~file4'
EOF
if test $failed -ne 0; then
  echo "Normal test failed" >> $logfile
  result=1
fi

# Don't let glob sort it
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -s "$testdir" "*" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
`*file6'
`-file3'
`\file9b\'
`\{file8\}'
`\{file9\,file9b\}'
`dir1'
`dir2'
`file1'
`file2'
`filea,'
`fileb}c'
`link1'
`noread'
`{file7,}'
`~file4'
EOF
if test $failed -ne 0; then
  echo "No sort test failed" >> $logfile
  result=1
fi

# Mark directories
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -m "$testdir" "*" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
`*file6'
`-file3'
`\file9b\'
`\{file8\}'
`\{file9\,file9b\}'
`dir1/'
`dir2/'
`file1'
`file2'
`filea,'
`fileb}c'
`link1/'
`noread/'
`{file7,}'
`~file4'
EOF
if test $failed -ne 0; then
  echo "Mark directories test failed" >> $logfile
  result=1
fi

# Find files starting with .
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -p "$testdir" "*" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
`*file6'
`-file3'
`.'
`..'
`.file5'
`\file9b\'
`\{file8\}'
`\{file9\,file9b\}'
`dir1'
`dir2'
`file1'
`file2'
`filea,'
`fileb}c'
`link1'
`noread'
`{file7,}'
`~file4'
EOF
if test $failed -ne 0; then
  echo "Leading period test failed" >> $logfile
  result=1
fi

# Test braces
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -b "$testdir" "file{1,2}" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
`file1'
`file2'
EOF
if test $failed -ne 0; then
  echo "Braces test failed" >> $logfile
  result=1
fi

failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -b "$testdir" "{file{1,2},-file3}" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
`-file3'
`file1'
`file2'
EOF
if test $failed -ne 0; then
  echo "Braces test 2 failed" >> $logfile
  result=1
fi

failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -b "$testdir" "{" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
GLOB_NOMATCH
EOF
if test $failed -ne 0; then
  echo "Braces test 3 failed" >> $logfile
  result=1
fi

# Test NOCHECK
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -c "$testdir" "abc" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
`abc'
EOF
if test $failed -ne 0; then
  echo "No check test failed" >> $logfile
  result=1
fi

# Test NOMAGIC without magic characters
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -g "$testdir" "abc" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
`abc'
EOF
if test $failed -ne 0; then
  echo "No magic test failed" >> $logfile
  result=1
fi

# Test NOMAGIC with magic characters
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -g "$testdir" "abc*" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
GLOB_NOMATCH
EOF
if test $failed -ne 0; then
  echo "No magic w/ magic chars test failed" >> $logfile
  result=1
fi

# Test NOMAGIC for subdirs
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -g "$testdir" "*/does-not-exist" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
GLOB_NOMATCH
EOF
if test $failed -ne 0; then
  echo "No magic in subdir test failed" >> $logfile
  result=1
fi

# Test subdirs correctly
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest "$testdir" "*/*" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
`dir1/file1_1'
`dir1/file1_2'
`link1/file1_1'
`link1/file1_2'
EOF
if test $failed -ne 0; then
  echo "Subdirs test failed" >> $logfile
  result=1
fi

# Test subdirs for invalid names
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest "$testdir" "*/1" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
GLOB_NOMATCH
EOF
if test $failed -ne 0; then
  echo "Invalid subdir test failed" >> $logfile
  result=1
fi

# Test subdirs with wildcard
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest "$testdir" "*/*1_1" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
`dir1/file1_1'
`link1/file1_1'
EOF
if test $failed -ne 0; then
  echo "Wildcard subdir test failed" >> $logfile
  result=1
fi

# Test subdirs with ?
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
`dir1/file1_1'
`dir1/file1_2'
`link1/file1_1'
`link1/file1_2'
EOF
if test $failed -ne 0; then
  echo "Wildcard2 subdir test failed" >> $logfile
  result=1
fi

failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest "$testdir" "*/file1_1" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
`dir1/file1_1'
`link1/file1_1'
EOF
if test $failed -ne 0; then
  echo "Wildcard3 subdir test failed" >> $logfile
  result=1
fi

failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest "$testdir" "*-/*" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
GLOB_NOMATCH
EOF
if test $failed -ne 0; then
  echo "Wildcard4 subdir test failed" >> $logfile
  result=1
fi

failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest "$testdir" "*-" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
GLOB_NOMATCH
EOF
if test $failed -ne 0; then
  echo "Wildcard5 subdir test failed" >> $logfile
  result=1
fi

# Test subdirs with ?
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
`dir1/file1_1'
`dir1/file1_2'
`link1/file1_1'
`link1/file1_2'
EOF
if test $failed -ne 0; then
  echo "Wildcard6 subdir test failed" >> $logfile
  result=1
fi

# Test subdirs with [ .. ]
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest "$testdir" "*/file1_[12]" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
`dir1/file1_1'
`dir1/file1_2'
`link1/file1_1'
`link1/file1_2'
EOF
if test $failed -ne 0; then
  echo "Brackets test failed" >> $logfile
  result=1
fi

# Test ']' inside bracket expression
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest "$testdir" "dir1/file1_[]12]" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
`dir1/file1_1'
`dir1/file1_2'
EOF
if test $failed -ne 0; then
  echo "Brackets2 test failed" >> $logfile
  result=1
fi

# Test tilde expansion
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -q -t "$testdir" "~" |
sort >$testout
echo ~ | $CMP - $testout >> $logfile || failed=1
if test $failed -ne 0; then
  if test -d ~; then
    echo "Tilde test failed" >> $logfile
    result=1
  else
    echo "Tilde test could not be run" >> $logfile
  fi
fi

# Test tilde expansion with trailing slash
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -q -t "$testdir" "~/" |
sort > $testout
# Some shell incorrectly(?) convert ~/ into // if ~ expands to /.
if test ~/ = //; then
    echo / | $CMP - $testout >> $logfile || failed=1
else
    echo ~/ | $CMP - $testout >> $logfile || failed=1
fi
if test $failed -ne 0; then
  if test -d ~/; then
    echo "Tilde2 test failed" >> $logfile
    result=1
  else
    echo "Tilde2 test could not be run" >> $logfile
  fi
fi

# Test tilde expansion with username
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -q -t "$testdir" "~"$USER |
sort > $testout
eval echo ~$USER | $CMP - $testout >> $logfile || failed=1
if test $failed -ne 0; then
  if eval test -d ~$USER; then
    echo "Tilde3 test failed" >> $logfile
    result=1
  else
    echo "Tilde3 test could not be run" >> $logfile
  fi
fi

# Tilde expansion shouldn't match a file
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -T "$testdir" "~file4" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
GLOB_NOMATCH
EOF
if test $failed -ne 0; then
  echo "Tilde4 test failed" >> $logfile
  result=1
fi

# Matching \** should only find *file6
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest "$testdir" "\**" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
`*file6'
EOF
if test $failed -ne 0; then
  echo "Star test failed" >> $logfile
  result=1
fi

# ... unless NOESCAPE is used, in which case it should entries with a
# leading \.
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -e "$testdir" "\**" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
`\file9b\'
`\{file8\}'
`\{file9\,file9b\}'
EOF
if test $failed -ne 0; then
  echo "Star2 test failed" >> $logfile
  result=1
fi

# Matching \*file6 should find *file6
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest "$testdir" "\*file6" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
`*file6'
EOF
if test $failed -ne 0; then
  echo "Star3 test failed" >> $logfile
  result=1
fi

# GLOB_BRACE alone
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -b "$testdir" '\{file7\,\}' |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
`{file7,}'
EOF
if test $failed -ne 0; then
  echo "Brace4 test failed" >> $logfile
  result=1
fi

# GLOB_BRACE and GLOB_NOESCAPE
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -b -e "$testdir" '\{file9\,file9b\}' |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
`\file9b\'
EOF
if test $failed -ne 0; then
  echo "Brace5 test failed" >> $logfile
  result=1
fi

# Escaped comma
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -b "$testdir" '{filea\,}' |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
`filea,'
EOF
if test $failed -ne 0; then
  echo "Brace6 test failed" >> $logfile
  result=1
fi

# Escaped closing brace
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -b "$testdir" '{fileb\}c}' |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
`fileb}c'
EOF
if test $failed -ne 0; then
  echo "Brace7 test failed" >> $logfile
  result=1
fi

# Try a recursive failed search
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -e "$testdir" "a*/*" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
GLOB_NOMATCH
EOF
if test $failed -ne 0; then
  echo "Star4 test failed" >> $logfile
  result=1
fi

# ... with GLOB_ERR
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -E "$testdir" "a*/*" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
GLOB_NOMATCH
EOF
if test $failed -ne 0; then
  echo "Star5 test failed" >> $logfile
  result=1
fi

# Try a recursive search in unreadable directory
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest "$testdir" "noread/*" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
GLOB_NOMATCH
EOF
if test $failed -ne 0; then
  echo "Star6 test failed" >> $logfile
  result=1
fi

failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest "$testdir" "noread*/*" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
GLOB_NOMATCH
EOF
if test $failed -ne 0; then
  echo "Star6 test failed" >> $logfile
  result=1
fi

# The following tests will fail if run as root.
user=`id -un 2> /dev/null`
if test -z "$user"; then
    uid="$USER"
fi
if test "$user" != root; then
    # ... with GLOB_ERR
    ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
    ${common_objpfx}posix/globtest -E "$testdir" "noread/*" |
    sort > $testout
    cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
GLOB_ABORTED
EOF

    ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
    ${common_objpfx}posix/globtest -E "$testdir" "noread*/*" |
    sort > $testout
    cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
GLOB_ABORTED
EOF
if test $failed -ne 0; then
  echo "GLOB_ERR test failed" >> $logfile
  result=1
fi
fi # not run as root

# Try multiple patterns (GLOB_APPEND)
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest "$testdir" "file1" "*/*" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
`dir1/file1_1'
`dir1/file1_2'
`file1'
`link1/file1_1'
`link1/file1_2'
EOF
if test $failed -ne 0; then
  echo "GLOB_APPEND test failed" >> $logfile
  result=1
fi

# Try multiple patterns (GLOB_APPEND) with offset (GLOB_DOOFFS)
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -o "$testdir" "file1" "*/*" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
`abc'
`dir1/file1_1'
`dir1/file1_2'
`file1'
`link1/file1_1'
`link1/file1_2'
EOF
if test $failed -ne 0; then
  echo "GLOB_APPEND2 test failed" >> $logfile
  result=1
fi

# Test NOCHECK with non-existing file in subdir.
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -c "$testdir" "*/blahblah" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
`*/blahblah'
EOF
if test $failed -ne 0; then
  echo "No check2 test failed" >> $logfile
  result=1
fi

# Test [[:punct:]] not matching leading period.
failed=0
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -c "$testdir" "[[:punct:]]*" |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
`*file6'
`-file3'
`\file9b\'
`\{file8\}'
`\{file9\,file9b\}'
`{file7,}'
`~file4'
EOF
if test $failed -ne 0; then
  echo "Punct test failed" >> $logfile
  result=1
fi

mkdir $testdir/'dir3*'
echo 1 > $testdir/'dir3*'/file1
mkdir $testdir/'dir4[a'
echo 2 > $testdir/'dir4[a'/file1
echo 3 > $testdir/'dir4[a'/file2
mkdir $testdir/'dir5[ab]'
echo 4 > $testdir/'dir5[ab]'/file1
echo 5 > $testdir/'dir5[ab]'/file2
mkdir $testdir/dir6
echo 6 > $testdir/dir6/'file1[a'
echo 7 > $testdir/dir6/'file1[ab]'
failed=0
v=`${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
   ${common_objpfx}posix/globtest "$testdir" 'dir3\*/file2'`
test "$v" != 'GLOB_NOMATCH' && echo "$v" >> $logfile && failed=1
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -c "$testdir" \
'dir3\*/file1' 'dir3\*/file2' 'dir1/file\1_1' 'dir1/file\1_9' \
'dir2\/' 'nondir\/' 'dir4[a/fil*1' 'di*r4[a/file2' 'dir5[ab]/file[12]' \
'dir6/fil*[a' 'dir*6/file1[a' 'dir6/fi*l[ab]' 'dir*6/file1[ab]' |
sort > $testout
cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
`di*r4[a/file2'
`dir*6/file1[a'
`dir*6/file1[ab]'
`dir1/file1_1'
`dir1/file\1_9'
`dir2/'
`dir3*/file1'
`dir3\*/file2'
`dir4[a/fil*1'
`dir5[ab]/file[12]'
`dir6/fi*l[ab]'
`dir6/fil*[a'
`nondir\/'
EOF
HOME="$testdir" \
${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
${common_objpfx}posix/globtest -ct "$testdir" \
'~/dir1/file1_1' '~/dir1/file1_9' '~/dir3\*/file1' '~/dir3\*/file2' \
'~\/dir1/file1_2' |
sort > $testout
cat <<EOF | $CMP - $testout >> $logfile || failed=1
\`$testdir/dir1/file1_1'
\`$testdir/dir1/file1_2'
\`$testdir/dir3*/file1'
\`~/dir1/file1_9'
\`~/dir3\\*/file2'
EOF
if eval test -d ~"$USER"/; then
  user=`echo "$USER" | sed -n -e 's/^\([^\\]\)\([^\\][^\\]*\)$/~\1\\\\\2/p'`
  if test -n "$user"; then
    ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
    ${common_objpfx}posix/globtest -ctq "$testdir" "$user/" |
    sort > $testout
    eval echo ~$USER/ | $CMP - $testout >> $logfile || failed=1
    ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
    ${common_objpfx}posix/globtest -ctq "$testdir" "$user\\/" |
    sort > $testout
    eval echo ~$USER/ | $CMP - $testout >> $logfile || failed=1
    ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
    ${common_objpfx}posix/globtest -ctq "$testdir" "$user" |
    sort > $testout
    eval echo ~$USER | $CMP - $testout >> $logfile || failed=1
  fi
fi
if test $failed -ne 0; then
  echo "Escape tests failed" >> $logfile
  result=1
fi

if test $result -eq 0; then
    chmod 777 $testdir/noread
    rm -fr $testdir $testout
    echo "All OK." > $logfile
fi

exit $result

# Preserve executable bits for this shell script.
Local Variables:
eval:(defun frobme () (set-file-modes buffer-file-name file-mode))
eval:(make-local-variable 'file-mode)
eval:(setq file-mode (file-modes (buffer-file-name)))
eval:(make-local-variable 'after-save-hook)
eval:(add-hook 'after-save-hook 'frobme)
End: