1240868Spjd# $NetBSD: t_cat.sh,v 1.3 2016/06/16 01:04:58 sevan Exp $
2240868Spjd#
3240868Spjd# Copyright (c) 2012 The NetBSD Foundation, Inc.
4240868Spjd# All rights reserved.
5240868Spjd#
6240868Spjd# This code is derived from software contributed to The NetBSD Foundation
7240868Spjd# by Jukka Ruohonen.
8240868Spjd#
9240868Spjd# Redistribution and use in source and binary forms, with or without
10240868Spjd# modification, are permitted provided that the following conditions
11240868Spjd# are met:
12240868Spjd# 1. Redistributions of source code must retain the above copyright
13240868Spjd#    notice, this list of conditions and the following disclaimer.
14240868Spjd# 2. Redistributions in binary form must reproduce the above copyright
15240868Spjd#    notice, this list of conditions and the following disclaimer in the
16240868Spjd#    documentation and/or other materials provided with the distribution.
17240868Spjd#
18240868Spjd# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19240868Spjd# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20240868Spjd# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21240868Spjd# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22240868Spjd# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23240868Spjd# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24240868Spjd# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25240868Spjd# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26240868Spjd# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27240868Spjd# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28240868Spjd# POSSIBILITY OF SUCH DAMAGE.
29240868Spjd#
30240868Spjd
31244187Ssmhatf_test_case align
32244187Ssmhalign_head() {
33244187Ssmh	atf_set "descr" "Test that cat(1) aligns the output " \
34244187Ssmh			"right with options '-be' (PR bin/4841)"
35244187Ssmh}
36244187Ssmh
37244187Ssmhalign_body() {
38244187Ssmh
39248572Ssmh	atf_check -s ignore -o file:$(atf_get_srcdir)/d_align.out \
40248572Ssmh		-x "cat -be $(atf_get_srcdir)/d_align.in"
41244187Ssmh}
42240868Spjd
43240868Spjdatf_test_case nonexistent
44240868Spjdnonexistent_head() {
45240868Spjd	atf_set "descr" "Test that cat(1) doesn't return zero exit " \
46240868Spjd			"status for a nonexistent file (PR bin/3538)"
47240868Spjd}
48240868Spjd
49240868Spjdnonexistent_body() {
50240868Spjd
51240868Spjd	atf_check -s not-exit:0 -o empty -e not-empty \
52240868Spjd		-x "cat /some/name/that/does/not/exist"
53240868Spjd}
54240868Spjd
55240868Spjd# Begin FreeBSD
56240868Spjdatf_test_case b_output
57240868Spjdb_output_head() {
58240868Spjd	atf_set "descr" "Test that cat(1) prints out numbers on non-blank "\
59240868Spjd			"lines with '-b'"
60240868Spjd}
61240868Spjd
62240868Spjdb_output_body() {
63240868Spjd	atf_check -o file:$(atf_get_srcdir)/d_b_output.out \
64240868Spjd		cat -b $(atf_get_srcdir)/d_b_output.in
65240868Spjd}
66240868Spjd# End FreeBSD
67240868Spjd
68240868Spjdatf_test_case se_output
69240868Spjdse_output_head() {
70240868Spjd	atf_set "descr" "Test that cat(1) prints a $ sign " \
71240868Spjd			"on blank lines with options '-se' (PR bin/51250)"
72240868Spjd}
73240868Spjd
74240868Spjdse_output_body() {
75240868Spjd	atf_check -s ignore -o file:$(atf_get_srcdir)/d_se_output.out \
76240868Spjd		-x "cat -se $(atf_get_srcdir)/d_se_output.in"
77240868Spjd}
78240868Spjd
79240868Spjd# Begin FreeBSD
80240868Spjdatf_test_case s_output
81240868Spjds_output_head() {
82240868Spjd	atf_set "descr" "Test that cat(1) squeezes multiple adjacent " \
83240868Spjd			"empty lines producing a single spaced output with option '-s'"
84240868Spjd}
85240868Spjd
86240868Spjds_output_body() {
87240868Spjd	atf_check -s ignore -o file:$(atf_get_srcdir)/d_s_output.out \
88240868Spjd		cat -s $(atf_get_srcdir)/d_s_output.in
89240868Spjd}
90240868Spjd
91240868Spjdatf_test_case e_output
92240868Spjde_output_head() {
93240868Spjd	atf_set "descr" "Test that cat(1) prints a $ sign " \
94240868Spjd			"on blank lines with option '-e'"
95240868Spjd}
96240868Spjd
97240868Spjde_output_body() {
98240868Spjd	atf_check -s ignore -o file:$(atf_get_srcdir)/d_se_output.out \
99240868Spjd		cat -e $(atf_get_srcdir)/d_se_output.in
100240868Spjd}
101240868Spjd
102240868Spjdatf_test_case vt_output
103240868Spjdvt_output_head() {
104240868Spjd	atf_set "descr" "Test that cat(1) displays non-printing characters, " \
105240868Spjd			"namely control characters, tab character and meta-characters " \
106240868Spjd			"using options '-vt'"
107240868Spjd}
108240868Spjd
109240868Spjdvt_output_body() {
110240868Spjd	atf_check -s ignore -o file:$(atf_get_srcdir)/d_vt_output.out \
111240868Spjd		cat -vt $(atf_get_srcdir)/d_vt_output.in
112240868Spjd}
113240868Spjd# End FreeBSD
114240868Spjd
115240868Spjdatf_init_test_cases()
116240868Spjd{
117240868Spjd	atf_add_test_case align
118240868Spjd	atf_add_test_case nonexistent
119240868Spjd# Begin FreeBSD
120240868Spjd	atf_add_test_case b_output
121240868Spjd# End FreeBSD
122240868Spjd	atf_add_test_case se_output
123240868Spjd# Begin FreeBSD
124240868Spjd	atf_add_test_case s_output
125240868Spjd	atf_add_test_case e_output
126240868Spjd	atf_add_test_case vt_output
127240868Spjd# End FreeBSD
128240868Spjd}
129240868Spjd