t_cut.sh revision 1.3
11.3Sgutterid# $NetBSD: t_cut.sh,v 1.3 2025/01/24 22:23:38 gutteridge Exp $
21.1Sjruoho#
31.1Sjruoho# Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
41.1Sjruoho# All rights reserved.
51.1Sjruoho#
61.1Sjruoho# Redistribution and use in source and binary forms, with or without
71.1Sjruoho# modification, are permitted provided that the following conditions
81.1Sjruoho# are met:
91.1Sjruoho# 1. Redistributions of source code must retain the above copyright
101.1Sjruoho#    notice, this list of conditions and the following disclaimer.
111.1Sjruoho# 2. Redistributions in binary form must reproduce the above copyright
121.1Sjruoho#    notice, this list of conditions and the following disclaimer in the
131.1Sjruoho#    documentation and/or other materials provided with the distribution.
141.1Sjruoho#
151.1Sjruoho# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
161.1Sjruoho# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
171.1Sjruoho# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
181.1Sjruoho# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
191.1Sjruoho# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
201.1Sjruoho# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
211.1Sjruoho# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
221.1Sjruoho# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
231.1Sjruoho# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
241.1Sjruoho# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
251.1Sjruoho# POSSIBILITY OF SUCH DAMAGE.
261.1Sjruoho#
271.1Sjruoho
281.1Sjruohoh_run()
291.1Sjruoho{
301.1Sjruoho	file="${1}"; shift
311.1Sjruoho	opts="${*}"
321.1Sjruoho
331.1Sjruoho	for fields in 1 2 3 1-2 2,3 4 1-3,4-7 1,2-7
341.1Sjruoho	do
351.1Sjruoho		opts="-f ${fields} $@"
361.1Sjruoho		echo "----- test: cut ${opts} $(basename $file) -----"
371.1Sjruoho		cut $opts "$file" || atf_fail "command failed: cut ${opts} $file"
381.1Sjruoho	done
391.1Sjruoho}
401.1Sjruoho
411.1Sjruohoh_check()
421.1Sjruoho{
431.1Sjruoho	diff -Nru "$1" "$2" || atf_fail "files $1 and $2 differ"
441.1Sjruoho}
451.1Sjruoho
461.1Sjruohoatf_test_case basic
471.1Sjruohobasic_head()
481.1Sjruoho{
491.1Sjruoho	atf_set "descr" "Checks basic functionality"
501.1Sjruoho}
511.1Sjruohobasic_body()
521.1Sjruoho{
531.1Sjruoho	h_run "$(atf_get_srcdir)/d_cut.in" > out
541.1Sjruoho	h_check out "$(atf_get_srcdir)/d_basic.out"
551.1Sjruoho}
561.1Sjruoho
571.1Sjruohoatf_test_case sflag
581.1Sjruohosflag_head()
591.1Sjruoho{
601.1Sjruoho	atf_set "descr" "Checks -s flag"
611.1Sjruoho}
621.1Sjruohosflag_body()
631.1Sjruoho{
641.1Sjruoho	h_run "$(atf_get_srcdir)/d_cut.in" -s > out
651.1Sjruoho	h_check out "$(atf_get_srcdir)/d_sflag.out"
661.1Sjruoho}
671.1Sjruoho
681.1Sjruohoatf_test_case dflag
691.1Sjruohodflag_head()
701.1Sjruoho{
711.1Sjruoho	atf_set "descr" "Checks -d flag"
721.1Sjruoho}
731.1Sjruohodflag_body()
741.1Sjruoho{
751.1Sjruoho	h_run "$(atf_get_srcdir)/d_cut.in" -d ":" > out
761.1Sjruoho	h_check out "$(atf_get_srcdir)/d_dflag.out"
771.1Sjruoho}
781.1Sjruoho
791.1Sjruohoatf_test_case dsflag
801.1Sjruohodsflag_head()
811.1Sjruoho{
821.1Sjruoho	atf_set "descr" "Checks -s and -d flags combined"
831.1Sjruoho}
841.1Sjruohodsflag_body()
851.1Sjruoho{
861.1Sjruoho	h_run "$(atf_get_srcdir)/d_cut.in" -d ":" -s > out
871.1Sjruoho	h_check out "$(atf_get_srcdir)/d_dsflag.out"
881.1Sjruoho}
891.1Sjruoho
901.1Sjruohoatf_test_case latin1
911.1Sjruoholatin1_head()
921.1Sjruoho{
931.2Sgutterid	atf_set "descr" "Checks support for non-ASCII characters"
941.1Sjruoho}
951.1Sjruoholatin1_body()
961.1Sjruoho{
971.1Sjruoho	export LC_ALL=C
981.1Sjruoho
991.1Sjruoho	atf_check -o inline:"bar\nBar\nBAr\nBAR\n" \
1001.1Sjruoho		cut -b 6,7,8 "$(atf_get_srcdir)/d_latin1.in"
1011.1Sjruoho
1021.1Sjruoho	atf_check -o inline:"bar\nBar\nBAr\nBAR\n" \
1031.1Sjruoho		cut -c 6,7,8 "$(atf_get_srcdir)/d_latin1.in"
1041.1Sjruoho}
1051.1Sjruoho
1061.1Sjruohoatf_test_case utf8
1071.1Sjruohoutf8_head()
1081.1Sjruoho{
1091.1Sjruoho	atf_set "descr" "Checks support for multibyte characters"
1101.1Sjruoho}
1111.1Sjruohoutf8_body()
1121.1Sjruoho{
1131.1Sjruoho	export LC_ALL=en_US.UTF-8
1141.1Sjruoho
1151.1Sjruoho	atf_check -o inline:":ba\n:Ba\n:BA\n:BA\n" \
1161.1Sjruoho		cut -b 6,7,8 "$(atf_get_srcdir)/d_utf8.in"
1171.1Sjruoho
1181.1Sjruoho	atf_check -o inline:"bar\nBar\nBAr\nBAR\n" \
1191.1Sjruoho		cut -c 6,7,8 "$(atf_get_srcdir)/d_utf8.in"
1201.1Sjruoho}
1211.1Sjruoho
1221.3Sgutteridatf_test_case nflag
1231.3Sgutteridnflag_head()
1241.3Sgutterid{
1251.3Sgutterid	atf_set "descr" "Checks -n flag (PR bin/59029)"
1261.3Sgutterid}
1271.3Sgutterid
1281.3Sgutteridnflag_body()
1291.3Sgutterid{
1301.3Sgutterid	export LC_ALL=en_US.UTF-8
1311.3Sgutterid
1321.3Sgutterid	atf_expect_fail "PR bin/59029"
1331.3Sgutterid	atf_check -o inline:"bar\nBar\nBAr\nBAR\n" \
1341.3Sgutterid		cut -b -n 6,7,8 "$(atf_get_srcdir)/d_utf8.in"
1351.3Sgutterid}
1361.3Sgutterid
1371.1Sjruohoatf_init_test_cases()
1381.1Sjruoho{
1391.1Sjruoho	atf_add_test_case basic
1401.1Sjruoho	atf_add_test_case sflag
1411.1Sjruoho	atf_add_test_case dflag
1421.1Sjruoho	atf_add_test_case dsflag
1431.1Sjruoho	atf_add_test_case latin1
1441.1Sjruoho	atf_add_test_case utf8
1451.3Sgutterid	atf_add_test_case nflag
1461.1Sjruoho}
147