mirror of
https://github.com/file/file.git
synced 2024-11-23 09:56:30 +08:00
Add multiple magic with continuation test
This commit is contained in:
parent
3503cc0c92
commit
b74150490b
@ -57,6 +57,11 @@ jsonlines1.testfile \
|
||||
jsonlines1.result \
|
||||
matilde.arm.result \
|
||||
matilde.arm.testfile \
|
||||
multiple-A.magic \
|
||||
multiple-B.magic \
|
||||
multiple.flags \
|
||||
multiple.result \
|
||||
multiple.testfile \
|
||||
pcjr.result \
|
||||
pcjr.testfile \
|
||||
pgp-binary-key-v2-phil.result \
|
||||
@ -127,14 +132,27 @@ zstd-v0.8-FF.testfile
|
||||
|
||||
T = $(top_srcdir)/tests
|
||||
check-local:
|
||||
MAGIC=$(top_builddir)/magic/magic ./test
|
||||
set -e; \
|
||||
for i in $T/*.testfile; do \
|
||||
echo Running test: $$i; \
|
||||
if [ -f $${i%%.testfile}.magic ]; then \
|
||||
m=$${i%%.testfile}.magic; \
|
||||
else \
|
||||
t=$${i%%.testfile}; \
|
||||
echo Running test: $$t; \
|
||||
m=; \
|
||||
for j in $$(eval echo $${t}\*.magic); do \
|
||||
if [ -f "$$j" ]; then \
|
||||
if [ -z "$$m" ]; then \
|
||||
m=$$j; \
|
||||
else \
|
||||
m=$$m:$$j; \
|
||||
fi \
|
||||
fi \
|
||||
done; \
|
||||
if [ -z "$$m" ]; then \
|
||||
m=$(top_builddir)/magic/magic; \
|
||||
fi; \
|
||||
TZ=UTC MAGIC=$$m ./test $$i $${i%%.testfile}.result; \
|
||||
f=-e; \
|
||||
if [ -f $${t}.flags ]; then \
|
||||
f=$$f$$(cat $${t}.flags); \
|
||||
fi; \
|
||||
echo TZ=UTC MAGIC=$$m ./test $$f $$i $${t}.result; \
|
||||
TZ=UTC MAGIC=$$m ./test $$f $$i $${t}.result; \
|
||||
done
|
||||
|
2
tests/multiple-A.magic
Normal file
2
tests/multiple-A.magic
Normal file
@ -0,0 +1,2 @@
|
||||
0 search {\\rt1 RTF1.0
|
||||
16 search ViVa2 Viva File 2.0
|
2
tests/multiple-B.magic
Normal file
2
tests/multiple-B.magic
Normal file
@ -0,0 +1,2 @@
|
||||
6 search ABCD ABCD File
|
||||
10 search TesT Test File 1.0
|
1
tests/multiple.flags
Normal file
1
tests/multiple.flags
Normal file
@ -0,0 +1 @@
|
||||
k
|
1
tests/multiple.result
Normal file
1
tests/multiple.result
Normal file
@ -0,0 +1 @@
|
||||
RTF1.0\012- Viva File 2.0\012- ABCD File\012- Test File 1.0, ASCII text, with no line terminators
|
1
tests/multiple.testfile
Normal file
1
tests/multiple.testfile
Normal file
@ -0,0 +1 @@
|
||||
{\rt1 ABCDTesT xxViVa2
|
52
tests/test.c
52
tests/test.c
@ -27,6 +27,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
@ -76,11 +77,11 @@ slurp(FILE *fp, size_t *final_len)
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
struct magic_set *ms;
|
||||
struct magic_set *ms = NULL;
|
||||
const char *result;
|
||||
size_t result_len, desired_len;
|
||||
char *desired = NULL;
|
||||
int e = EXIT_FAILURE;
|
||||
int e = EXIT_FAILURE, flags, c;
|
||||
FILE *fp;
|
||||
|
||||
|
||||
@ -90,7 +91,32 @@ main(int argc, char **argv)
|
||||
else
|
||||
prog = argv[0];
|
||||
|
||||
ms = magic_open(MAGIC_ERROR);
|
||||
if (argc == 1)
|
||||
return 0;
|
||||
|
||||
flags = 0;
|
||||
while ((c = getopt(argc, argv, "ek")) != -1)
|
||||
switch (c) {
|
||||
case 'e':
|
||||
flags |= MAGIC_ERROR;
|
||||
break;
|
||||
case 'k':
|
||||
flags |= MAGIC_CONTINUE;
|
||||
break;
|
||||
default:
|
||||
goto usage;
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
if (argc != 2) {
|
||||
usage:
|
||||
(void)fprintf(stderr,
|
||||
"Usage: %s [-ek] TEST-FILE RESULT\n", prog);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
ms = magic_open(flags);
|
||||
if (ms == NULL) {
|
||||
(void)fprintf(stderr, "%s: ERROR opening MAGIC_NONE: %s\n",
|
||||
prog, strerror(errno));
|
||||
@ -102,29 +128,20 @@ main(int argc, char **argv)
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (argc == 1) {
|
||||
e = 0;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (argc != 3) {
|
||||
(void)fprintf(stderr, "Usage: %s TEST-FILE RESULT\n", prog);
|
||||
goto bad;
|
||||
}
|
||||
if ((result = magic_file(ms, argv[1])) == NULL) {
|
||||
if ((result = magic_file(ms, argv[0])) == NULL) {
|
||||
(void)fprintf(stderr, "%s: ERROR loading file %s: %s\n",
|
||||
prog, argv[1], magic_error(ms));
|
||||
goto bad;
|
||||
}
|
||||
fp = fopen(argv[2], "r");
|
||||
fp = fopen(argv[1], "r");
|
||||
if (fp == NULL) {
|
||||
(void)fprintf(stderr, "%s: ERROR opening `%s': %s",
|
||||
prog, argv[2], strerror(errno));
|
||||
prog, argv[1], strerror(errno));
|
||||
goto bad;
|
||||
}
|
||||
desired = slurp(fp, &desired_len);
|
||||
fclose(fp);
|
||||
(void)printf("%s: %s\n", argv[1], result);
|
||||
(void)printf("%s: %s\n", argv[0], result);
|
||||
if (strcmp(result, desired) != 0) {
|
||||
result_len = strlen(result);
|
||||
(void)fprintf(stderr, "%s: ERROR: result was (len %zu)\n%s\n"
|
||||
@ -135,6 +152,7 @@ main(int argc, char **argv)
|
||||
e = 0;
|
||||
bad:
|
||||
free(desired);
|
||||
magic_close(ms);
|
||||
if (ms)
|
||||
magic_close(ms);
|
||||
return e;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user