Sync usage with man page.
[netbsd-mini2440.git] / tests / util / mtree / t_mtree.sh
blob6615a9faf8ddc1f37e37a9e69c4e520c8dc8e1ae
1 # $NetBSD: t_mtree.sh,v 1.3 2009/04/08 19:06:30 apb Exp $
3 # Copyright (c) 2009 The NetBSD Foundation, Inc.
4 # All rights reserved.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 # POSSIBILITY OF SUCH DAMAGE.
28 # Postprocess mtreee output, canonicalising portions that
29 # are expected to differ from one run to another.
30 h_postprocess()
32 sed -e '
33 /^# user: /s/:.*/: x/
34 /^# machine: /s/:.*/: x/
35 /^# tree: /s/:.*/: x/
36 /^# date: /s/:.*/: x/
40 h_check()
42 diff -Nru "$1" "$2" || atf_fail "files $1 and $2 differ"
45 atf_test_case create
46 create_head()
48 atf_set "descr" "Create a specfile describing a directory tree"
50 create_setup()
52 # create some directories
53 mkdir -p create/a/1 create/a/2 create/b
54 # create some files
55 for file in create/top.file.1 \
56 create/a/a.file.1 \
57 create/a/a.file.2 \
58 create/a/1/a1.file.1 \
59 create/b/b.file.1 \
60 create/b/b.file.2
62 echo "$file" >$file
63 done
64 # hard link to file in same dir
65 ln create/b/b.file.1 create/b/b.hardlink.1
66 # hard link to file in another dir
67 ln create/b/b.file.2 create/a/a.hardlink.b2
68 # symlink to file
69 ln -s a.file.1 create/a.symlink.1
70 # symlink to dir
71 ln -s b create/top.symlink.b
72 # dangling symlink
73 ln -s nonexistent create/top.dangling
75 create_body()
77 create_setup
79 # run mtree and check output
80 ( cd create && mtree -c -k type,nlink,link,size,sha256 ) >output.raw \
81 || atf_fail "mtree exit status $?"
82 h_postprocess <output.raw >output
83 h_check "$(atf_get_srcdir)/d_create.out" output
86 atf_test_case check
87 check_head()
89 atf_set "descr" "Check a directory tree against a specfile"
91 check_body()
93 # we use the same directory tree and specfile as in the "create" test
94 create_setup
96 # run mtree and check output
97 ( cd create && mtree ) <"$(atf_get_srcdir)/d_create.out" >output \
98 || atf_fail "mtree exit status $?"
99 h_check /dev/null output
102 atf_test_case convert_C
103 convert_C_head()
105 atf_set "descr" "Convert a specfile to mtree -C format, unsorted"
107 convert_C_body()
109 mtree -C -K all <"$(atf_get_srcdir)/d_convert.in" >output
110 h_check "$(atf_get_srcdir)/d_convert_C.out" output
113 atf_test_case convert_C_S
114 convert_C_S_head()
116 atf_set "descr" "Convert a specfile to mtree -C format, sorted"
118 convert_C_S_body()
120 mtree -C -S -K all <"$(atf_get_srcdir)/d_convert.in" >output
121 h_check "$(atf_get_srcdir)/d_convert_C_S.out" output
124 atf_test_case convert_D
125 convert_D_head()
127 atf_set "descr" "Convert a specfile to mtree -D format, unsorted"
129 convert_D_body()
131 mtree -D -K all <"$(atf_get_srcdir)/d_convert.in" >output
132 h_check "$(atf_get_srcdir)/d_convert_D.out" output
135 atf_test_case convert_D_S
136 convert_D_S_head()
138 atf_set "descr" "Convert a specfile to mtree -D format, sorted"
140 convert_D_S_body()
142 mtree -D -S -K all <"$(atf_get_srcdir)/d_convert.in" >output
143 h_check "$(atf_get_srcdir)/d_convert_D_S.out" output
146 atf_test_case merge
147 merge_head()
149 atf_set "descr" "Merge records of different type"
151 merge_body()
153 mtree -C -M -K all <"$(atf_get_srcdir)/d_merge.in" >output
154 h_check "$(atf_get_srcdir)/d_merge_C_M.out" output
155 # same again, with sorting
156 mtree -C -M -S -K all <"$(atf_get_srcdir)/d_merge.in" >output
157 h_check "$(atf_get_srcdir)/d_merge_C_M_S.out" output
160 atf_init_test_cases()
162 atf_add_test_case create
163 atf_add_test_case check
164 atf_add_test_case convert_C
165 atf_add_test_case convert_C_S
166 atf_add_test_case convert_D
167 atf_add_test_case convert_D_S
168 atf_add_test_case merge