1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2010 Tim Kientzle 5 * All rights reserved. 6 */ 7 #include "test.h" 8 9 static const char *test4out[] = {"file1", "file2", NULL}; 10 static const char *test5err[] = {"file1", "file2", NULL}; 11 12 DEFINE_TEST(test_option_O_upper) 13 { 14 assertMakeFile("file1", 0644, "file1"); 15 assertMakeFile("file2", 0644, "file2"); 16 assertEqualInt(0, systemf("%s -cf archive.tar file1 file2", testprog)); 17 18 /* Test 1: -x without -O */ 19 assertMakeDir("test1", 0755); 20 assertChdir("test1"); 21 assertEqualInt(0, 22 systemf("%s -xf ../archive.tar >test.out 2>test.err", testprog)); 23 assertFileContents("file1", 5, "file1"); 24 assertFileContents("file2", 5, "file2"); 25 assertEmptyFile("test.out"); 26 assertEmptyFile("test.err"); 27 assertChdir(".."); 28 29 /* Test 2: -x with -O */ 30 assertMakeDir("test2", 0755); 31 assertChdir("test2"); 32 assertEqualInt(0, 33 systemf("%s -xOf ../archive.tar file1 >test.out 2>test.err", testprog)); 34 assertFileNotExists("file1"); 35 assertFileNotExists("file2"); 36 assertFileContents("file1", 5, "test.out"); 37 assertEmptyFile("test.err"); 38 assertChdir(".."); 39 40 /* Test 3: -x with -O and multiple files */ 41 assertMakeDir("test3", 0755); 42 assertChdir("test3"); 43 assertEqualInt(0, 44 systemf("%s -xOf ../archive.tar >test.out 2>test.err", testprog)); 45 assertFileNotExists("file1"); 46 assertFileNotExists("file2"); 47 assertFileContents("file1file2", 10, "test.out"); 48 assertEmptyFile("test.err"); 49 assertChdir(".."); 50 51 /* Test 4: -t without -O */ 52 assertMakeDir("test4", 0755); 53 assertChdir("test4"); 54 assertEqualInt(0, 55 systemf("%s -tf ../archive.tar >test.out 2>test.err", testprog)); 56 assertFileContainsLinesAnyOrder("test.out", test4out); 57 assertEmptyFile("test.err"); 58 assertChdir(".."); 59 60 /* Test 5: -t with -O */ 61 assertMakeDir("test5", 0755); 62 assertChdir("test5"); 63 assertEqualInt(0, 64 systemf("%s -tOf ../archive.tar >test.out 2>test.err", testprog)); 65 assertEmptyFile("test.out"); 66 assertFileContainsLinesAnyOrder("test.err", test5err); 67 assertChdir(".."); 68 } 69