xref: /freebsd/contrib/libarchive/cpio/test/test_option_y.c (revision b64c5a0ace59af62eff52bfe110a521dc73c937b)
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_y)
10 {
11 	char *p;
12 	int r;
13 	size_t s;
14 
15 	/* Create a file. */
16 	assertMakeFile("f", 0644, "a");
17 
18 	/* Archive it with bzip2 compression. */
19 	r = systemf("echo f | %s -oy >archive.out 2>archive.err",
20 	    testprog);
21 	p = slurpfile(&s, "archive.err");
22 	free(p);
23 	if (r != 0) {
24 		if (!canBzip2()) {
25 			skipping("bzip2 is not supported on this platform");
26 			return;
27 		}
28 		failure("-y option is broken");
29 		assertEqualInt(r, 0);
30 		return;
31 	}
32 	assertTextFileContents("1 block\n", "archive.err");
33 	/* Check that the archive file has a bzip2 signature. */
34 	p = slurpfile(&s, "archive.out");
35 	assert(s > 2);
36 	assertEqualMem(p, "BZh9", 4);
37 	free(p);
38 }
39