2
* Copyright (c) 2010 Tim Kientzle
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
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.
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.
26
__FBSDID("$FreeBSD$");
28
DEFINE_TEST(test_option_exclude)
32
assertMakeFile("file1", 0644, "file1");
33
assertMakeFile("file2", 0644, "file2");
34
assertEqualInt(0, systemf("%s -cf archive.tar file1 file2", testprog));
37
* Now, try extracting from the test archive with various --exclude options.
40
/* Test 1: Without --exclude */
41
assertMakeDir("test1", 0755);
44
systemf("%s -xf ../archive.tar >test.out 2>test.err", testprog));
45
assertFileContents("file1", 5, "file1");
46
assertFileContents("file2", 5, "file2");
47
assertEmptyFile("test.out");
48
assertEmptyFile("test.err");
51
/* Test 2: Selecting just one file */
52
assertMakeDir("test2", 0755);
55
systemf("%s -xf ../archive.tar file1 >test.out 2>test.err", testprog));
56
assertFileContents("file1", 5, "file1");
57
assertFileNotExists("file2");
58
assertEmptyFile("test.out");
59
assertEmptyFile("test.err");
62
/* Test 3: Use --exclude to skip one file */
63
assertMakeDir("test3", 0755);
66
systemf("%s -xf ../archive.tar --exclude file1 >test.out 2>test.err", testprog));
67
assertFileNotExists("file1");
68
assertFileContents("file2", 5, "file2");
69
assertEmptyFile("test.out");
70
assertEmptyFile("test.err");
73
/* Test 4: Selecting one valid and one invalid file */
74
assertMakeDir("test4", 0755);
76
r = systemf("%s -xf ../archive.tar file1 file3 >test.out 2>test.err", testprog);
78
assertFileContents("file1", 5, "file1");
79
assertFileNotExists("file2");
80
assertFileNotExists("file3");
81
assertEmptyFile("test.out");
82
assertNonEmptyFile("test.err");
85
/* Test 5: Selecting one valid file twice */
86
assertMakeDir("test5", 0755);
89
systemf("%s -xf ../archive.tar file1 file1 >test.out 2>test.err", testprog));
90
assertFileContents("file1", 5, "file1");
91
assertFileNotExists("file2");
92
assertEmptyFile("test.out");
93
assertEmptyFile("test.err");
96
/* Test 6: Include and exclude the same file */
97
assertMakeDir("test6", 0755);
100
systemf("%s -xf ../archive.tar --exclude file1 file1 >test.out 2>test.err", testprog));
101
assertFileNotExists("file1");
102
assertFileNotExists("file2");
103
assertEmptyFile("test.out");
104
assertEmptyFile("test.err");
107
/* Test 7: Exclude a non-existent file */
108
assertMakeDir("test7", 0755);
109
assertChdir("test7");
111
systemf("%s -xf ../archive.tar --exclude file3 file1 >test.out 2>test.err", testprog));
112
assertFileContents("file1", 5, "file1");
113
assertFileNotExists("file2");
114
assertFileNotExists("file3");
115
assertEmptyFile("test.out");
116
assertEmptyFile("test.err");
119
/* Test 8: Include a non-existent file */
120
assertMakeDir("test8", 0755);
121
assertChdir("test8");
122
r = systemf("%s -xf ../archive.tar file3 >test.out 2>test.err", testprog);
124
assertFileNotExists("file1");
125
assertFileNotExists("file2");
126
assertFileNotExists("file3");
127
assertEmptyFile("test.out");
128
assertNonEmptyFile("test.err");
131
/* Test 9: Include a non-existent file plus an exclusion */
132
assertMakeDir("test9", 0755);
133
assertChdir("test9");
134
r = systemf("%s -xf ../archive.tar --exclude file1 file3 >test.out 2>test.err", testprog);
136
assertFileNotExists("file1");
137
assertFileNotExists("file2");
138
assertFileNotExists("file3");
139
assertEmptyFile("test.out");
140
assertNonEmptyFile("test.err");