xref: /freebsd/contrib/libarchive/tar/test/test_option_exclude_vcs.c (revision e63d20b70ee1dbee9b075f29de6f30cdcfe1abe1)
1 /*-
2  * Copyright (c) 2019 Martin Matuska
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 #include "test.h"
26 
27 DEFINE_TEST(test_option_exclude_vcs)
28 {
29 	assertUmask(0);
30 	assertMakeDir("in", 0755);
31 	assertChdir("in");
32 	assertMakeFile("file", 0644, "");
33 	assertMakeDir("dir", 0755);
34 	assertMakeDir("CVS", 0755);
35 	assertMakeFile("CVS/fileattr", 0644, "");
36 	assertMakeFile(".cvsignore", 0644, "");
37 	assertMakeDir("RCS", 0755);
38 	assertMakeFile("RCS/somefile", 0655, "");
39 	assertMakeDir("SCCS", 0755);
40 	assertMakeFile("SCCS/somefile", 0655, "");
41 	assertMakeDir(".svn", 0755);
42 	assertMakeFile(".svn/format", 0655, "");
43 	assertMakeDir(".git", 0755);
44 	assertMakeFile(".git/config", 0655, "");
45 	assertMakeFile(".gitignore", 0644, "");
46 	assertMakeFile(".gitattributes", 0644, "");
47 	assertMakeFile(".gitmodules", 0644, "");
48 	assertMakeDir(".arch-ids", 0755);
49 	assertMakeFile(".arch-ids/somefile", 0644, "");
50 	assertMakeDir("{arch}", 0755);
51 	assertMakeFile("{arch}/somefile", 0644, "");
52 	assertMakeFile("=RELEASE-ID", 0644, "");
53 	assertMakeFile("=meta-update", 0644, "");
54 	assertMakeFile("=update", 0644, "");
55 	assertMakeDir(".bzr", 0755);
56 	assertMakeDir(".bzr/checkout", 0755);
57 	assertMakeFile(".bzrignore", 0644, "");
58 	assertMakeFile(".bzrtags", 0644, "");
59 	assertMakeDir(".hg", 0755);
60 	assertMakeFile(".hg/dirstate", 0644, "");
61 	assertMakeFile(".hgignore", 0644, "");
62 	assertMakeFile(".hgtags", 0644, "");
63 	assertMakeDir("_darcs", 0755);
64 	assertMakeFile("_darcs/format", 0644, "");
65 	assertChdir("..");
66 
67 	assertEqualInt(0, systemf("%s -c -C in -f included.tar .", testprog));
68 	assertEqualInt(0,
69 	    systemf("%s -c --exclude-vcs -C in -f excluded.tar .", testprog));
70 
71 	/* No flags, archive with vcs files */
72 	assertMakeDir("vcs-noexclude", 0755);
73 	assertEqualInt(0, systemf("%s -x -C vcs-noexclude -f included.tar",
74 	    testprog));
75 	assertChdir("vcs-noexclude");
76 	assertFileExists("file");
77 	assertIsDir("dir", 0755);
78 	assertIsDir("CVS", 0755);
79 	assertFileExists("CVS/fileattr");
80 	assertFileExists(".cvsignore");
81 	assertIsDir("RCS", 0755);
82 	assertFileExists("RCS/somefile");
83 	assertIsDir("SCCS", 0755);
84 	assertFileExists("SCCS/somefile");
85 	assertIsDir(".svn", 0755);
86 	assertFileExists(".svn/format");
87 	assertIsDir(".git", 0755);
88 	assertFileExists(".git/config");
89 	assertFileExists(".gitignore");
90 	assertFileExists(".gitattributes");
91 	assertFileExists(".gitmodules");
92 	assertIsDir(".arch-ids", 0755);
93 	assertFileExists(".arch-ids/somefile");
94 	assertIsDir("{arch}", 0755);
95 	assertFileExists("{arch}/somefile");
96 	assertFileExists("=RELEASE-ID");
97 	assertFileExists("=meta-update");
98 	assertFileExists("=update");
99 	assertIsDir(".bzr", 0755);
100 	assertIsDir(".bzr/checkout", 0755);
101 	assertFileExists(".bzrignore");
102 	assertFileExists(".bzrtags");
103 	assertIsDir(".hg", 0755);
104 	assertFileExists(".hg/dirstate");
105 	assertFileExists(".hgignore");
106 	assertFileExists(".hgtags");
107 	assertIsDir("_darcs", 0755);
108 	assertFileExists("_darcs/format");
109 	assertChdir("..");
110 
111 	/* --exclude-vcs, archive with vcs files */
112 	assertMakeDir("vcs-exclude", 0755);
113 	assertEqualInt(0,
114 	    systemf("%s -x --exclude-vcs -C vcs-exclude -f included.tar", testprog));
115 	assertChdir("vcs-exclude");
116 	assertFileExists("file");
117 	assertIsDir("dir", 0755);
118 	assertFileNotExists("CVS");
119 	assertFileNotExists("CVS/fileattr");
120 	assertFileNotExists(".cvsignore");
121 	assertFileNotExists("RCS");
122 	assertFileNotExists("RCS/somefile");
123 	assertFileNotExists("SCCS");
124 	assertFileNotExists("SCCS/somefile");
125 	assertFileNotExists(".svn");
126 	assertFileNotExists(".svn/format");
127 	assertFileNotExists(".git");
128 	assertFileNotExists(".git/config");
129 	assertFileNotExists(".gitignore");
130 	assertFileNotExists(".gitattributes");
131 	assertFileNotExists(".gitmodules");
132 	assertFileNotExists(".arch-ids");
133 	assertFileNotExists(".arch-ids/somefile");
134 	assertFileNotExists("{arch}");
135 	assertFileNotExists("{arch}/somefile");
136 	assertFileNotExists("=RELEASE-ID");
137 	assertFileNotExists("=meta-update");
138 	assertFileNotExists("=update");
139 	assertFileNotExists(".bzr");
140 	assertFileNotExists(".bzr/checkout");
141 	assertFileNotExists(".bzrignore");
142 	assertFileNotExists(".bzrtags");
143 	assertFileNotExists(".hg");
144 	assertFileNotExists(".hg/dirstate");
145 	assertFileNotExists(".hgignore");
146 	assertFileNotExists(".hgtags");
147 	assertFileNotExists("_darcs");
148 	assertFileNotExists("_darcs/format");
149 	assertChdir("..");
150 
151 	/* --exclude-vcs, archive without vcs files */
152 	assertMakeDir("novcs-exclude", 0755);
153 	assertEqualInt(0,
154 	    systemf("%s -x --exclude-vcs -C novcs-exclude -f excluded.tar",
155 	    testprog));
156 	assertChdir("novcs-exclude");
157 	assertFileExists("file");
158 	assertIsDir("dir", 0755);
159 	assertFileNotExists("CVS");
160 	assertFileNotExists("CVS/fileattr");
161 	assertFileNotExists(".cvsignore");
162 	assertFileNotExists("RCS");
163 	assertFileNotExists("RCS/somefile");
164 	assertFileNotExists("SCCS");
165 	assertFileNotExists("SCCS/somefile");
166 	assertFileNotExists(".svn");
167 	assertFileNotExists(".svn/format");
168 	assertFileNotExists(".git");
169 	assertFileNotExists(".git/config");
170 	assertFileNotExists(".gitignore");
171 	assertFileNotExists(".gitattributes");
172 	assertFileNotExists(".gitmodules");
173 	assertFileNotExists(".arch-ids");
174 	assertFileNotExists(".arch-ids/somefile");
175 	assertFileNotExists("{arch}");
176 	assertFileNotExists("{arch}/somefile");
177 	assertFileNotExists("=RELEASE-ID");
178 	assertFileNotExists("=meta-update");
179 	assertFileNotExists("=update");
180 	assertFileNotExists(".bzr");
181 	assertFileNotExists(".bzr/checkout");
182 	assertFileNotExists(".bzrignore");
183 	assertFileNotExists(".bzrtags");
184 	assertFileNotExists(".hg");
185 	assertFileNotExists(".hg/dirstate");
186 	assertFileNotExists(".hgignore");
187 	assertFileNotExists(".hgtags");
188 	assertFileNotExists("_darcs");
189 	assertFileNotExists("_darcs/format");
190 	assertChdir("..");
191 
192 	/* No flags, archive without vcs files */
193 	assertMakeDir("novcs-noexclude", 0755);
194 	assertEqualInt(0,
195 	    systemf("%s -x -C novcs-noexclude -f excluded.tar", testprog));
196 	assertChdir("novcs-noexclude");
197 	assertFileExists("file");
198 	assertIsDir("dir", 0755);
199 	assertFileNotExists("CVS");
200 	assertFileNotExists("CVS/fileattr");
201 	assertFileNotExists(".cvsignore");
202 	assertFileNotExists("RCS");
203 	assertFileNotExists("RCS/somefile");
204 	assertFileNotExists("SCCS");
205 	assertFileNotExists("SCCS/somefile");
206 	assertFileNotExists(".svn");
207 	assertFileNotExists(".svn/format");
208 	assertFileNotExists(".git");
209 	assertFileNotExists(".git/config");
210 	assertFileNotExists(".gitignore");
211 	assertFileNotExists(".gitattributes");
212 	assertFileNotExists(".gitmodules");
213 	assertFileNotExists(".arch-ids");
214 	assertFileNotExists(".arch-ids/somefile");
215 	assertFileNotExists("{arch}");
216 	assertFileNotExists("{arch}/somefile");
217 	assertFileNotExists("=RELEASE-ID");
218 	assertFileNotExists("=meta-update");
219 	assertFileNotExists("=update");
220 	assertFileNotExists(".bzr");
221 	assertFileNotExists(".bzr/checkout");
222 	assertFileNotExists(".bzrignore");
223 	assertFileNotExists(".bzrtags");
224 	assertFileNotExists(".hg");
225 	assertFileNotExists(".hg/dirstate");
226 	assertFileNotExists(".hgignore");
227 	assertFileNotExists(".hgtags");
228 	assertFileNotExists("_darcs");
229 	assertFileNotExists("_darcs/format");
230 }
231