1*4000dbbeSgutteridge# $NetBSD: t_cut.sh,v 1.4 2025/01/24 22:26:41 gutteridge Exp $ 228604916Sjruoho# 328604916Sjruoho# Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. 428604916Sjruoho# All rights reserved. 528604916Sjruoho# 628604916Sjruoho# Redistribution and use in source and binary forms, with or without 728604916Sjruoho# modification, are permitted provided that the following conditions 828604916Sjruoho# are met: 928604916Sjruoho# 1. Redistributions of source code must retain the above copyright 1028604916Sjruoho# notice, this list of conditions and the following disclaimer. 1128604916Sjruoho# 2. Redistributions in binary form must reproduce the above copyright 1228604916Sjruoho# notice, this list of conditions and the following disclaimer in the 1328604916Sjruoho# documentation and/or other materials provided with the distribution. 1428604916Sjruoho# 1528604916Sjruoho# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 1628604916Sjruoho# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 1728604916Sjruoho# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1828604916Sjruoho# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 1928604916Sjruoho# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2028604916Sjruoho# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2128604916Sjruoho# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2228604916Sjruoho# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2328604916Sjruoho# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2428604916Sjruoho# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2528604916Sjruoho# POSSIBILITY OF SUCH DAMAGE. 2628604916Sjruoho# 2728604916Sjruoho 2828604916Sjruohoh_run() 2928604916Sjruoho{ 3028604916Sjruoho file="${1}"; shift 3128604916Sjruoho opts="${*}" 3228604916Sjruoho 3328604916Sjruoho for fields in 1 2 3 1-2 2,3 4 1-3,4-7 1,2-7 3428604916Sjruoho do 3528604916Sjruoho opts="-f ${fields} $@" 3628604916Sjruoho echo "----- test: cut ${opts} $(basename $file) -----" 3728604916Sjruoho cut $opts "$file" || atf_fail "command failed: cut ${opts} $file" 3828604916Sjruoho done 3928604916Sjruoho} 4028604916Sjruoho 4128604916Sjruohoh_check() 4228604916Sjruoho{ 4328604916Sjruoho diff -Nru "$1" "$2" || atf_fail "files $1 and $2 differ" 4428604916Sjruoho} 4528604916Sjruoho 4628604916Sjruohoatf_test_case basic 4728604916Sjruohobasic_head() 4828604916Sjruoho{ 4928604916Sjruoho atf_set "descr" "Checks basic functionality" 5028604916Sjruoho} 5128604916Sjruohobasic_body() 5228604916Sjruoho{ 5328604916Sjruoho h_run "$(atf_get_srcdir)/d_cut.in" > out 5428604916Sjruoho h_check out "$(atf_get_srcdir)/d_basic.out" 5528604916Sjruoho} 5628604916Sjruoho 5728604916Sjruohoatf_test_case sflag 5828604916Sjruohosflag_head() 5928604916Sjruoho{ 6028604916Sjruoho atf_set "descr" "Checks -s flag" 6128604916Sjruoho} 6228604916Sjruohosflag_body() 6328604916Sjruoho{ 6428604916Sjruoho h_run "$(atf_get_srcdir)/d_cut.in" -s > out 6528604916Sjruoho h_check out "$(atf_get_srcdir)/d_sflag.out" 6628604916Sjruoho} 6728604916Sjruoho 6828604916Sjruohoatf_test_case dflag 6928604916Sjruohodflag_head() 7028604916Sjruoho{ 7128604916Sjruoho atf_set "descr" "Checks -d flag" 7228604916Sjruoho} 7328604916Sjruohodflag_body() 7428604916Sjruoho{ 7528604916Sjruoho h_run "$(atf_get_srcdir)/d_cut.in" -d ":" > out 7628604916Sjruoho h_check out "$(atf_get_srcdir)/d_dflag.out" 7728604916Sjruoho} 7828604916Sjruoho 7928604916Sjruohoatf_test_case dsflag 8028604916Sjruohodsflag_head() 8128604916Sjruoho{ 8228604916Sjruoho atf_set "descr" "Checks -s and -d flags combined" 8328604916Sjruoho} 8428604916Sjruohodsflag_body() 8528604916Sjruoho{ 8628604916Sjruoho h_run "$(atf_get_srcdir)/d_cut.in" -d ":" -s > out 8728604916Sjruoho h_check out "$(atf_get_srcdir)/d_dsflag.out" 8828604916Sjruoho} 8928604916Sjruoho 9028604916Sjruohoatf_test_case latin1 9128604916Sjruoholatin1_head() 9228604916Sjruoho{ 9383e5c9bfSgutteridge atf_set "descr" "Checks support for non-ASCII characters" 9428604916Sjruoho} 9528604916Sjruoholatin1_body() 9628604916Sjruoho{ 9728604916Sjruoho export LC_ALL=C 9828604916Sjruoho 9928604916Sjruoho atf_check -o inline:"bar\nBar\nBAr\nBAR\n" \ 10028604916Sjruoho cut -b 6,7,8 "$(atf_get_srcdir)/d_latin1.in" 10128604916Sjruoho 10228604916Sjruoho atf_check -o inline:"bar\nBar\nBAr\nBAR\n" \ 10328604916Sjruoho cut -c 6,7,8 "$(atf_get_srcdir)/d_latin1.in" 10428604916Sjruoho} 10528604916Sjruoho 10628604916Sjruohoatf_test_case utf8 10728604916Sjruohoutf8_head() 10828604916Sjruoho{ 10928604916Sjruoho atf_set "descr" "Checks support for multibyte characters" 11028604916Sjruoho} 11128604916Sjruohoutf8_body() 11228604916Sjruoho{ 11328604916Sjruoho export LC_ALL=en_US.UTF-8 11428604916Sjruoho 11528604916Sjruoho atf_check -o inline:":ba\n:Ba\n:BA\n:BA\n" \ 11628604916Sjruoho cut -b 6,7,8 "$(atf_get_srcdir)/d_utf8.in" 11728604916Sjruoho 11828604916Sjruoho atf_check -o inline:"bar\nBar\nBAr\nBAR\n" \ 11928604916Sjruoho cut -c 6,7,8 "$(atf_get_srcdir)/d_utf8.in" 12028604916Sjruoho} 12128604916Sjruoho 1226db988dfSgutteridgeatf_test_case nflag 1236db988dfSgutteridgenflag_head() 1246db988dfSgutteridge{ 1256db988dfSgutteridge atf_set "descr" "Checks -n flag (PR bin/59029)" 1266db988dfSgutteridge} 1276db988dfSgutteridge 1286db988dfSgutteridgenflag_body() 1296db988dfSgutteridge{ 1306db988dfSgutteridge export LC_ALL=en_US.UTF-8 1316db988dfSgutteridge 1326db988dfSgutteridge atf_expect_fail "PR bin/59029" 1336db988dfSgutteridge atf_check -o inline:"bar\nBar\nBAr\nBAR\n" \ 134*4000dbbeSgutteridge cut -b 6,7,8 -n "$(atf_get_srcdir)/d_utf8.in" 1356db988dfSgutteridge} 1366db988dfSgutteridge 13728604916Sjruohoatf_init_test_cases() 13828604916Sjruoho{ 13928604916Sjruoho atf_add_test_case basic 14028604916Sjruoho atf_add_test_case sflag 14128604916Sjruoho atf_add_test_case dflag 14228604916Sjruoho atf_add_test_case dsflag 14328604916Sjruoho atf_add_test_case latin1 14428604916Sjruoho atf_add_test_case utf8 1456db988dfSgutteridge atf_add_test_case nflag 14628604916Sjruoho} 147