]> git.ipfire.org Git - thirdparty/glibc.git/blame - posix/wordexp-tst.sh
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / posix / wordexp-tst.sh
CommitLineData
48d0341c 1#!/bin/sh
9a9028b1 2# Test for wordexp(3).
04277e02 3# Copyright (C) 1998-2019 Free Software Foundation, Inc.
9a9028b1
DL
4# This file is part of the GNU C Library.
5
6# The GNU C Library is free software; you can redistribute it and/or
7# modify it under the terms of the GNU Lesser General Public
8# License as published by the Free Software Foundation; either
9# version 2.1 of the License, or (at your option) any later version.
10
11# The GNU C Library is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14# Lesser General Public License for more details.
15
16# You should have received a copy of the GNU Lesser General Public
17# License along with the GNU C Library; if not, see
5a82c748 18# <https://www.gnu.org/licenses/>.
14c44e2e 19
57c69bef
DL
20set -e
21
14c44e2e
UD
22# Some of these tests may look a little weird.
23# The first parameter to wordexp-test is what it gives to wordexp.
24# The others are just there to be parameters.
25
26common_objpfx=$1; shift
8540f6d2
JM
27test_program_prefix_before_env=$1; shift
28run_program_env=$1; shift
29test_program_prefix_after_env=$1; shift
ceb579a3
UD
30logfile=${common_objpfx}posix/wordexp-tst.out
31testout=${common_objpfx}posix/wordexp-test-result
14c44e2e 32
3f36c563
UD
33result=0
34rm -f $logfile
31161268
UD
35# This is written in this funny way so that there is no trailing whitespace.
36# The first line contains a space followed by a tab.
37IFS=" \
38
39"
40export IFS
41
3f36c563 42failed=0
8540f6d2
JM
43${test_program_prefix_before_env} ${run_program_env} IFS="$IFS" \
44${test_program_prefix_after_env} \
14c44e2e 45${common_objpfx}posix/wordexp-test '$*' > ${testout}1
3f36c563 46cat <<"EOF" | cmp - ${testout}1 >> $logfile || failed=1
14c44e2e
UD
47wordexp returned 0
48we_wordv[0] = "$*"
49EOF
3f36c563
UD
50if test $failed -ne 0; then
51 echo '$* test failed'
52 status=1
53fi
14c44e2e 54
3f36c563 55failed=0
8540f6d2
JM
56${test_program_prefix_before_env} ${run_program_env} IFS="$IFS" \
57${test_program_prefix_after_env} \
14c44e2e 58${common_objpfx}posix/wordexp-test '${*}' unquoted > ${testout}2
3f36c563 59cat <<"EOF" | cmp - ${testout}2 >> $logfile || failed=1
14c44e2e
UD
60wordexp returned 0
61we_wordv[0] = "${*}"
62we_wordv[1] = "unquoted"
63EOF
3f36c563
UD
64if test $failed -ne 0; then
65 echo '${*} test failed'
66 status=1
67fi
14c44e2e 68
3f36c563 69failed=0
8540f6d2
JM
70${test_program_prefix_before_env} ${run_program_env} IFS="$IFS" \
71${test_program_prefix_after_env} \
14c44e2e 72${common_objpfx}posix/wordexp-test '$@' unquoted > ${testout}3
3f36c563 73cat <<"EOF" | cmp - ${testout}3 >> $logfile || failed=1
14c44e2e
UD
74wordexp returned 0
75we_wordv[0] = "$@"
76we_wordv[1] = "unquoted"
77EOF
3f36c563
UD
78if test $failed -ne 0; then
79 echo '$@ test failed'
80 status=1
81fi
14c44e2e 82
3f36c563 83failed=0
8540f6d2
JM
84${test_program_prefix_before_env} ${run_program_env} IFS="$IFS" \
85${test_program_prefix_after_env} \
14c44e2e 86${common_objpfx}posix/wordexp-test '"$* quoted"' param > ${testout}4
3f36c563 87cat <<"EOF" | cmp - ${testout}4 >> $logfile || failed=1
14c44e2e
UD
88wordexp returned 0
89we_wordv[0] = ""$* quoted" param quoted"
90EOF
3f36c563
UD
91if test $failed -ne 0; then
92 echo '$* quoted test failed'
93 status=1
94fi
14c44e2e 95
3f36c563 96failed=0
8540f6d2
JM
97${test_program_prefix_before_env} ${run_program_env} IFS="$IFS" \
98${test_program_prefix_after_env} \
14c44e2e 99${common_objpfx}posix/wordexp-test '"$@ quoted"' param > ${testout}5
3f36c563 100cat <<"EOF" | cmp - ${testout}5 >> $logfile || failed=1
14c44e2e
UD
101wordexp returned 0
102we_wordv[0] = ""$@ quoted""
103we_wordv[1] = "param quoted"
104EOF
3f36c563
UD
105if test $failed -ne 0; then
106 echo '$@ quoted test failed'
107 status=1
108fi
14c44e2e
UD
109# Why? Because bash does it that way..
110
3f36c563 111failed=0
8540f6d2
JM
112${test_program_prefix_before_env} ${run_program_env} IFS="$IFS" \
113${test_program_prefix_after_env} \
14c44e2e 114${common_objpfx}posix/wordexp-test '$#' 2 3 4 5 > ${testout}6
3f36c563 115cat <<"EOF" | cmp - ${testout}6 >> $logfile || failed=1
14c44e2e
UD
116wordexp returned 0
117we_wordv[0] = "5"
118EOF
3f36c563
UD
119if test $failed -ne 0; then
120 echo '$# test failed'
121 status=1
122fi
14c44e2e 123
3f36c563 124failed=0
8540f6d2
JM
125${test_program_prefix_before_env} ${run_program_env} IFS="$IFS" \
126${test_program_prefix_after_env} \
76fbcfdd 127${common_objpfx}posix/wordexp-test '$2 ${3} $4' 2nd 3rd "4 th" > ${testout}7
3f36c563 128cat <<"EOF" | cmp - ${testout}7 >> $logfile || failed=1
14c44e2e
UD
129wordexp returned 0
130we_wordv[0] = "2nd"
131we_wordv[1] = "3rd"
76fbcfdd
UD
132we_wordv[2] = "4"
133we_wordv[3] = "th"
14c44e2e 134EOF
3f36c563
UD
135if test $failed -ne 0; then
136 echo '$2 ${3} $4 test failed'
137 status=1
138fi
14c44e2e 139
3f36c563 140failed=0
8540f6d2
JM
141${test_program_prefix_before_env} ${run_program_env} IFS="$IFS" \
142${test_program_prefix_after_env} \
31161268 143${common_objpfx}posix/wordexp-test '${11}' 2 3 4 5 6 7 8 9 10 11 > ${testout}8
3f36c563 144cat <<"EOF" | cmp - ${testout}8 >> $logfile || failed=1
31161268
UD
145wordexp returned 0
146we_wordv[0] = "11"
147EOF
3f36c563
UD
148if test $failed -ne 0; then
149 echo '${11} test failed'
150 status=1
151fi
31161268 152
3f36c563 153failed=0
8540f6d2
JM
154${test_program_prefix_before_env} ${run_program_env} IFS="$IFS" \
155${test_program_prefix_after_env} \
31161268 156${common_objpfx}posix/wordexp-test '"a $@ b"' c d > ${testout}9
3f36c563 157cat <<"EOF" | cmp - ${testout}9 >> $logfile || failed=1
31161268
UD
158wordexp returned 0
159we_wordv[0] = "a "a $@ b""
160we_wordv[1] = "c"
161we_wordv[2] = "d b"
162EOF
3f36c563
UD
163if test $failed -ne 0; then
164 echo '"a $@ b" test failed'
165 status=1
166fi
31161268 167
8540f6d2
JM
168${test_program_prefix_before_env} ${run_program_env} IFS="$IFS" \
169${test_program_prefix_after_env} \
e9fc7bbb
UD
170${common_objpfx}posix/wordexp-test '${#@} ${#2} *$**' two 3 4 > ${testout}10
171cat <<"EOF" | cmp - ${testout}10 || failed=1
172wordexp returned 0
173we_wordv[0] = "4"
174we_wordv[1] = "3"
175we_wordv[2] = "*${#@}"
176we_wordv[3] = "${#2}"
177we_wordv[4] = "*$**"
178we_wordv[5] = "two"
179we_wordv[6] = "3"
180we_wordv[7] = "4*"
181EOF
182
3f36c563 183exit $result