Blame posix/wordexp-tst.sh

Packit 6c4009
#!/bin/sh
Packit 6c4009
# Test for wordexp(3).
Packit 6c4009
# Copyright (C) 1998-2018 Free Software Foundation, Inc.
Packit 6c4009
# This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
# The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
# modify it under the terms of the GNU Lesser General Public
Packit 6c4009
# License as published by the Free Software Foundation; either
Packit 6c4009
# version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
# The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
# Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
# You should have received a copy of the GNU Lesser General Public
Packit 6c4009
# License along with the GNU C Library; if not, see
Packit 6c4009
# <http://www.gnu.org/licenses/>.
Packit 6c4009
Packit 6c4009
set -e
Packit 6c4009
Packit 6c4009
# Some of these tests may look a little weird.
Packit 6c4009
# The first parameter to wordexp-test is what it gives to wordexp.
Packit 6c4009
# The others are just there to be parameters.
Packit 6c4009
Packit 6c4009
common_objpfx=$1; shift
Packit 6c4009
test_program_prefix_before_env=$1; shift
Packit 6c4009
run_program_env=$1; shift
Packit 6c4009
test_program_prefix_after_env=$1; shift
Packit 6c4009
logfile=${common_objpfx}posix/wordexp-tst.out
Packit 6c4009
testout=${common_objpfx}posix/wordexp-test-result
Packit 6c4009
Packit 6c4009
result=0
Packit 6c4009
rm -f $logfile
Packit 6c4009
# This is written in this funny way so that there is no trailing whitespace.
Packit 6c4009
# The first line contains a space followed by a tab.
Packit 6c4009
IFS=" 	\
Packit 6c4009
Packit 6c4009
"
Packit 6c4009
export IFS
Packit 6c4009
Packit 6c4009
failed=0
Packit 6c4009
${test_program_prefix_before_env} ${run_program_env} IFS="$IFS" \
Packit 6c4009
${test_program_prefix_after_env} \
Packit 6c4009
${common_objpfx}posix/wordexp-test '$*' > ${testout}1
Packit 6c4009
cat <<"EOF" | cmp - ${testout}1 >> $logfile || failed=1
Packit 6c4009
wordexp returned 0
Packit 6c4009
we_wordv[0] = "$*"
Packit 6c4009
EOF
Packit 6c4009
if test $failed -ne 0; then
Packit 6c4009
  echo '$* test failed'
Packit 6c4009
  status=1
Packit 6c4009
fi
Packit 6c4009
Packit 6c4009
failed=0
Packit 6c4009
${test_program_prefix_before_env} ${run_program_env} IFS="$IFS" \
Packit 6c4009
${test_program_prefix_after_env} \
Packit 6c4009
${common_objpfx}posix/wordexp-test '${*}' unquoted > ${testout}2
Packit 6c4009
cat <<"EOF" | cmp - ${testout}2 >> $logfile || failed=1
Packit 6c4009
wordexp returned 0
Packit 6c4009
we_wordv[0] = "${*}"
Packit 6c4009
we_wordv[1] = "unquoted"
Packit 6c4009
EOF
Packit 6c4009
if test $failed -ne 0; then
Packit 6c4009
  echo '${*} test failed'
Packit 6c4009
  status=1
Packit 6c4009
fi
Packit 6c4009
Packit 6c4009
failed=0
Packit 6c4009
${test_program_prefix_before_env} ${run_program_env} IFS="$IFS" \
Packit 6c4009
${test_program_prefix_after_env} \
Packit 6c4009
${common_objpfx}posix/wordexp-test '$@' unquoted > ${testout}3
Packit 6c4009
cat <<"EOF" | cmp - ${testout}3 >> $logfile || failed=1
Packit 6c4009
wordexp returned 0
Packit 6c4009
we_wordv[0] = "$@"
Packit 6c4009
we_wordv[1] = "unquoted"
Packit 6c4009
EOF
Packit 6c4009
if test $failed -ne 0; then
Packit 6c4009
  echo '$@ test failed'
Packit 6c4009
  status=1
Packit 6c4009
fi
Packit 6c4009
Packit 6c4009
failed=0
Packit 6c4009
${test_program_prefix_before_env} ${run_program_env} IFS="$IFS" \
Packit 6c4009
${test_program_prefix_after_env} \
Packit 6c4009
${common_objpfx}posix/wordexp-test '"$* quoted"' param > ${testout}4
Packit 6c4009
cat <<"EOF" | cmp - ${testout}4 >> $logfile || failed=1
Packit 6c4009
wordexp returned 0
Packit 6c4009
we_wordv[0] = ""$* quoted" param quoted"
Packit 6c4009
EOF
Packit 6c4009
if test $failed -ne 0; then
Packit 6c4009
  echo '$* quoted test failed'
Packit 6c4009
  status=1
Packit 6c4009
fi
Packit 6c4009
Packit 6c4009
failed=0
Packit 6c4009
${test_program_prefix_before_env} ${run_program_env} IFS="$IFS" \
Packit 6c4009
${test_program_prefix_after_env} \
Packit 6c4009
${common_objpfx}posix/wordexp-test '"$@ quoted"' param > ${testout}5
Packit 6c4009
cat <<"EOF" | cmp - ${testout}5 >> $logfile || failed=1
Packit 6c4009
wordexp returned 0
Packit 6c4009
we_wordv[0] = ""$@ quoted""
Packit 6c4009
we_wordv[1] = "param quoted"
Packit 6c4009
EOF
Packit 6c4009
if test $failed -ne 0; then
Packit 6c4009
  echo '$@ quoted test failed'
Packit 6c4009
  status=1
Packit 6c4009
fi
Packit 6c4009
# Why?  Because bash does it that way..
Packit 6c4009
Packit 6c4009
failed=0
Packit 6c4009
${test_program_prefix_before_env} ${run_program_env} IFS="$IFS" \
Packit 6c4009
${test_program_prefix_after_env} \
Packit 6c4009
${common_objpfx}posix/wordexp-test '$#' 2 3 4 5 > ${testout}6
Packit 6c4009
cat <<"EOF" | cmp - ${testout}6 >> $logfile || failed=1
Packit 6c4009
wordexp returned 0
Packit 6c4009
we_wordv[0] = "5"
Packit 6c4009
EOF
Packit 6c4009
if test $failed -ne 0; then
Packit 6c4009
  echo '$# test failed'
Packit 6c4009
  status=1
Packit 6c4009
fi
Packit 6c4009
Packit 6c4009
failed=0
Packit 6c4009
${test_program_prefix_before_env} ${run_program_env} IFS="$IFS" \
Packit 6c4009
${test_program_prefix_after_env} \
Packit 6c4009
${common_objpfx}posix/wordexp-test '$2 ${3} $4' 2nd 3rd "4 th" > ${testout}7
Packit 6c4009
cat <<"EOF" | cmp - ${testout}7 >> $logfile || failed=1
Packit 6c4009
wordexp returned 0
Packit 6c4009
we_wordv[0] = "2nd"
Packit 6c4009
we_wordv[1] = "3rd"
Packit 6c4009
we_wordv[2] = "4"
Packit 6c4009
we_wordv[3] = "th"
Packit 6c4009
EOF
Packit 6c4009
if test $failed -ne 0; then
Packit 6c4009
  echo '$2 ${3} $4 test failed'
Packit 6c4009
  status=1
Packit 6c4009
fi
Packit 6c4009
Packit 6c4009
failed=0
Packit 6c4009
${test_program_prefix_before_env} ${run_program_env} IFS="$IFS" \
Packit 6c4009
${test_program_prefix_after_env} \
Packit 6c4009
${common_objpfx}posix/wordexp-test '${11}' 2 3 4 5 6 7 8 9 10 11 > ${testout}8
Packit 6c4009
cat <<"EOF" | cmp - ${testout}8 >> $logfile || failed=1
Packit 6c4009
wordexp returned 0
Packit 6c4009
we_wordv[0] = "11"
Packit 6c4009
EOF
Packit 6c4009
if test $failed -ne 0; then
Packit 6c4009
  echo '${11} test failed'
Packit 6c4009
  status=1
Packit 6c4009
fi
Packit 6c4009
Packit 6c4009
failed=0
Packit 6c4009
${test_program_prefix_before_env} ${run_program_env} IFS="$IFS" \
Packit 6c4009
${test_program_prefix_after_env} \
Packit 6c4009
${common_objpfx}posix/wordexp-test '"a $@ b"' c d > ${testout}9
Packit 6c4009
cat <<"EOF" | cmp - ${testout}9 >> $logfile || failed=1
Packit 6c4009
wordexp returned 0
Packit 6c4009
we_wordv[0] = "a "a $@ b""
Packit 6c4009
we_wordv[1] = "c"
Packit 6c4009
we_wordv[2] = "d b"
Packit 6c4009
EOF
Packit 6c4009
if test $failed -ne 0; then
Packit 6c4009
  echo '"a $@ b" test failed'
Packit 6c4009
  status=1
Packit 6c4009
fi
Packit 6c4009
Packit 6c4009
${test_program_prefix_before_env} ${run_program_env} IFS="$IFS" \
Packit 6c4009
${test_program_prefix_after_env} \
Packit 6c4009
${common_objpfx}posix/wordexp-test '${#@} ${#2} *$**' two 3 4 > ${testout}10
Packit 6c4009
cat <<"EOF" | cmp - ${testout}10 || failed=1
Packit 6c4009
wordexp returned 0
Packit 6c4009
we_wordv[0] = "4"
Packit 6c4009
we_wordv[1] = "3"
Packit 6c4009
we_wordv[2] = "*${#@}"
Packit 6c4009
we_wordv[3] = "${#2}"
Packit 6c4009
we_wordv[4] = "*$**"
Packit 6c4009
we_wordv[5] = "two"
Packit 6c4009
we_wordv[6] = "3"
Packit 6c4009
we_wordv[7] = "4*"
Packit 6c4009
EOF
Packit 6c4009
Packit 6c4009
exit $result