Add some more tests to verify that "./foo" matches "foo" but "/foo" does not.

This commit is contained in:
Tim Kientzle 2008-08-21 07:04:57 +00:00
parent e0e53b4111
commit 503b743566
4 changed files with 76 additions and 1 deletions

View File

@ -502,6 +502,37 @@ test_assert_empty_file(const char *f1fmt, ...)
return (0);
}
int
test_assert_non_empty_file(const char *f1fmt, ...)
{
char f1[1024];
struct stat st;
va_list ap;
va_start(ap, f1fmt);
vsprintf(f1, f1fmt, ap);
va_end(ap);
if (stat(f1, &st) != 0) {
fprintf(stderr, "%s:%d: Could not stat: %s\n",
test_filename, test_line, f1);
report_failure(NULL);
return (0);
}
if (st.st_size != 0)
return (1);
failures ++;
if (!verbose && previous_failures(test_filename, test_line))
return (0);
fprintf(stderr, "%s:%d: File empty: %s\n",
test_filename, test_line, f1);
report_failure(NULL);
return (0);
}
/* assertEqualFile() asserts that two files have the same contents. */
/* TODO: hexdump the first bytes that actually differ. */
int

View File

@ -98,6 +98,9 @@
/* Assert that a file is empty; supports printf-style arguments. */
#define assertEmptyFile \
test_setup(__FILE__, __LINE__);test_assert_empty_file
/* Assert that a file is not empty; supports printf-style arguments. */
#define assertNonEmptyFile \
test_setup(__FILE__, __LINE__);test_assert_non_empty_file
/* Assert that a file exists; supports printf-style arguments. */
#define assertFileExists \
test_setup(__FILE__, __LINE__);test_assert_file_exists
@ -123,6 +126,7 @@ void test_setup(const char *, int);
void test_skipping(const char *fmt, ...);
int test_assert(const char *, int, int, const char *, void *);
int test_assert_empty_file(const char *, ...);
int test_assert_non_empty_file(const char *, ...);
int test_assert_equal_file(const char *, const char *, ...);
int test_assert_equal_int(const char *, int, int, const char *, int, const char *, void *);
int test_assert_equal_string(const char *, int, const char *v1, const char *, const char *v2, const char *, void *);

View File

@ -30,6 +30,7 @@ DEFINE_TEST(test_patterns)
int fd, r;
const char *reffile2 = "test_patterns_2.tgz";
const char *reffile2_out = "test_patterns_2.tgz.out";
const char *reffile3 = "test_patterns_3.tgz";
/*
* Test basic command-line pattern handling.
@ -63,6 +64,37 @@ DEFINE_TEST(test_patterns)
assertEmptyFile("tar2a.err");
/*
*
* Test 3 archive has some entries starting with '/' and some not.
*/
extract_reference_file(reffile3);
/* Test 3a: Pattern tmp/foo/bar should not match /tmp/foo/bar */
r = systemf("%s xf %s tmp/foo/bar > tar3a.out 2> tar3a.err",
testprog, reffile3);
assert(r != 0);
assertEmptyFile("tar3a.out");
/* Test 3b: Pattern /tmp/foo/baz should not match tmp/foo/baz */
assertNonEmptyFile("tar3a.err");
/* Again, with the '/' */
r = systemf("%s xf %s /tmp/foo/baz > tar3b.out 2> tar3b.err",
testprog, reffile3);
assert(r != 0);
assertEmptyFile("tar3b.out");
assertNonEmptyFile("tar3b.err");
/* Test 3c: ./tmp/foo/bar should not match /tmp/foo/bar */
r = systemf("%s xf %s ./tmp/foo/bar > tar3c.out 2> tar3c.err",
testprog, reffile3);
assert(r != 0);
assertEmptyFile("tar3c.out");
assertNonEmptyFile("tar3c.err");
/* Test 3d: ./tmp/foo/baz should match tmp/foo/baz */
r = systemf("%s xf %s ./tmp/foo/baz > tar3d.out 2> tar3d.err",
testprog, reffile3);
assertEqualInt(r, 0);
assertEmptyFile("tar3d.out");
assertEmptyFile("tar3d.err");
assertEqualInt(0, access("tmp/foo/baz/bar", F_OK));
}

View File

@ -0,0 +1,8 @@
$FreeBSD$
begin 644 test_patterns_3.tgz
M'XL(`)P/K4@``^W5T0K"(!3&\3V*;^#1H3Z/@T5!8[&,H*=O%J/M9M3(7?U_
M-T?1BR.?HD[=11_Z7C=QT%49(A*<4V,UP4FNV53?$V/$U3;OLTK,./*5<H7Z
M6;A=4QS&5M*I6]UW/[;M>65]>2CUUQX+TO/\F_@H<0<VY!^\)?\]?.(O$OW+
K3_E[R?F;FO>_BWG^I;Z`#?D'X?T#``````````````!\Y0FE&!YR`"@`````
`
end