]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Fix some TODOs in tar/test/test_stdio.c (#2442)
authorGraham Percival <gperciva@tarsnap.com>
Thu, 19 Dec 2024 22:24:57 +0000 (14:24 -0800)
committerGitHub <noreply@github.com>
Thu, 19 Dec 2024 22:24:57 +0000 (14:24 -0800)
tar/test/test_stdio.c

index 0c27c59a2af6413a4fbc5072b277069ff66fd509..8bb08ca451f7b73495c24d2330781748ad9c84c8 100644 (file)
@@ -6,6 +6,22 @@
  */
 #include "test.h"
 
+/*
+ * This data would fit onto one line, but it's easier to understand when it's
+ * on mulitple lines (and thus matches the output files).
+ */
+static const char *cvf_err =
+"a f\n"
+"a l\n";
+
+static const char *tf_out =
+"f\n"
+"l\n";
+
+static const char *xvf_err =
+"x f\n"
+"x l\n";
+
 DEFINE_TEST(test_stdio)
 {
        FILE *filelist;
@@ -47,7 +63,7 @@ DEFINE_TEST(test_stdio)
        failure("'cv' writes filenames to stderr, nothing to stdout (SUSv2)\n"
            "Note that GNU tar writes the file list to stdout by default.");
        assertEmptyFile("cvf.out");
-       /* TODO: Verify cvf.err has file list in SUSv2-prescribed format. */
+       assertTextFileContents(cvf_err, "cvf.err");
 
        /* 'cvf -' should generate file list on stderr, archive on stdout. */
        r = systemf("%s cvf - f l >cvf-.out 2>cvf-.err", testprog);
@@ -55,14 +71,14 @@ DEFINE_TEST(test_stdio)
        failure("cvf - should write archive to stdout");
        /* TODO: Verify cvf-.out has archive. */
        failure("cvf - should write file list to stderr (SUSv2)");
-       /* TODO: Verify cvf-.err has verbose file list. */
+       assertEqualFile("cvf.err", "cvf-.err");
 
        /* 'tf' should generate file list on stdout, empty stderr. */
        r = systemf("%s tf archive >tf.out 2>tf.err", testprog);
        assertEqualInt(r, 0);
        assertEmptyFile("tf.err");
        failure("'t' mode should write results to stdout");
-       /* TODO: Verify tf.out has file list. */
+       assertTextFileContents(tf_out, "tf.out");
 
        /* 'tvf' should generate file list on stdout, empty stderr. */
        r = systemf("%s tvf archive >tvf.out 2>tvf.err", testprog);
@@ -75,7 +91,8 @@ DEFINE_TEST(test_stdio)
        r = systemf("%s tvf - < archive >tvf-.out 2>tvf-.err", testprog);
        assertEqualInt(r, 0);
        assertEmptyFile("tvf-.err");
-       /* TODO: Verify tvf-.out has file list. */
+       failure("'tvf-' mode should write the same results as 'tvf'");
+       assertEqualFile("tvf.out", "tvf-.out");
 
        /* Basic 'xf' should generate no output on stdout or stderr. */
        r = systemf("%s xf archive >xf.out 2>xf.err", testprog);
@@ -87,7 +104,7 @@ DEFINE_TEST(test_stdio)
        r = systemf("%s xvf archive >xvf.out 2>xvf.err", testprog);
        assertEqualInt(r, 0);
        assertEmptyFile("xvf.out");
-       /* TODO: Verify xvf.err */
+       assertTextFileContents(xvf_err, "xvf.err");
 
        /* 'xvOf' should generate list on stderr, file contents on stdout. */
        r = systemf("%s xvOf archive >xvOf.out 2>xvOf.err", testprog);
@@ -96,12 +113,12 @@ DEFINE_TEST(test_stdio)
        p = slurpfile(&s, "xvOf.out");
        assertEqualInt((int)s, 3);
        assertEqualMem(p, "abc", 3);
-       /* TODO: Verify xvf.err */
+       assertEqualFile("xvf.err", "xvOf.err");
        free(p);
 
        /* 'xvf -' should generate list on stderr, empty stdout. */
        r = systemf("%s xvf - < archive >xvf-.out 2>xvf-.err", testprog);
        assertEqualInt(r, 0);
        assertEmptyFile("xvf-.out");
-       /* TODO: Verify xvf-.err */
+       assertEqualFile("xvf.err", "xvf-.err");
 }