xref: /freebsd/contrib/libarchive/tar/test/test_option_nodump.c (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2012 Michihiro NAKAJIMA
5  * All rights reserved.
6  */
7 #include "test.h"
8 
9 DEFINE_TEST(test_option_nodump)
10 {
11 
12 	if (!canNodump()) {
13 		skipping("Can't test nodump on this filesystem");
14 		return;
15 	}
16 
17 	assertMakeFile("file1", 0644, "file1");
18 	assertMakeFile("file2", 0644, "file2");
19 	assertMakeFile("file3", 0644, "file3");
20 	assertSetNodump("file2");
21 
22 	/* Test 1: Without --nodump */
23 	assertEqualInt(0, systemf("%s -cf test1.tar file1 file2 file3",
24 	    testprog));
25 	assertMakeDir("test1", 0755);
26 	assertChdir("test1");
27 	assertEqualInt(0,
28 	    systemf("%s -xf ../test1.tar >test.out 2>test.err", testprog));
29 	assertFileContents("file1", 5, "file1");
30 	assertFileContents("file2", 5, "file2");
31 	assertFileContents("file3", 5, "file3");
32 	assertEmptyFile("test.out");
33 	assertEmptyFile("test.err");
34 	assertChdir("..");
35 
36 	/* Test 2: With --nodump */
37 	assertEqualInt(0, systemf("%s -cf test2.tar --nodump file1 file2 file3",
38 	    testprog));
39 	assertMakeDir("test2", 0755);
40 	assertChdir("test2");
41 	assertEqualInt(0,
42 	    systemf("%s -xf ../test2.tar >test.out 2>test.err", testprog));
43 	assertFileContents("file1", 5, "file1");
44 	assertFileNotExists("file2");
45 	assertFileContents("file3", 5, "file3");
46 	assertEmptyFile("test.out");
47 	assertEmptyFile("test.err");
48 	assertChdir("..");
49 }
50