xref: /freebsd/usr.bin/locale/tests/locale_test.sh (revision e0c4386e)
1#
2# SPDX-License-Identifier: BSD-2-Clause
3#
4# Copyright 2019 Yuri Pankov
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12#    notice, this list of conditions and the following disclaimer in the
13#    documentation and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25# SUCH DAMAGE.
26#
27
28atf_test_case k_flag_posix
29k_flag_posix_head()
30{
31	atf_set "descr" \
32	    "Verify output of 'locale -k' for all POSIX specified keywords"
33}
34k_flag_posix_body()
35{
36	export LC_ALL="C"
37
38	# LC_MONETARY
39	atf_check -o file:"$(atf_get_srcdir)/k_flag_posix_monetary.out" \
40	    locale -k \
41	    int_curr_symbol \
42	    currency_symbol \
43	    mon_decimal_point \
44	    mon_thousands_sep \
45	    mon_grouping \
46	    positive_sign \
47	    negative_sign \
48	    int_frac_digits \
49	    frac_digits \
50	    p_cs_precedes \
51	    p_sep_by_space \
52	    n_cs_precedes \
53	    n_sep_by_space \
54	    p_sign_posn \
55	    n_sign_posn \
56	    int_p_cs_precedes \
57	    int_n_cs_precedes \
58	    int_p_sep_by_space \
59	    int_n_sep_by_space \
60	    int_p_sign_posn \
61	    int_n_sign_posn
62
63	# LC_NUMERIC
64	atf_check -o file:"$(atf_get_srcdir)/k_flag_posix_numeric.out" \
65	    locale -k \
66	    decimal_point \
67	    thousands_sep \
68	    grouping
69
70	# LC_TIME
71	atf_check -o file:"$(atf_get_srcdir)/k_flag_posix_time.out" \
72	    locale -k \
73	    abday \
74	    day \
75	    abmon \
76	    mon \
77	    d_t_fmt \
78	    d_fmt \
79	    t_fmt \
80	    am_pm \
81	    t_fmt_ampm \
82	    era \
83	    era_d_fmt \
84	    era_t_fmt \
85	    era_d_t_fmt \
86	    alt_digits
87
88	# LC_MESSAGES
89	atf_check -o file:"$(atf_get_srcdir)/k_flag_posix_messages.out" \
90	    locale -k \
91	    yesexpr \
92	    noexpr
93}
94
95atf_test_case no_flags_posix
96no_flags_posix_head()
97{
98	atf_set "descr" \
99	    "Verify output of 'locale' for all POSIX specified keywords"
100}
101no_flags_posix_body()
102{
103	export LC_ALL="C"
104
105	# LC_MONETARY
106	atf_check -o file:"$(atf_get_srcdir)/no_flags_posix_monetary.out" \
107	    locale \
108	    int_curr_symbol \
109	    currency_symbol \
110	    mon_decimal_point \
111	    mon_thousands_sep \
112	    mon_grouping \
113	    positive_sign \
114	    negative_sign \
115	    int_frac_digits \
116	    frac_digits \
117	    p_cs_precedes \
118	    p_sep_by_space \
119	    n_cs_precedes \
120	    n_sep_by_space \
121	    p_sign_posn \
122	    n_sign_posn \
123	    int_p_cs_precedes \
124	    int_n_cs_precedes \
125	    int_p_sep_by_space \
126	    int_n_sep_by_space \
127	    int_p_sign_posn \
128	    int_n_sign_posn
129
130	# LC_NUMERIC
131	atf_check -o file:"$(atf_get_srcdir)/no_flags_posix_numeric.out" \
132	    locale \
133	    decimal_point \
134	    thousands_sep \
135	    grouping
136
137	# LC_TIME
138	atf_check -o file:"$(atf_get_srcdir)/no_flags_posix_time.out" \
139	    locale \
140	    abday \
141	    day \
142	    abmon \
143	    mon \
144	    d_t_fmt \
145	    d_fmt \
146	    t_fmt \
147	    am_pm \
148	    t_fmt_ampm \
149	    era \
150	    era_d_fmt \
151	    era_t_fmt \
152	    era_d_t_fmt \
153	    alt_digits
154
155	# LC_MESSAGES
156	atf_check -o file:"$(atf_get_srcdir)/no_flags_posix_messages.out" \
157	    locale \
158	    yesexpr \
159	    noexpr
160}
161
162atf_test_case k_flag_unknown_kw
163k_flag_unknown_kw_head()
164{
165	atf_set "descr" \
166	    "Verify 'locale -k' exit status is '1' for unknown keywords"
167}
168k_flag_unknown_kw_body()
169{
170	export LC_ALL="C"
171
172	# Hopefully the keyword will stay nonexistent
173	atf_check -s exit:1 -o empty -e ignore locale -k nonexistent
174}
175
176
177atf_init_test_cases()
178{
179	atf_add_test_case k_flag_posix
180	atf_add_test_case no_flags_posix
181	atf_add_test_case k_flag_unknown_kw
182}
183