1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2003-2007 Tim Kientzle 5 * All rights reserved. 6 */ 7 #include "test.h" 8 9 DEFINE_TEST(test_option_d) 10 { 11 int r; 12 13 /* 14 * Create a file in a directory. 15 */ 16 assertMakeDir("dir", 0755); 17 assertMakeFile("dir/file", 0644, NULL); 18 19 /* Create an archive. */ 20 r = systemf("echo dir/file | %s -o > archive.cpio 2>archive.err", testprog); 21 assertEqualInt(r, 0); 22 assertTextFileContents("1 block\n", "archive.err"); 23 assertFileSize("archive.cpio", 512); 24 25 /* Dearchive without -d, this should fail. */ 26 assertMakeDir("without-d", 0755); 27 assertChdir("without-d"); 28 r = systemf("%s -i < ../archive.cpio >out 2>err", testprog); 29 assert(r != 0); 30 assertEmptyFile("out"); 31 /* And the file should not be restored. */ 32 assertFileNotExists("dir/file"); 33 34 /* Dearchive with -d, this should succeed. */ 35 assertChdir(".."); 36 assertMakeDir("with-d", 0755); 37 assertChdir("with-d"); 38 r = systemf("%s -id < ../archive.cpio >out 2>err", testprog); 39 assertEqualInt(r, 0); 40 assertEmptyFile("out"); 41 assertTextFileContents("1 block\n", "err"); 42 /* And the file should be restored. */ 43 assertFileExists("dir/file"); 44 } 45