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 #ifdef HAVE_SYS_WAIT_H
32 DEFINE_TEST(test_option_n)
36 assertMakeDir("d1", 0755);
37 assertMakeFile("d1/file1", 0644, "d1/file1");
39 /* Test 1: -c without -n */
40 assertMakeDir("test1", 0755);
43 systemf("%s -cf archive.tar -C .. d1 >c.out 2>c.err", testprog));
44 assertEmptyFile("c.out");
45 assertEmptyFile("c.err");
47 systemf("%s -xf archive.tar >x.out 2>x.err", testprog));
48 assertEmptyFile("x.out");
49 assertEmptyFile("x.err");
50 assertFileContents("d1/file1", 8, "d1/file1");
53 /* Test 2: -c with -n */
54 assertMakeDir("test2", 0755);
57 systemf("%s -cnf archive.tar -C .. d1 >c.out 2>c.err", testprog));
58 assertEmptyFile("c.out");
59 assertEmptyFile("c.err");
61 systemf("%s -xf archive.tar >x.out 2>x.err", testprog));
62 assertEmptyFile("x.out");
63 assertEmptyFile("x.err");
64 assertIsDir("d1", umasked(0755));
65 assertFileNotExists("d1/file1");
69 * Create a test archive with the following content:
76 * Extracting uses the same code as listing and thus does not
77 * get tested separately. This also covers the
78 * archive_match_set_inclusion_recursion()
81 assertMakeFile("d1/file2", 0644, "d1/file2");
82 assertMakeFile("file3", 0644, "file3");
83 assertMakeDir("d2", 0755);
84 assertMakeFile("d2/file4", 0644, "d2/file4");
86 systemf("%s -cnf partial-archive.tar d1 d1/file1 d1/file2 file3 "
87 "d2/file4 >c.out 2>c.err", testprog));
89 /* Test 3: -t without other options */
91 systemf("%s -tf partial-archive.tar >test3.out 2>test3.err",
93 assertEmptyFile("test3.err");
94 assertTextFileContents("d1/\n"
101 /* Test 4: -t without -n and some entries selected */
103 systemf("%s -tf partial-archive.tar d1 file3 d2/file4 "
104 ">test4.out 2>test4.err", testprog));
105 assertEmptyFile("test4.err");
106 assertTextFileContents("d1/\n"
113 /* Test 5: -t with -n and some entries selected */
115 systemf("%s -tnf partial-archive.tar d1 file3 d2/file4 "
116 ">test5.out 2>test5.err", testprog));
117 assertEmptyFile("test5.err");
118 assertTextFileContents("d1/\n"
123 /* Test 6: -t without -n and non-existent directory selected */
125 systemf("%s -tf partial-archive.tar d2 >test6.out 2>test6.err",
127 assertEmptyFile("test6.err");
128 assertTextFileContents("d2/file4\n",
131 /* Test 7: -t with -n and non-existent directory selected */
132 status = systemf("%s -tnf partial-archive.tar d2 "
133 ">test7.out 2>test7.err", testprog);
135 assert(status != -1);
136 #if !defined(_WIN32) || defined(__CYGWIN__)
137 assert(WIFEXITED(status));
138 assertEqualInt(1, WEXITSTATUS(status));
140 assertNonEmptyFile("test7.err");
141 assertEmptyFile("test7.out");