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 DEFINE_TEST(test_option_exclude) 10 { 11 int r; 12 13 assertMakeFile("file1", 0644, "file1"); 14 assertMakeFile("file2", 0644, "file2"); 15 assertEqualInt(0, systemf("%s -cf archive.tar file1 file2", testprog)); 16 17 /* 18 * Now, try extracting from the test archive with various --exclude options. 19 */ 20 21 /* Test 1: Without --exclude */ 22 assertMakeDir("test1", 0755); 23 assertChdir("test1"); 24 assertEqualInt(0, 25 systemf("%s -xf ../archive.tar >test.out 2>test.err", testprog)); 26 assertFileContents("file1", 5, "file1"); 27 assertFileContents("file2", 5, "file2"); 28 assertEmptyFile("test.out"); 29 assertEmptyFile("test.err"); 30 assertChdir(".."); 31 32 /* Test 2: Selecting just one file */ 33 assertMakeDir("test2", 0755); 34 assertChdir("test2"); 35 assertEqualInt(0, 36 systemf("%s -xf ../archive.tar file1 >test.out 2>test.err", testprog)); 37 assertFileContents("file1", 5, "file1"); 38 assertFileNotExists("file2"); 39 assertEmptyFile("test.out"); 40 assertEmptyFile("test.err"); 41 assertChdir(".."); 42 43 /* Test 3: Use --exclude to skip one file */ 44 assertMakeDir("test3", 0755); 45 assertChdir("test3"); 46 assertEqualInt(0, 47 systemf("%s -xf ../archive.tar --exclude file1 >test.out 2>test.err", testprog)); 48 assertFileNotExists("file1"); 49 assertFileContents("file2", 5, "file2"); 50 assertEmptyFile("test.out"); 51 assertEmptyFile("test.err"); 52 assertChdir(".."); 53 54 /* Test 4: Selecting one valid and one invalid file */ 55 assertMakeDir("test4", 0755); 56 assertChdir("test4"); 57 r = systemf("%s -xf ../archive.tar file1 file3 >test.out 2>test.err", testprog); 58 assert(r != 0); 59 assertFileContents("file1", 5, "file1"); 60 assertFileNotExists("file2"); 61 assertFileNotExists("file3"); 62 assertEmptyFile("test.out"); 63 assertNonEmptyFile("test.err"); 64 assertChdir(".."); 65 66 /* Test 5: Selecting one valid file twice */ 67 assertMakeDir("test5", 0755); 68 assertChdir("test5"); 69 assertEqualInt(0, 70 systemf("%s -xf ../archive.tar file1 file1 >test.out 2>test.err", testprog)); 71 assertFileContents("file1", 5, "file1"); 72 assertFileNotExists("file2"); 73 assertEmptyFile("test.out"); 74 assertEmptyFile("test.err"); 75 assertChdir(".."); 76 77 /* Test 6: Include and exclude the same file */ 78 assertMakeDir("test6", 0755); 79 assertChdir("test6"); 80 assertEqualInt(0, 81 systemf("%s -xf ../archive.tar --exclude file1 file1 >test.out 2>test.err", testprog)); 82 assertFileNotExists("file1"); 83 assertFileNotExists("file2"); 84 assertEmptyFile("test.out"); 85 assertEmptyFile("test.err"); 86 assertChdir(".."); 87 88 /* Test 7: Exclude a non-existent file */ 89 assertMakeDir("test7", 0755); 90 assertChdir("test7"); 91 assertEqualInt(0, 92 systemf("%s -xf ../archive.tar --exclude file3 file1 >test.out 2>test.err", testprog)); 93 assertFileContents("file1", 5, "file1"); 94 assertFileNotExists("file2"); 95 assertFileNotExists("file3"); 96 assertEmptyFile("test.out"); 97 assertEmptyFile("test.err"); 98 assertChdir(".."); 99 100 /* Test 8: Include a non-existent file */ 101 assertMakeDir("test8", 0755); 102 assertChdir("test8"); 103 r = systemf("%s -xf ../archive.tar file3 >test.out 2>test.err", testprog); 104 assert(r != 0); 105 assertFileNotExists("file1"); 106 assertFileNotExists("file2"); 107 assertFileNotExists("file3"); 108 assertEmptyFile("test.out"); 109 assertNonEmptyFile("test.err"); 110 assertChdir(".."); 111 112 /* Test 9: Include a non-existent file plus an exclusion */ 113 assertMakeDir("test9", 0755); 114 assertChdir("test9"); 115 r = systemf("%s -xf ../archive.tar --exclude file1 file3 >test.out 2>test.err", testprog); 116 assert(r != 0); 117 assertFileNotExists("file1"); 118 assertFileNotExists("file2"); 119 assertFileNotExists("file3"); 120 assertEmptyFile("test.out"); 121 assertNonEmptyFile("test.err"); 122 assertChdir(".."); 123 } 124