1 1.1 joerg /*- 2 1.1.1.3 christos * SPDX-License-Identifier: BSD-2-Clause 3 1.1.1.3 christos * 4 1.1 joerg * Copyright (c) 2010 Tim Kientzle 5 1.1 joerg * All rights reserved. 6 1.1 joerg */ 7 1.1 joerg #include "test.h" 8 1.1 joerg 9 1.1 joerg DEFINE_TEST(test_option_X_upper) 10 1.1 joerg { 11 1.1 joerg int r; 12 1.1 joerg 13 1.1 joerg /* 14 1.1 joerg * Create a sample archive. 15 1.1 joerg */ 16 1.1 joerg assertMakeFile("file1", 0644, "file1"); 17 1.1 joerg assertMakeFile("file2", 0644, "file2"); 18 1.1 joerg assertMakeFile("file3a", 0644, "file3a"); 19 1.1 joerg assertMakeFile("file4a", 0644, "file4a"); 20 1.1 joerg assertEqualInt(0, 21 1.1 joerg systemf("%s -cf archive.tar file1 file2 file3a file4a", testprog)); 22 1.1 joerg 23 1.1 joerg /* 24 1.1 joerg * Now, try extracting from the test archive with various -X usage. 25 1.1 joerg */ 26 1.1 joerg 27 1.1 joerg /* Test 1: Without -X */ 28 1.1 joerg assertMakeDir("test1", 0755); 29 1.1 joerg assertChdir("test1"); 30 1.1 joerg r = systemf("%s -xf ../archive.tar >test.out 2>test.err", 31 1.1 joerg testprog); 32 1.1 joerg if (!assertEqualInt(0, r)) 33 1.1 joerg return; 34 1.1 joerg 35 1.1 joerg assertFileContents("file1", 5, "file1"); 36 1.1 joerg assertFileContents("file2", 5, "file2"); 37 1.1 joerg assertFileContents("file3a", 6, "file3a"); 38 1.1 joerg assertFileContents("file4a", 6, "file4a"); 39 1.1 joerg assertEmptyFile("test.out"); 40 1.1 joerg assertEmptyFile("test.err"); 41 1.1 joerg assertChdir(".."); 42 1.1 joerg 43 1.1 joerg /* Test 2: Use -X to skip one file */ 44 1.1 joerg assertMakeDir("test2", 0755); 45 1.1 joerg assertChdir("test2"); 46 1.1 joerg assertMakeFile("exclusions", 0644, "file1\n"); 47 1.1 joerg assertEqualInt(0, 48 1.1 joerg systemf("%s -xf ../archive.tar -X exclusions >test.out 2>test.err", testprog)); 49 1.1 joerg assertFileNotExists("file1"); 50 1.1 joerg assertFileContents("file2", 5, "file2"); 51 1.1 joerg assertFileContents("file3a", 6, "file3a"); 52 1.1 joerg assertFileContents("file4a", 6, "file4a"); 53 1.1 joerg assertEmptyFile("test.out"); 54 1.1 joerg assertEmptyFile("test.err"); 55 1.1 joerg assertChdir(".."); 56 1.1 joerg 57 1.1 joerg /* Test 3: Use -X to skip multiple files */ 58 1.1 joerg assertMakeDir("test3", 0755); 59 1.1 joerg assertChdir("test3"); 60 1.1 joerg assertMakeFile("exclusions", 0644, "file1\nfile2\n"); 61 1.1 joerg assertEqualInt(0, 62 1.1 joerg systemf("%s -xf ../archive.tar -X exclusions >test.out 2>test.err", testprog)); 63 1.1 joerg assertFileNotExists("file1"); 64 1.1 joerg assertFileNotExists("file2"); 65 1.1 joerg assertFileContents("file3a", 6, "file3a"); 66 1.1 joerg assertFileContents("file4a", 6, "file4a"); 67 1.1 joerg assertEmptyFile("test.out"); 68 1.1 joerg assertEmptyFile("test.err"); 69 1.1 joerg assertChdir(".."); 70 1.1 joerg 71 1.1 joerg /* Test 4: Omit trailing \n */ 72 1.1 joerg assertMakeDir("test4", 0755); 73 1.1 joerg assertChdir("test4"); 74 1.1 joerg assertMakeFile("exclusions", 0644, "file1\nfile2"); 75 1.1 joerg assertEqualInt(0, 76 1.1 joerg systemf("%s -xf ../archive.tar -X exclusions >test.out 2>test.err", testprog)); 77 1.1 joerg assertFileNotExists("file1"); 78 1.1 joerg assertFileNotExists("file2"); 79 1.1 joerg assertFileContents("file3a", 6, "file3a"); 80 1.1 joerg assertFileContents("file4a", 6, "file4a"); 81 1.1 joerg assertEmptyFile("test.out"); 82 1.1 joerg assertEmptyFile("test.err"); 83 1.1 joerg assertChdir(".."); 84 1.1 joerg 85 1.1 joerg /* Test 5: include/exclude without overlap */ 86 1.1 joerg assertMakeDir("test5", 0755); 87 1.1 joerg assertChdir("test5"); 88 1.1 joerg assertMakeFile("exclusions", 0644, "file1\nfile2"); 89 1.1 joerg assertEqualInt(0, 90 1.1 joerg systemf("%s -xf ../archive.tar -X exclusions file3a >test.out 2>test.err", testprog)); 91 1.1 joerg assertFileNotExists("file1"); 92 1.1 joerg assertFileNotExists("file2"); 93 1.1 joerg assertFileContents("file3a", 6, "file3a"); 94 1.1 joerg assertFileNotExists("file4a"); 95 1.1 joerg assertEmptyFile("test.out"); 96 1.1 joerg assertEmptyFile("test.err"); 97 1.1 joerg assertChdir(".."); 98 1.1 joerg 99 1.1 joerg /* Test 6: Overlapping include/exclude */ 100 1.1 joerg assertMakeDir("test6", 0755); 101 1.1 joerg assertChdir("test6"); 102 1.1 joerg assertMakeFile("exclusions", 0644, "file1\nfile2"); 103 1.1 joerg assertEqualInt(0, 104 1.1 joerg systemf("%s -xf ../archive.tar -X exclusions file1 file3a >test.out 2>test.err", testprog)); 105 1.1 joerg assertFileNotExists("file1"); 106 1.1 joerg assertFileNotExists("file2"); 107 1.1 joerg assertFileContents("file3a", 6, "file3a"); 108 1.1 joerg assertFileNotExists("file4a"); 109 1.1 joerg assertEmptyFile("test.out"); 110 1.1 joerg assertEmptyFile("test.err"); 111 1.1 joerg assertChdir(".."); 112 1.1 joerg 113 1.1 joerg /* Test 7: with pattern */ 114 1.1 joerg assertMakeDir("test7", 0755); 115 1.1 joerg assertChdir("test7"); 116 1.1 joerg assertMakeFile("exclusions", 0644, "file*a\nfile1"); 117 1.1 joerg assertEqualInt(0, 118 1.1 joerg systemf("%s -xf ../archive.tar -X exclusions >test.out 2>test.err", testprog)); 119 1.1 joerg assertFileNotExists("file1"); 120 1.1 joerg assertFileContents("file2", 5, "file2"); 121 1.1 joerg assertFileNotExists("file3a"); 122 1.1 joerg assertFileNotExists("file4a"); 123 1.1 joerg assertEmptyFile("test.out"); 124 1.1 joerg assertEmptyFile("test.err"); 125 1.1 joerg assertChdir(".."); 126 1.1 joerg 127 1.1 joerg /* Test 8: with empty exclusions file */ 128 1.1 joerg assertMakeDir("test8", 0755); 129 1.1 joerg assertChdir("test8"); 130 1.1 joerg assertMakeFile("exclusions", 0644, ""); 131 1.1 joerg assertEqualInt(0, 132 1.1 joerg systemf("%s -xf ../archive.tar -X exclusions >test.out 2>test.err", testprog)); 133 1.1 joerg assertFileContents("file1", 5, "file1"); 134 1.1 joerg assertFileContents("file2", 5, "file2"); 135 1.1 joerg assertFileContents("file3a", 6, "file3a"); 136 1.1 joerg assertFileContents("file4a", 6, "file4a"); 137 1.1 joerg assertEmptyFile("test.out"); 138 1.1 joerg assertEmptyFile("test.err"); 139 1.1 joerg assertChdir(".."); 140 1.1 joerg } 141