#!/bin/bash
# Test for glob(3).
# Copyright (C) 1997-2025 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# The GNU C Library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# The GNU C Library 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. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with the GNU C Library; if not, see
# <https://www.gnu.org/licenses/>.
set -e
common_objpfx=$1; shift
test_via_rtld_prefix=$1; shift
test_program_prefix=$1; shift
test_wrapper_env=$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
# Since we use `sort' we must make sure to use the same locale everywhere.
LC_ALL=C
export LC_ALL
# Create the arena
testdir=${common_objpfx}posix/globtest-dir
testout=${common_objpfx}posix/globtest-out
rm -rf $testdir $testout
mkdir $testdir
cleanup() {
chmod 777 $testdir/noread
rm -fr $testdir $testout
}
trap cleanup 0 HUP INT QUIT TERM
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
${test_program_prefix} \
${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,}'