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 static const char *test4out[] = {"file1", "file2", NULL};
29 static const char *test5err[] = {"file1", "file2", NULL};
31 DEFINE_TEST(test_option_O_upper)
33 assertMakeFile("file1", 0644, "file1");
34 assertMakeFile("file2", 0644, "file2");
35 assertEqualInt(0, systemf("%s -cf archive.tar file1 file2", testprog));
37 /* Test 1: -x without -O */
38 assertMakeDir("test1", 0755);
41 systemf("%s -xf ../archive.tar >test.out 2>test.err", testprog));
42 assertFileContents("file1", 5, "file1");
43 assertFileContents("file2", 5, "file2");
44 assertEmptyFile("test.out");
45 assertEmptyFile("test.err");
48 /* Test 2: -x with -O */
49 assertMakeDir("test2", 0755);
52 systemf("%s -xOf ../archive.tar file1 >test.out 2>test.err", testprog));
53 assertFileNotExists("file1");
54 assertFileNotExists("file2");
55 assertFileContents("file1", 5, "test.out");
56 assertEmptyFile("test.err");
59 /* Test 3: -x with -O and multiple files */
60 assertMakeDir("test3", 0755);
63 systemf("%s -xOf ../archive.tar >test.out 2>test.err", testprog));
64 assertFileNotExists("file1");
65 assertFileNotExists("file2");
66 assertFileContents("file1file2", 10, "test.out");
67 assertEmptyFile("test.err");
70 /* Test 4: -t without -O */
71 assertMakeDir("test4", 0755);
74 systemf("%s -tf ../archive.tar >test.out 2>test.err", testprog));
75 assertFileContainsLinesAnyOrder("test.out", test4out);
76 assertEmptyFile("test.err");
79 /* Test 5: -t with -O */
80 assertMakeDir("test5", 0755);
83 systemf("%s -tOf ../archive.tar >test.out 2>test.err", testprog));
84 assertEmptyFile("test.out");
85 assertFileContainsLinesAnyOrder("test.err", test5err);