diff options
author | Lasse Collin <lasse.collin@tukaani.org> | 2022-05-23 20:32:49 +0300 |
---|---|---|
committer | Lasse Collin <lasse.collin@tukaani.org> | 2022-05-23 20:59:47 +0300 |
commit | c7758ac9c734707514dd34f254173ebac5eea7f8 (patch) | |
tree | 77fd77ec012ebce35071b42c295cc786b3afde95 /tests | |
parent | Tests: Remove unneeded commented lines from test_compress.sh. (diff) | |
download | xz-c7758ac9c734707514dd34f254173ebac5eea7f8.tar.xz |
Test: Make create_compress_files.c a little more flexible.
If a command line argument is given, then only the test file
of that type is created. It's quite dumb in sense that unknown
names don't give an error but it's good enough here.
Also use EXIT_FAILURE instead of 1 as exit status for errors.
Diffstat (limited to '')
-rw-r--r-- | tests/create_compress_files.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/tests/create_compress_files.c b/tests/create_compress_files.c index 88d60b73..797a73e7 100644 --- a/tests/create_compress_files.c +++ b/tests/create_compress_files.c @@ -17,10 +17,15 @@ #include <stdio.h> +// If a command-line argument was given, only create the file if its +// name was specified on the command line. If no args were given then +// all files are created. +// // Avoid re-creating the test files every time the tests are run. -#define create_test(name) \ +#define maybe_create_test(argc, argv, name) \ do { \ - if (!file_exists("compress_generated_" #name)) { \ + if ((argc < 2 || strcmp(argv[1], #name) == 0) \ + && !file_exists("compress_generated_" #name)) { \ FILE *file = file_create("compress_generated_" #name); \ write_ ## name(file); \ file_finish(file, "compress_generated_" #name); \ @@ -53,7 +58,7 @@ file_create(const char *filename) if (file == NULL) { perror(filename); - exit(1); + exit(EXIT_FAILURE); } return file; @@ -68,7 +73,7 @@ file_finish(FILE *file, const char *filename) if (ferror_fail || fclose_fail) { perror(filename); - exit(1); + exit(EXIT_FAILURE); } } @@ -80,7 +85,7 @@ write_abc(FILE *file) { for (size_t i = 0; i < 12345; ++i) if (fwrite("abc\n", 4, 1, file) != 1) - exit(1); + exit(EXIT_FAILURE); } @@ -149,10 +154,10 @@ write_text(FILE *file) int -main(void) +main(int argc, char **argv) { - create_test(abc); - create_test(random); - create_test(text); - return 0; + maybe_create_test(argc, argv, abc); + maybe_create_test(argc, argv, random); + maybe_create_test(argc, argv, text); + return EXIT_SUCCESS; } |