Path: blob/main/contrib/libarchive/tar/test/test_option_exclude.c
39536 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2010 Tim Kientzle4* All rights reserved.5*/6#include "test.h"78DEFINE_TEST(test_option_exclude)9{10int r;1112assertMakeFile("file1", 0644, "file1");13assertMakeFile("file2", 0644, "file2");14assertEqualInt(0, systemf("%s -cf archive.tar file1 file2", testprog));1516/*17* Now, try extracting from the test archive with various --exclude options.18*/1920/* Test 1: Without --exclude */21assertMakeDir("test1", 0755);22assertChdir("test1");23assertEqualInt(0,24systemf("%s -xf ../archive.tar >test.out 2>test.err", testprog));25assertFileContents("file1", 5, "file1");26assertFileContents("file2", 5, "file2");27assertEmptyFile("test.out");28assertEmptyFile("test.err");29assertChdir("..");3031/* Test 2: Selecting just one file */32assertMakeDir("test2", 0755);33assertChdir("test2");34assertEqualInt(0,35systemf("%s -xf ../archive.tar file1 >test.out 2>test.err", testprog));36assertFileContents("file1", 5, "file1");37assertFileNotExists("file2");38assertEmptyFile("test.out");39assertEmptyFile("test.err");40assertChdir("..");4142/* Test 3: Use --exclude to skip one file */43assertMakeDir("test3", 0755);44assertChdir("test3");45assertEqualInt(0,46systemf("%s -xf ../archive.tar --exclude file1 >test.out 2>test.err", testprog));47assertFileNotExists("file1");48assertFileContents("file2", 5, "file2");49assertEmptyFile("test.out");50assertEmptyFile("test.err");51assertChdir("..");5253/* Test 4: Selecting one valid and one invalid file */54assertMakeDir("test4", 0755);55assertChdir("test4");56r = systemf("%s -xf ../archive.tar file1 file3 >test.out 2>test.err", testprog);57assert(r != 0);58assertFileContents("file1", 5, "file1");59assertFileNotExists("file2");60assertFileNotExists("file3");61assertEmptyFile("test.out");62assertNonEmptyFile("test.err");63assertChdir("..");6465/* Test 5: Selecting one valid file twice */66assertMakeDir("test5", 0755);67assertChdir("test5");68assertEqualInt(0,69systemf("%s -xf ../archive.tar file1 file1 >test.out 2>test.err", testprog));70assertFileContents("file1", 5, "file1");71assertFileNotExists("file2");72assertEmptyFile("test.out");73assertEmptyFile("test.err");74assertChdir("..");7576/* Test 6: Include and exclude the same file */77assertMakeDir("test6", 0755);78assertChdir("test6");79assertEqualInt(0,80systemf("%s -xf ../archive.tar --exclude file1 file1 >test.out 2>test.err", testprog));81assertFileNotExists("file1");82assertFileNotExists("file2");83assertEmptyFile("test.out");84assertEmptyFile("test.err");85assertChdir("..");8687/* Test 7: Exclude a non-existent file */88assertMakeDir("test7", 0755);89assertChdir("test7");90assertEqualInt(0,91systemf("%s -xf ../archive.tar --exclude file3 file1 >test.out 2>test.err", testprog));92assertFileContents("file1", 5, "file1");93assertFileNotExists("file2");94assertFileNotExists("file3");95assertEmptyFile("test.out");96assertEmptyFile("test.err");97assertChdir("..");9899/* Test 8: Include a non-existent file */100assertMakeDir("test8", 0755);101assertChdir("test8");102r = systemf("%s -xf ../archive.tar file3 >test.out 2>test.err", testprog);103assert(r != 0);104assertFileNotExists("file1");105assertFileNotExists("file2");106assertFileNotExists("file3");107assertEmptyFile("test.out");108assertNonEmptyFile("test.err");109assertChdir("..");110111/* Test 9: Include a non-existent file plus an exclusion */112assertMakeDir("test9", 0755);113assertChdir("test9");114r = systemf("%s -xf ../archive.tar --exclude file1 file3 >test.out 2>test.err", testprog);115assert(r != 0);116assertFileNotExists("file1");117assertFileNotExists("file2");118assertFileNotExists("file3");119assertEmptyFile("test.out");120assertNonEmptyFile("test.err");121assertChdir("..");122}123124125