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_k)
31 * Create an archive with a couple of different versions of the
35 assertMakeFile("foo", 0644, "foo1");
37 assertEqualInt(0, systemf("%s -cf archive.tar foo", testprog));
39 assertMakeFile("foo", 0644, "foo2");
41 assertEqualInt(0, systemf("%s -rf archive.tar foo", testprog));
43 assertMakeFile("bar", 0644, "bar1");
45 assertEqualInt(0, systemf("%s -rf archive.tar bar", testprog));
47 assertMakeFile("foo", 0644, "foo3");
49 assertEqualInt(0, systemf("%s -rf archive.tar foo", testprog));
51 assertMakeFile("bar", 0644, "bar2");
53 assertEqualInt(0, systemf("%s -rf archive.tar bar", testprog));
56 * Now, try extracting from the test archive with various
60 /* Test 1: No option */
61 assertMakeDir("test1", 0755);
64 systemf("%s -xf ../archive.tar >test.out 2>test.err", testprog));
65 assertFileContents("foo3", 4, "foo");
66 assertFileContents("bar2", 4, "bar");
67 assertEmptyFile("test.out");
68 assertEmptyFile("test.err");
71 /* Test 2: With -k, we should just get the first versions. */
72 assertMakeDir("test2", 0755);
75 systemf("%s -xf ../archive.tar -k >test.out 2>test.err", testprog));
76 assertFileContents("foo1", 4, "foo");
77 assertFileContents("bar1", 4, "bar");
78 assertEmptyFile("test.out");
79 assertEmptyFile("test.err");
82 /* Test 3: Without -k, existing files should get overwritten */
83 assertMakeDir("test3", 0755);
85 assertMakeFile("bar", 0644, "bar0");
86 assertMakeFile("foo", 0644, "foo0");
88 systemf("%s -xf ../archive.tar >test.out 2>test.err", testprog));
89 assertFileContents("foo3", 4, "foo");
90 assertFileContents("bar2", 4, "bar");
91 assertEmptyFile("test.out");
92 assertEmptyFile("test.err");
95 /* Test 4: With -k, existing files should not get overwritten */
96 assertMakeDir("test4", 0755);
98 assertMakeFile("bar", 0644, "bar0");
99 assertMakeFile("foo", 0644, "foo0");
101 systemf("%s -xf ../archive.tar -k >test.out 2>test.err", testprog));
102 assertFileContents("foo0", 4, "foo");
103 assertFileContents("bar0", 4, "bar");
104 assertEmptyFile("test.out");
105 assertEmptyFile("test.err");