summaryrefslogtreecommitdiff
path: root/tests/init.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tests/init.sh')
-rw-r--r--tests/init.sh71
1 files changed, 56 insertions, 15 deletions
diff --git a/tests/init.sh b/tests/init.sh
index 3bd1e3b9..21a43898 100644
--- a/tests/init.sh
+++ b/tests/init.sh
@@ -1,6 +1,6 @@
# source this file; set up for tests
-# Copyright (C) 2009-2024 Free Software Foundation, Inc.
+# Copyright (C) 2009-2025 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -103,7 +103,11 @@ warn_ ()
case $IFS in
' '*) printf '%s\n' "$*" >&2
test $stderr_fileno_ = 2 \
- || { printf '%s\n' "$*" | sed 1q >&$stderr_fileno_ ; } ;;
+ || { local args=$*
+ local firstline=${args%%"$gl_init_sh_nl_"*}
+ printf '%s\n' "$firstline" >&$stderr_fileno_
+ }
+ ;;
*) (IFS=' '; warn_ "$@");;
esac
}
@@ -160,12 +164,12 @@ fi
# ? - not ok
gl_shell_test_script_='
test $(echo y) = y || exit 1
-LC_ALL=en_US.UTF-8 printf "\\351" 2>/dev/null \
- | LC_ALL=C tr "\\351" x | LC_ALL=C grep "^x$" > /dev/null \
- || exit 1
-printf "\\351" 2>/dev/null \
- | LC_ALL=C tr "\\351" x | LC_ALL=C grep "^x$" > /dev/null \
- || exit 1
+case $({ LC_ALL=en_US.UTF-8 printf "\\351"
+ printf "\\351\\n"
+ } 2>/dev/null | LC_ALL=C tr "\\351" x) in
+ xx) ;;
+ *) exit 1;;
+esac
f_local_() { local v=1; }; f_local_ || exit 1
f_dash_local_fail_() { local t=$(printf " 1"); }; f_dash_local_fail_
score_=10
@@ -267,7 +271,7 @@ test -n "$EXEEXT" && test -n "$BASH_VERSION" && shopt -s expand_aliases
# Create a temporary directory, much like mktemp -d does.
# Written by Jim Meyering.
#
-# Usage: mktempd_ /tmp phoey.XXXXXXXXXX
+# Usage: mktempd_ /tmp template.XXXXXXXXXX
#
# First, try to use the mktemp program.
# Failing that, we'll roll our own mktemp-like function:
@@ -277,6 +281,19 @@ test -n "$EXEEXT" && test -n "$BASH_VERSION" && shopt -s expand_aliases
# - try to create the desired directory.
# - make only $MAX_TRIES_ attempts
+# mkdir on msys2 does not support the '-m' option.
+case `(uname -o) 2>/dev/null` in
+ Msys)
+ mkdir ()
+ {
+ if test " $1" = " -m"; then
+ shift; shift
+ fi
+ /bin/mkdir "$@"
+ }
+ ;;
+esac
+
# Helper function. Print $N pseudo-random bytes from a-zA-Z0-9.
rand_bytes_ ()
{
@@ -381,7 +398,7 @@ mktempd_ ()
err_=`mkdir -m 0700 "$candidate_dir_" 2>&1` \
&& { echo "$candidate_dir_"; return; }
test $MAX_TRIES_ -le $i_ && break;
- i_=`expr $i_ + 1`
+ i_=`expr $i_ + 1` || break
done
fail_ "$err_"
}
@@ -398,7 +415,7 @@ setup_ ()
if test "$VERBOSE" = yes; then
# Test whether set -x may cause the selected shell to corrupt an
# application's stderr. Many do, including zsh-4.3.10 and the /bin/sh
- # from SunOS 5.11, OpenBSD 4.7 and Irix 6.5.
+ # from SunOS 5.11 and OpenBSD 4.7.
# If enabling verbose output this way would cause trouble, simply
# issue a warning and refrain.
if $gl_set_x_corrupts_stderr_; then
@@ -471,8 +488,11 @@ remove_tmp_ ()
# cd out of the directory we're about to remove
cd "$initial_cwd_" || cd / || cd /tmp
chmod -R u+rwx "$test_dir_"
- # If removal fails and exit status was to be 0, then change it to 1.
- rm -rf "$test_dir_" || { test $__st = 0 && __st=1; }
+ # If the first removal fails, wait for subprocesses to exit and try again.
+ # If that fails and exit status was to be 0, change it to 1.
+ rm -rf "$test_dir_" 2>/dev/null \
+ || { sleep 1 && rm -rf "$test_dir_"; } \
+ || { test $__st = 0 && __st=1; }
fi
exit $__st
}
@@ -626,7 +646,7 @@ emit_diff_u_header_ ()
}
# Arrange not to let diff or cmp operate on /dev/null,
-# since on some systems (at least OSF/1 5.1), that doesn't work.
+# since on some old systems, that doesn't work.
# When there are not two arguments, or no argument is /dev/null, return 2.
# When one argument is /dev/null and the other is not empty,
# cat the nonempty file to stderr and return 1.
@@ -658,7 +678,28 @@ for diff_opt_ in -u -U3 -c '' no; do
done
if test "$diff_opt_" != no; then
if test -z "$diff_out_"; then
- compare_ () { LC_ALL=C diff $diff_opt_ "$@"; }
+ # diff on msys2 does not support the '-' argument for denoting stdin.
+ case `(uname -o) 2>/dev/null` in
+ Msys)
+ compare_ ()
+ {
+ if test " $1" = " -"; then
+ cat > '(stdin)'
+ LC_ALL=C diff $diff_opt_ '(stdin)' "$2"
+ elif test " $2" = " -"; then
+ cat > '(stdin)'
+ LC_ALL=C diff $diff_opt_ "$1" '(stdin)'
+ else
+ LC_ALL=C diff $diff_opt_ "$@"
+ fi
+ }
+ ;;
+ *)
+ compare_ ()
+ {
+ LC_ALL=C diff $diff_opt_ "$@"
+ }
+ esac
else
compare_ ()
{