xref: /freebsd/contrib/libarchive/tar/test/test_option_keep_newer_files.c (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
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_keep_newer_files)
10 {
11 	const char *reffile = "test_option_keep_newer_files.tar.Z";
12 
13 	/* Reference file has one entry "file" with a very old timestamp. */
14 	extract_reference_file(reffile);
15 
16 	/* Test 1: Without --keep-newer-files */
17 	assertMakeDir("test1", 0755);
18 	assertChdir("test1");
19 	assertMakeFile("file", 0644, "new");
20 	assertEqualInt(0,
21 	    systemf("%s -xf ../%s >test.out 2>test.err", testprog, reffile));
22 	assertFileContents("old\n", 4, "file");
23 	assertEmptyFile("test.out");
24 	assertEmptyFile("test.err");
25 	assertChdir("..");
26 
27 	/* Test 2: With --keep-newer-files */
28 	assertMakeDir("test2", 0755);
29 	assertChdir("test2");
30 	assertMakeFile("file", 0644, "new");
31 	assertEqualInt(0,
32 	    systemf("%s -xf ../%s --keep-newer-files >test.out 2>test.err", testprog, reffile));
33 	assertFileContents("new", 3, "file");
34 	assertEmptyFile("test.out");
35 	assertEmptyFile("test.err");
36 	assertChdir("..");
37 }
38