summaryrefslogtreecommitdiffstats
path: root/usr.bin/tar/test
diff options
context:
space:
mode:
authorkientzle <kientzle@FreeBSD.org>2008-08-21 07:04:57 +0000
committerkientzle <kientzle@FreeBSD.org>2008-08-21 07:04:57 +0000
commitaeb6db009284ab77dba7815ac89f692a5ca5cfdc (patch)
tree36be5e393d3f1eed4e9e7728d5ace958c5451feb /usr.bin/tar/test
parentb25650cc125c051999d50e3520607fe1e1139297 (diff)
downloadFreeBSD-src-aeb6db009284ab77dba7815ac89f692a5ca5cfdc.zip
FreeBSD-src-aeb6db009284ab77dba7815ac89f692a5ca5cfdc.tar.gz
Add some more tests to verify that "./foo" matches "foo" but "/foo" does not.
Diffstat (limited to 'usr.bin/tar/test')
-rw-r--r--usr.bin/tar/test/main.c31
-rw-r--r--usr.bin/tar/test/test.h4
-rw-r--r--usr.bin/tar/test/test_patterns.c34
-rw-r--r--usr.bin/tar/test/test_patterns_3.tgz.uu8
4 files changed, 76 insertions, 1 deletions
diff --git a/usr.bin/tar/test/main.c b/usr.bin/tar/test/main.c
index 3f4384f..c9284c1 100644
--- a/usr.bin/tar/test/main.c
+++ b/usr.bin/tar/test/main.c
@@ -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
diff --git a/usr.bin/tar/test/test.h b/usr.bin/tar/test/test.h
index 39a9837..bb7003e 100644
--- a/usr.bin/tar/test/test.h
+++ b/usr.bin/tar/test/test.h
@@ -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 *);
diff --git a/usr.bin/tar/test/test_patterns.c b/usr.bin/tar/test/test_patterns.c
index 575e8a4..4707dac 100644
--- a/usr.bin/tar/test/test_patterns.c
+++ b/usr.bin/tar/test/test_patterns.c
@@ -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));
}
diff --git a/usr.bin/tar/test/test_patterns_3.tgz.uu b/usr.bin/tar/test/test_patterns_3.tgz.uu
new file mode 100644
index 0000000..f85afc0
--- /dev/null
+++ b/usr.bin/tar/test/test_patterns_3.tgz.uu
@@ -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
OpenPOWER on IntegriCloud