summaryrefslogtreecommitdiff
path: root/tests/getopt-m4sh.at
blob: 4c11dbf5b3627ebb3bcfa3a74eb645a9c25360b3 (plain)
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
# getopts-m4sh.at -- test getopts.m4sh option parsers       -*- Autotest -*-
#
#   Copyright (C) 2010 Free Software Foundation, Inc.
#   Written by Gary V. Vaughan, 2010
#
#   This file is part of GNU Libtool.
#
# GNU Libtool is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
#
# GNU Libtool 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Libtool; see the file COPYING.  If not, a copy
# can be downloaded from  http://www.gnu.org/licenses/gpl.html,
# or obtained by writing to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
####

AT_BANNER([Shell option parser generator.])


# _LT_AT_GETOPT_M4SH_SETUP
# ------------------------
m4_define([_LT_AT_GETOPT_M4SH_SETUP],
[m4_pattern_allow([AS_INIT])
m4_pattern_allow([m4_include])
AT_DATA([options.m4sh],
[[AS_INIT[]m4_include([getopt.m4sh])
nl='
'
list=
opts=
M4SH_GETOPTS(
  [a!],	[--append],	[],	[func_append list "$optarg$nl"],
  [f],	[--force],	[],	[opts="$opts force"],
  [i],	[--install],	[],	[opts="$opts install"],
  [v],	[--verbose],	[],	[opts="$opts verbose"],
  [!],	[--ltdl],	[false],[opts="$opts ltdl=$optarg"],
[echo "$list" $opts])
]])
m4_pattern_forbid([m4_include])
m4_pattern_forbid([AS_INIT])
AT_CHECK([$M4SH --version || exit 77], [], [ignore], [ignore])
AT_CHECK([$M4SH -B $abs_top_srcdir/build-aux options.m4sh > t-options],
	 [], [], [], [AT_CHECK([test $at_status -eq 63 && exit 77])])
$SED "s,@LN_S\@,$LN_S,g;s,@SED\@,$SED,g" t-options > options
])# _LT_AT_GETOPT_M4SH_SETUP


# _LT_AT_FALLBACK_FUNC_EXTRACT(FUNC-NAME)
# ---------------------------------------
# Extract the fallback function FUNC-NAME from ltmain.m4sh
m4_define([_LT_AT_FALLBACK_FUNC_EXTRACT],
[dnl {{
$SED '/^# func_dirname /q' options > options.tmp
echo '# func_append var value' >> options.tmp
$SED -n '/^$1 ()/,/^} # $1 /p' $abs_top_srcdir/build-aux/ltmain.m4sh >> options.tmp
$SED '1,/^# func_dirname/d' options >> options.tmp
rm -f options && mv options.tmp options])


# _LT_AT_EXTENDED_SHELL_FUNC_EXTRACT(FUNC-NAME)
# ---------------------------------------------
# Extract the 'Extended-shell'-decorated function FUNC-NAME from libtool
m4_define([_LT_AT_XSI_FUNC_EXTRACT],
[dnl {{
$SED '/^# $1/q' options > options.tmp
$SED -n '/^$1 ()/,/^} # Extended-shell $1 /p' $abs_top_builddir/libtool >> options.tmp
$SED '1,/^} # $1 /d' options >> options.tmp
rm -f options && mv options.tmp options])


## ----------------------- ##
## Short option splitting. ##
## ----------------------- ##

AT_SETUP([short option splitting])

AT_DATA(expout,
[[ force verbose install
]])

_LT_AT_GETOPT_M4SH_SETUP

AT_CHECK([$SHELL ./options -fvi], 0, [expout])

AT_CLEANUP


AT_SETUP([enhanced shell short option splitting])

# Don't bother with additional XSI checks unless functions were substituted
AT_CHECK([fgrep '@%:@ Extended-shell func_split_short_opt' $abs_top_builddir/libtool >/dev/null 2>&1 || (exit 77)])

AT_DATA(expout,
[[ force verbose install
]])

_LT_AT_GETOPT_M4SH_SETUP
_LT_AT_XSI_FUNC_EXTRACT(func_split_short_opt)

AT_CHECK([$SHELL ./options -fvi], 0, [expout])

AT_CLEANUP


## ---------------------- ##
## Long option splitting. ##
## ---------------------- ##

AT_SETUP([long option splitting])

AT_DATA(expout,
[[ ltdl=long
]])

_LT_AT_GETOPT_M4SH_SETUP

AT_CHECK([$SHELL ./options --ltdl=long], 0, [expout])

AT_CLEANUP


AT_SETUP([XSI long option splitting])

# Don't bother with additional XSI checks unless functions were substituted
AT_CHECK([fgrep '@%:@ Extended-shell func_split_long_opt' $abs_top_builddir/libtool >/dev/null 2>&1 || (exit 77)])

AT_DATA(expout,
[[ ltdl=long
]])

_LT_AT_GETOPT_M4SH_SETUP
_LT_AT_XSI_FUNC_EXTRACT(func_split_long_opt)

AT_CHECK([$SHELL ./options --ltdl=long], 0, [expout])

AT_CLEANUP


## ----------------- ##
## Option appending. ##
## ----------------- ##

AT_SETUP([option appending])

AT_DATA(expout,
[[first   --append second
third

]])

_LT_AT_GETOPT_M4SH_SETUP
_LT_AT_FALLBACK_FUNC_EXTRACT(func_append)

AT_CHECK([$SHELL ./options -a "first   --append second" -athird], 0, [expout])

AT_CLEANUP


AT_SETUP([enhanced shell option appending])

# Don't bother with additional += check unless functions were substituted
AT_CHECK([fgrep '@%:@ Extended-shell func_append ' $abs_top_builddir/libtool >/dev/null 2>&1 || (exit 77)])

AT_DATA(expout,
[[first   --append second
third

]])

_LT_AT_GETOPT_M4SH_SETUP
_LT_AT_FALLBACK_FUNC_EXTRACT(func_append)
_LT_AT_XSI_FUNC_EXTRACT(func_append)

AT_CHECK([$SHELL ./options -a "first   --append second" -athird], 0, [expout])

AT_CLEANUP