mirror of
https://gitlab.alpinelinux.org/alpine/abuild.git
synced 2025-02-01 20:22:51 +00:00
abuild-tar: fix --help and add test for usage
This commit is contained in:
parent
94122d7bec
commit
8a16229d3e
16
abuild-tar.c
16
abuild-tar.c
@ -104,9 +104,9 @@ static void tarhdr_checksum(struct tar_header *hdr)
|
|||||||
put_octal(hdr->chksum, sizeof(hdr->chksum)-1, chksum);
|
put_octal(hdr->chksum, sizeof(hdr->chksum)-1, chksum);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int usage(void)
|
static int usage(FILE *out)
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(out,
|
||||||
"abuild-tar " VERSION "\n"
|
"abuild-tar " VERSION "\n"
|
||||||
"\n"
|
"\n"
|
||||||
"usage: abuild-tar [--hash[=<algorithm>]] [--cut]\n"
|
"usage: abuild-tar [--hash[=<algorithm>]] [--cut]\n"
|
||||||
@ -367,9 +367,10 @@ err:
|
|||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
static int cut = 0;
|
static int cut = 0, help = 0;
|
||||||
static const struct option options[] = {
|
static const struct option options[] = {
|
||||||
{ "hash", optional_argument },
|
{ "hash", optional_argument },
|
||||||
|
{ "help", no_argument, &help, 1 },
|
||||||
{ "cut", no_argument, &cut, 1 },
|
{ "cut", no_argument, &cut, 1 },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
@ -388,15 +389,18 @@ int main(int argc, char **argv)
|
|||||||
digest = optarg ? optarg : "sha1";
|
digest = optarg ? optarg : "sha1";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (help)
|
||||||
|
return usage(stdout) && 0;
|
||||||
|
|
||||||
if (digest == NULL && cut == 0)
|
if (digest == NULL && cut == 0)
|
||||||
return usage();
|
return usage(stderr);
|
||||||
if (isatty(STDIN_FILENO))
|
if (isatty(STDIN_FILENO))
|
||||||
return usage();
|
return usage(stderr);
|
||||||
|
|
||||||
if (digest != NULL) {
|
if (digest != NULL) {
|
||||||
md = EVP_get_digestbyname(digest);
|
md = EVP_get_digestbyname(digest);
|
||||||
if (md == NULL)
|
if (md == NULL)
|
||||||
return usage();
|
return usage(stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return do_it(md, cut);
|
return do_it(md, cut);
|
||||||
|
20
tests/abuild_tar_test
Executable file
20
tests/abuild_tar_test
Executable file
@ -0,0 +1,20 @@
|
|||||||
|
#!/usr/bin/env atf-sh
|
||||||
|
|
||||||
|
. $(atf_get_srcdir)/test_env.sh
|
||||||
|
init_tests \
|
||||||
|
abuild_tar_help \
|
||||||
|
abuild_tar_invalid_opt
|
||||||
|
|
||||||
|
DATADIR=$(atf_get_srcdir)/testdata
|
||||||
|
|
||||||
|
abuild_tar_help_body() {
|
||||||
|
atf_check -s exit:0 \
|
||||||
|
-o match:"usage:" \
|
||||||
|
abuild-tar --help
|
||||||
|
}
|
||||||
|
|
||||||
|
abuild_tar_invalid_opt_body() {
|
||||||
|
atf_check -s not-exit:0 \
|
||||||
|
-e match:"usage:" \
|
||||||
|
abuild-tar --invalid
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user