diff options
Diffstat (limited to 'tar/test/test_basic.c')
-rw-r--r-- | tar/test/test_basic.c | 112 |
1 files changed, 63 insertions, 49 deletions
diff --git a/tar/test/test_basic.c b/tar/test/test_basic.c index 4dc7cf6..8832787 100644 --- a/tar/test/test_basic.c +++ b/tar/test/test_basic.c @@ -25,48 +25,49 @@ #include "test.h" __FBSDID("$FreeBSD: src/usr.bin/tar/test/test_basic.c,v 1.2 2008/05/26 17:10:10 kientzle Exp $"); - -static void -basic_tar(const char *target, const char *pack_options, - const char *unpack_options, const char *flist) +static const char * +make_files(void) { - int r; - - assertMakeDir(target, 0775); + FILE *f; - /* Use the tar program to create an archive. */ - r = systemf("%s cf - %s %s >%s/archive 2>%s/pack.err", testprog, pack_options, flist, target, target); - failure("Error invoking %s cf -", testprog, pack_options); - assertEqualInt(r, 0); + /* File with 10 bytes content. */ + f = fopen("file", "wb"); + assert(f != NULL); + assertEqualInt(10, fwrite("123456789", 1, 10, f)); + fclose(f); - assertChdir(target); + /* hardlink to above file. */ + assertMakeHardlink("linkfile", "file"); + assertIsHardlink("file", "linkfile"); - /* Verify that nothing went to stderr. */ - assertEmptyFile("pack.err"); + /* Symlink to above file. */ + if (canSymlink()) + assertMakeSymlink("symlink", "file"); - /* - * Use tar to unpack the archive into another directory. - */ - r = systemf("%s xf archive %s >unpack.out 2>unpack.err", testprog, unpack_options); - failure("Error invoking %s xf archive %s", testprog, unpack_options); - assertEqualInt(r, 0); + /* Directory. */ + assertMakeDir("dir", 0775); - /* Verify that nothing went to stderr. */ - assertEmptyFile("unpack.err"); + return canSymlink() + ? "file linkfile symlink dir" + : "file linkfile dir"; +} - /* - * Verify unpacked files. - */ +static void +verify_files(const char *target) +{ + assertChdir(target); /* Regular file with 2 links. */ assertIsReg("file", -1); assertFileSize("file", 10); + assertFileContents("123456789", 10, "file"); failure("%s", target); assertFileNLinks("file", 2); /* Another name for the same file. */ assertIsReg("linkfile", -1); assertFileSize("linkfile", 10); + assertFileContents("123456789", 10, "linkfile"); assertFileNLinks("linkfile", 2); assertIsHardlink("file", "linkfile"); @@ -79,37 +80,50 @@ basic_tar(const char *target, const char *pack_options, assertChdir(".."); } -DEFINE_TEST(test_basic) +static void +run_tar(const char *target, const char *pack_options, + const char *unpack_options, const char *flist) { - FILE *f; - const char *flist; + int r; - assertUmask(0); + assertMakeDir(target, 0775); - /* File with 10 bytes content. */ - f = fopen("file", "wb"); - assert(f != NULL); - assertEqualInt(10, fwrite("123456789", 1, 10, f)); - fclose(f); + /* Use the tar program to create an archive. */ + r = systemf("%s cf - %s %s >%s/archive 2>%s/pack.err", testprog, pack_options, flist, target, target); + failure("Error invoking %s cf -", testprog, pack_options); + assertEqualInt(r, 0); - /* hardlink to above file. */ - assertMakeHardlink("linkfile", "file"); - assertIsHardlink("file", "linkfile"); + assertChdir(target); - /* Symlink to above file. */ - if (canSymlink()) - assertMakeSymlink("symlink", "file"); + /* Verify that nothing went to stderr. */ + assertEmptyFile("pack.err"); - /* Directory. */ - assertMakeDir("dir", 0775); + /* + * Use tar to unpack the archive into another directory. + */ + r = systemf("%s xf archive %s >unpack.out 2>unpack.err", + testprog, unpack_options); + failure("Error invoking %s xf archive %s", testprog, unpack_options); + assertEqualInt(r, 0); - if (canSymlink()) - flist = "file linkfile symlink dir"; - else - flist = "file linkfile dir"; + /* Verify that nothing went to stderr. */ + assertEmptyFile("unpack.err"); + assertChdir(".."); +} + +DEFINE_TEST(test_basic) +{ + const char *flist; + + assertUmask(0); + flist = make_files(); /* Archive/dearchive with a variety of options. */ - basic_tar("copy", "", "", flist); + run_tar("copy", "", "", flist); + verify_files("copy"); + + run_tar("copy_ustar", "--format=ustar", "", flist); + verify_files("copy_ustar"); + /* tar doesn't handle cpio symlinks correctly */ - /* basic_tar("copy_odc", "--format=odc", ""); */ - basic_tar("copy_ustar", "--format=ustar", "", flist); + /* run_tar("copy_odc", "--format=odc", ""); */ } |