cmp_test2.sh revision 314425
1# Copyright (c) 2017 Alan Somers
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions
6# are met:
7# 1. Redistributions of source code must retain the above copyright
8#    notice, this list of conditions and the following disclaimer.
9# 2. Redistributions in binary form must reproduce the above copyright
10#    notice, this list of conditions and the following disclaimer in the
11#    documentation and/or other materials provided with the distribution.
12#
13# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
14# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
15# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
17# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23# POSSIBILITY OF SUCH DAMAGE.
24#
25# $FreeBSD: stable/10/usr.bin/cmp/tests/cmp_test2.sh 314425 2017-02-28 22:18:05Z asomers $
26
27atf_test_case special
28special_head() {
29	atf_set "descr" "Test cmp(1)'s handling of non-regular files"
30}
31special_body() {
32	echo 0123456789abcdef > a
33	echo 0123456789abcdeg > b
34	cat a | atf_check -s exit:0 cmp a -
35	cat a | atf_check -s exit:0 cmp - a
36	cat b | atf_check -s not-exit:0 cmp a -
37	cat b | atf_check -s not-exit:0 cmp - a
38	true
39}
40
41atf_test_case symlink
42symlink_head() {
43	atf_set "descr" "Test cmp(1)'s handling of symlinks"
44}
45symlink_body() {
46	echo 0123456789abcdef > a
47	echo 0123456789abcdeg > b
48	ln -s a a.lnk
49	ln -s b b.lnk
50	ln -s a a2.lnk
51	cp a adup
52	ln -s adup adup.lnk
53	atf_check -s exit:0 cmp a a.lnk
54	atf_check -s exit:0 cmp a.lnk a
55	atf_check -s not-exit:0 -o ignore cmp a b.lnk
56	atf_check -s not-exit:0 -o ignore cmp b.lnk a
57	atf_check -s not-exit:0 -o ignore -e ignore cmp -h a a.lnk
58	atf_check -s not-exit:0 -o ignore -e ignore cmp -h a.lnk a
59	atf_check -s exit:0 cmp -h a.lnk a2.lnk
60	atf_check -s not-exit:0 -o ignore -e ignore cmp -h a.lnk adup.lnk
61}
62
63atf_init_test_cases()
64{
65	atf_add_test_case special
66	atf_add_test_case symlink
67}
68