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_C_upper)
32 assertMakeDir("d1", 0755);
33 assertMakeDir("d2", 0755);
34 assertMakeFile("d1/file1", 0644, "d1/file1");
35 assertMakeFile("d1/file2", 0644, "d1/file2");
36 assertMakeFile("d2/file1", 0644, "d2/file1");
37 assertMakeFile("d2/file2", 0644, "d2/file2");
40 * Test 1: Basic use of -C
42 assertMakeDir("test1", 0755);
44 assertEqualInt(0, systemf("%s -cf archive.tar -C ../d1 file1 -C ../d2 file2", testprog));
46 systemf("%s -xf archive.tar >test.out 2>test.err", testprog));
47 assertFileContents("d1/file1", 8, "file1");
48 assertFileContents("d2/file2", 8, "file2");
49 assertEmptyFile("test.out");
50 assertEmptyFile("test.err");
57 assertMakeDir("test2", 0755);
59 assertEqualInt(0, systemf("%s -cf archive.tar -C .. -C d1 file1 -C .. -C d2 file2", testprog));
61 systemf("%s -xf archive.tar >test.out 2>test.err", testprog));
62 assertFileContents("d1/file1", 8, "file1");
63 assertFileContents("d2/file2", 8, "file2");
64 assertEmptyFile("test.out");
65 assertEmptyFile("test.err");
71 assertMakeDir("test3", 0755);
73 r = systemf("%s -cf archive.tar -C ../XXX file1 -C ../d2 file2 2>write.err", testprog);
75 assertNonEmptyFile("write.err");
77 systemf("%s -xf archive.tar >test.out 2>test.err", testprog));
78 assertFileNotExists("file1");
79 assertFileNotExists("file2");
80 assertEmptyFile("test.out");
81 assertEmptyFile("test.err");
87 assertMakeDir("test4", 0755);
90 systemf("%s -cf archive.tar -C %s/d1 file1",
91 testprog, testworkdir));
93 systemf("%s -xf archive.tar >test.out 2>test.err", testprog));
94 assertFileContents("d1/file1", 8, "file1");
95 assertEmptyFile("test.out");
96 assertEmptyFile("test.err");
100 * Test 5: Unnecessary -C ignored even if directory named doesn't exist
102 assertMakeDir("test5", 0755);
103 assertChdir("test5");
105 systemf("%s -cf archive.tar -C XXX -C %s/d1 file1",
106 testprog, testworkdir));
108 systemf("%s -xf archive.tar >test.out 2>test.err", testprog));
109 assertFileContents("d1/file1", 8, "file1");
110 assertEmptyFile("test.out");
111 assertEmptyFile("test.err");
115 * Test 6: Necessary -C not ignored if directory doesn't exist
117 assertMakeDir("test6", 0755);
118 assertChdir("test6");
119 r = systemf("%s -cf archive.tar -C XXX -C ../d1 file1 2>write.err",
120 testprog, testworkdir);
122 assertNonEmptyFile("write.err");
124 systemf("%s -xf archive.tar >test.out 2>test.err", testprog));
125 assertEmptyFile("test.out");
126 assertEmptyFile("test.err");
130 * Test 7: -C used without specifying directory
132 assertMakeDir("test7", 0755);
133 assertChdir("test7");
134 r = systemf("%s -cf archive.tar ../d1/file1 -C 2>write.err", testprog);
136 assertNonEmptyFile("write.err");
140 * Test 8: -C used with meaningless option ''
142 assertMakeDir("test8", 0755);
143 assertChdir("test8");
144 r = systemf("%s -cf archive.tar ../d1/file1 -C \"\" 2>write.err",
147 assertNonEmptyFile("write.err");