xref: /freebsd/usr.bin/csplit/tests/csplit_test.sh (revision 48b644192d73be11d54b4b3dcfe255bd1b47884d)
1*48b64419SConrad Meyer# Copyright (c) 2017 Conrad Meyer <cem@FreeBSD.org>
2*48b64419SConrad Meyer# All rights reserved.
3*48b64419SConrad Meyer#
4*48b64419SConrad Meyer# Redistribution and use in source and binary forms, with or without
5*48b64419SConrad Meyer# modification, are permitted provided that the following conditions
6*48b64419SConrad Meyer# are met:
7*48b64419SConrad Meyer# 1. Redistributions of source code must retain the above copyright
8*48b64419SConrad Meyer#    notice, this list of conditions and the following disclaimer.
9*48b64419SConrad Meyer# 2. Redistributions in binary form must reproduce the above copyright
10*48b64419SConrad Meyer#    notice, this list of conditions and the following disclaimer in the
11*48b64419SConrad Meyer#    documentation and/or other materials provided with the distribution.
12*48b64419SConrad Meyer#
13*48b64419SConrad Meyer# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14*48b64419SConrad Meyer# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15*48b64419SConrad Meyer# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16*48b64419SConrad Meyer# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17*48b64419SConrad Meyer# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18*48b64419SConrad Meyer# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19*48b64419SConrad Meyer# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20*48b64419SConrad Meyer# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21*48b64419SConrad Meyer# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22*48b64419SConrad Meyer# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23*48b64419SConrad Meyer# SUCH DAMAGE.
24*48b64419SConrad Meyer#
25*48b64419SConrad Meyer# $FreeBSD$
26*48b64419SConrad Meyer
27*48b64419SConrad Meyeratf_test_case lines_lt_count
28*48b64419SConrad Meyerlines_lt_count_head()
29*48b64419SConrad Meyer{
30*48b64419SConrad Meyer	atf_set "descr" \
31*48b64419SConrad Meyer	    "Test an edge case where input has fewer lines than count"
32*48b64419SConrad Meyer}
33*48b64419SConrad Meyerlines_lt_count_body()
34*48b64419SConrad Meyer{
35*48b64419SConrad Meyer	cat > expectfile00 << HERE
36*48b64419SConrad Meyerone
37*48b64419SConrad Meyertwo
38*48b64419SConrad MeyerHERE
39*48b64419SConrad Meyer	cat > expectfile01 << HERE
40*48b64419SConrad Meyerxxx 1
41*48b64419SConrad Meyerthree
42*48b64419SConrad Meyerfour
43*48b64419SConrad MeyerHERE
44*48b64419SConrad Meyer	cat > expectfile02 << HERE
45*48b64419SConrad Meyerxxx 2
46*48b64419SConrad Meyerfive
47*48b64419SConrad Meyersix
48*48b64419SConrad MeyerHERE
49*48b64419SConrad Meyer	echo -e "one\ntwo\nxxx 1\nthree\nfour\nxxx 2\nfive\nsix" | \
50*48b64419SConrad Meyer	    csplit -k - '/xxx/' '{10}'
51*48b64419SConrad Meyer
52*48b64419SConrad Meyer	atf_check cmp expectfile00 xx00
53*48b64419SConrad Meyer	atf_check cmp expectfile01 xx01
54*48b64419SConrad Meyer	atf_check cmp expectfile02 xx02
55*48b64419SConrad Meyer}
56*48b64419SConrad Meyer
57*48b64419SConrad Meyeratf_init_test_cases()
58*48b64419SConrad Meyer{
59*48b64419SConrad Meyer	atf_add_test_case lines_lt_count
60*48b64419SConrad Meyer}
61