Path: blob/main/contrib/libarchive/cat/test/test_help.c
39488 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2003-2007 Tim Kientzle4* All rights reserved.5*/6#include "test.h"78/*9* Test that "--help", "-h", and "-W help" options all work and10* generate reasonable output.11*/1213static int14in_first_line(const char *p, const char *substring)15{16size_t l = strlen(substring);1718while (*p != '\0' && *p != '\n') {19if (memcmp(p, substring, l) == 0)20return (1);21++p;22}23return (0);24}2526DEFINE_TEST(test_help)27{28int r;29char *p;30size_t plen;3132/* Exercise --help option. */33r = systemf("%s --help >help.stdout 2>help.stderr", testprog);34assertEqualInt(r, 0);35failure("--help should generate nothing to stderr.");36assertEmptyFile("help.stderr");37/* Help message should start with name of program. */38p = slurpfile(&plen, "help.stdout");39failure("Help output should be long enough.");40assert(plen >= 6);41failure("First line of help output should contain 'bsdcat': %s", p);42assert(in_first_line(p, "bsdcat"));43/*44* TODO: Extend this check to further verify that --help output45* looks approximately right.46*/47free(p);4849/* -h option should generate the same output. */50r = systemf("%s -h >h.stdout 2>h.stderr", testprog);51assertEqualInt(r, 0);52failure("-h should generate nothing to stderr.");53assertEmptyFile("h.stderr");54failure("stdout should be same for -h and --help");55assertEqualFile("h.stdout", "help.stdout");56}575859