Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/contrib/libarchive/cat/test/test_help.c
39488 views
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
/*
10
* Test that "--help", "-h", and "-W help" options all work and
11
* generate reasonable output.
12
*/
13
14
static int
15
in_first_line(const char *p, const char *substring)
16
{
17
size_t l = strlen(substring);
18
19
while (*p != '\0' && *p != '\n') {
20
if (memcmp(p, substring, l) == 0)
21
return (1);
22
++p;
23
}
24
return (0);
25
}
26
27
DEFINE_TEST(test_help)
28
{
29
int r;
30
char *p;
31
size_t plen;
32
33
/* Exercise --help option. */
34
r = systemf("%s --help >help.stdout 2>help.stderr", testprog);
35
assertEqualInt(r, 0);
36
failure("--help should generate nothing to stderr.");
37
assertEmptyFile("help.stderr");
38
/* Help message should start with name of program. */
39
p = slurpfile(&plen, "help.stdout");
40
failure("Help output should be long enough.");
41
assert(plen >= 6);
42
failure("First line of help output should contain 'bsdcat': %s", p);
43
assert(in_first_line(p, "bsdcat"));
44
/*
45
* TODO: Extend this check to further verify that --help output
46
* looks approximately right.
47
*/
48
free(p);
49
50
/* -h option should generate the same output. */
51
r = systemf("%s -h >h.stdout 2>h.stderr", testprog);
52
assertEqualInt(r, 0);
53
failure("-h should generate nothing to stderr.");
54
assertEmptyFile("h.stderr");
55
failure("stdout should be same for -h and --help");
56
assertEqualFile("h.stdout", "help.stdout");
57
}
58
59