[BACK]Return to t_sdiff.sh CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / tests / usr.bin / sdiff

File: [cvs.NetBSD.org] / src / tests / usr.bin / sdiff / t_sdiff.sh (download)

Revision 1.1, Sat Mar 17 16:33:15 2012 UTC (9 years, 1 month ago) by jruoho
Branch: MAIN
CVS Tags: yamt-pagecache-base9, yamt-pagecache-base8, yamt-pagecache-base7, yamt-pagecache-base6, yamt-pagecache-base5, yamt-pagecache-base4, tls-maxphys-base, tls-maxphys, tls-earlyentropy-base, tls-earlyentropy, riastradh-xf86-video-intel-2-7-1-pre-2-21-15, riastradh-drm2-base3, riastradh-drm2-base2, riastradh-drm2-base1, riastradh-drm2-base, riastradh-drm2, prg-localcount2-base3, prg-localcount2-base2, prg-localcount2-base1, prg-localcount2-base, prg-localcount2, phil-wifi-base, phil-wifi-20200421, phil-wifi-20200411, phil-wifi-20200406, phil-wifi-20191119, phil-wifi-20190609, phil-wifi, pgoyette-localcount-base, pgoyette-localcount-20170426, pgoyette-localcount-20170320, pgoyette-localcount-20170107, pgoyette-localcount-20161104, pgoyette-localcount-20160806, pgoyette-localcount-20160726, pgoyette-localcount, pgoyette-compat-merge-20190127, pgoyette-compat-base, pgoyette-compat-20190127, pgoyette-compat-20190118, pgoyette-compat-1226, pgoyette-compat-1126, pgoyette-compat-1020, pgoyette-compat-0930, pgoyette-compat-0906, pgoyette-compat-0728, pgoyette-compat-0625, pgoyette-compat-0521, pgoyette-compat-0502, pgoyette-compat-0422, pgoyette-compat-0415, pgoyette-compat-0407, pgoyette-compat-0330, pgoyette-compat-0322, pgoyette-compat-0315, pgoyette-compat, perseant-stdc-iso10646-base, perseant-stdc-iso10646, netbsd-9-base, netbsd-9-1-RELEASE, netbsd-9-0-RELEASE, netbsd-9-0-RC2, netbsd-9-0-RC1, netbsd-9, netbsd-8-base, netbsd-8-2-RELEASE, netbsd-8-1-RELEASE, netbsd-8-1-RC1, netbsd-8-0-RELEASE, netbsd-8-0-RC2, netbsd-8-0-RC1, netbsd-8, netbsd-7-nhusb-base-20170116, netbsd-7-nhusb-base, netbsd-7-nhusb, netbsd-7-base, netbsd-7-2-RELEASE, netbsd-7-1-RELEASE, netbsd-7-1-RC2, netbsd-7-1-RC1, netbsd-7-1-2-RELEASE, netbsd-7-1-1-RELEASE, netbsd-7-1, netbsd-7-0-RELEASE, netbsd-7-0-RC3, netbsd-7-0-RC2, netbsd-7-0-RC1, netbsd-7-0-2-RELEASE, netbsd-7-0-1-RELEASE, netbsd-7-0, netbsd-7, matt-nb8-mediatek-base, matt-nb8-mediatek, localcount-20160914, is-mlppp-base, is-mlppp, bouyer-socketcan-base1, bouyer-socketcan-base, bouyer-socketcan, agc-symver-base, agc-symver, HEAD
Branch point for: yamt-pagecache

Deprecate tests/util.

# $NetBSD: t_sdiff.sh,v 1.1 2012/03/17 16:33:15 jruoho Exp $
#
# Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

atf_test_case flags
flags_head()
{
	atf_set "descr" "Checks -l, -s and -w flags"
}
flags_body()
{
	atf_check -o file:$(atf_get_srcdir)/d_flags_l.out -s eq:1 \
	    sdiff -l "$(atf_get_srcdir)/d_input1" "$(atf_get_srcdir)/d_input2"

	atf_check -o file:$(atf_get_srcdir)/d_flags_s.out -s eq:1 \
	    sdiff -s "$(atf_get_srcdir)/d_input1" "$(atf_get_srcdir)/d_input2"

	atf_check -o file:$(atf_get_srcdir)/d_flags_w.out -s eq:1 \
	    sdiff -w 125 "$(atf_get_srcdir)/d_input1" "$(atf_get_srcdir)/d_input2"
}

atf_test_case iflags
iflags_head()
{
	atf_set "descr" "Checks flags -l, -s and -w combined with -I"
}
iflags_body()
{
	tail1="-w 125 -I .*filename.* $(atf_get_srcdir)/d_input1 $(atf_get_srcdir)/d_input2"
	tail2="-w 125 -I .*filename.* $(atf_get_srcdir)/d_input2 $(atf_get_srcdir)/d_input1"

	atf_check -o file:$(atf_get_srcdir)/d_iflags_a1.out -s eq:1 sdiff ${tail1}
	atf_check -o file:$(atf_get_srcdir)/d_iflags_a2.out -s eq:1 sdiff ${tail2}
	atf_check -o file:$(atf_get_srcdir)/d_iflags_b1.out -s eq:1 sdiff -s ${tail1}
	atf_check -o file:$(atf_get_srcdir)/d_iflags_b2.out -s eq:1 sdiff -s ${tail2}
	atf_check -o file:$(atf_get_srcdir)/d_iflags_c1.out -s eq:1 sdiff -l ${tail1}
	atf_check -o file:$(atf_get_srcdir)/d_iflags_c2.out -s eq:1 sdiff -l ${tail2}
	atf_check -o file:$(atf_get_srcdir)/d_iflags_d1.out -s eq:1 sdiff -s ${tail1}
	atf_check -o file:$(atf_get_srcdir)/d_iflags_d2.out -s eq:1 sdiff -s ${tail2}
}

atf_test_case tabs
tabs_head()
{
	atf_set "descr" "Checks comparing files containing tabs"
}
tabs_body()
{
	atf_check -o file:$(atf_get_srcdir)/d_tabs.out -s eq:1 \
	    sdiff "$(atf_get_srcdir)/d_tabs1.in" "$(atf_get_srcdir)/d_tabs2.in"
}

atf_test_case tabends
tabends_head()
{
	atf_set "descr" "Checks correct handling of lines ended with tabs"
}
tabends_body()
{
	atf_check -o file:$(atf_get_srcdir)/d_tabends_a.out -s eq:1 \
	    sdiff -w30 "$(atf_get_srcdir)/d_tabends.in" /dev/null

	atf_check -o file:$(atf_get_srcdir)/d_tabends_b.out -s eq:1 \
	    sdiff -w30 /dev/null "$(atf_get_srcdir)/d_tabends.in"

	atf_check -o file:$(atf_get_srcdir)/d_tabends_c.out -s eq:1 \
	    sdiff -w19 "$(atf_get_srcdir)/d_tabends.in" /dev/null
}

atf_test_case merge
merge_head()
{
	atf_set "descr" "Checks interactive merging"
}
merge_body()
{
	merge_tail="-o merge.out $(atf_get_srcdir)/d_input1 \
$(atf_get_srcdir)/d_input2 >/dev/null ; cat merge.out"

	cp $(atf_get_srcdir)/d_input* .

	atf_check -o file:d_input1 -x "yes l | sdiff ${merge_tail}"
	atf_check -o file:d_input2 -x "yes r | sdiff ${merge_tail}"

	atf_check -o file:d_input1 -x \
		"yes el | EDITOR=cat VISUAL=cat sdiff ${merge_tail}"
	atf_check -o file:d_input2 -x \
		"yes er | EDITOR=cat VISUAL=cat sdiff ${merge_tail}"

	atf_check -o file:d_input1 -x "yes l | sdiff -s ${merge_tail}"
	atf_check -o file:d_input2 -x "yes r | sdiff -s ${merge_tail}"
	atf_check -o file:d_input1 -x "yes l | sdiff -l ${merge_tail}"
	atf_check -o file:d_input2 -x "yes r | sdiff -l ${merge_tail}"
	atf_check -o file:d_input1 -x "yes l | sdiff -ls ${merge_tail}"
	atf_check -o file:d_input2 -x "yes r | sdiff -ls ${merge_tail}"

	atf_check -o file:d_input1 -x "{ while :; do echo s; echo l; \
echo v; echo l; done; } | sdiff ${merge_tail}"

	atf_check -o file:d_input2 -x "{ while :; do echo s; echo r; \
echo v; echo r; done; } | sdiff ${merge_tail}"
}

atf_test_case same
same_head()
{
	atf_set "descr" "Checks comparing file with itself"
}
same_body()
{
	atf_check -o file:$(atf_get_srcdir)/d_same.out \
	    sdiff "$(atf_get_srcdir)/d_input1" "$(atf_get_srcdir)/d_input1"
}

atf_test_case oneline
oneline_head()
{
	atf_set "descr" "Checks comparing one-line files"
}
oneline_body()
{
	atf_check -o file:$(atf_get_srcdir)/d_oneline_a.out -s eq:1 \
	    sdiff /dev/null "$(atf_get_srcdir)/d_oneline.in"

	atf_check -o file:$(atf_get_srcdir)/d_oneline_b.out -s eq:1 \
	    sdiff "$(atf_get_srcdir)/d_oneline.in" /dev/null
}

atf_test_case dot
dot_head()
{
	atf_set "descr" "Checks comparing with file containing only one character"
}
dot_body()
{
	echo ".                                                               <" > expout
	atf_check -o file:expout -s eq:1 sdiff "$(atf_get_srcdir)/d_dot.in" /dev/null

	echo "                                                                > ." > expout
	atf_check -o file:expout -s eq:1 sdiff /dev/null "$(atf_get_srcdir)/d_dot.in"
}

atf_test_case stdin
stdin_head()
{
	atf_set "descr" "Checks reading data from stdin"
}
stdin_body()
{
	echo "                                                                > stdin" > expout
	atf_check -o file:expout -s eq:1 -x \
	    "echo stdin | sdiff /dev/null /dev/stdin"

	echo "stdin                                                           <" > expout
	atf_check -o file:expout -s eq:1 -x \
	    "echo stdin | sdiff /dev/stdin /dev/null"
}

atf_test_case short
short_head()
{
	atf_set "descr" "Checks premature stop of merging"
}
short_body()
{
	atf_check -o file:$(atf_get_srcdir)/d_short.out -x \
	    "printf \"r\\nl\\nr\\nl\" | sdiff -o merge.out $(atf_get_srcdir)/d_input1 \
$(atf_get_srcdir)/d_input2 >/dev/null ; cat merge.out"
}

atf_init_test_cases()
{
	atf_add_test_case flags
	atf_add_test_case iflags
	atf_add_test_case tabs
	atf_add_test_case tabends
	atf_add_test_case merge
	atf_add_test_case same
	atf_add_test_case oneline
	atf_add_test_case dot
	atf_add_test_case stdin
	atf_add_test_case short
}