2
* Copyright (c) 2003-2007 Tim Kientzle
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
8
* 1. Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
14
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_stdio.c,v 1.2 2008/05/26 17:10:10 kientzle Exp $");
28
DEFINE_TEST(test_stdio)
38
* Create a couple of files on disk.
41
assertMakeFile("f", 0755, "abc");
42
/* Link to above file. */
43
assertMakeHardlink("l", "f");
45
/* Create file list (text mode here) */
46
filelist = fopen("filelist", "w");
47
assert(filelist != NULL);
48
fprintf(filelist, "f\n");
49
fprintf(filelist, "l\n");
53
* Archive/dearchive with a variety of options, verifying
57
/* 'cf' should generate no output unless there's an error. */
58
r = systemf("%s cf archive f l >cf.out 2>cf.err", testprog);
60
assertEmptyFile("cf.out");
61
assertEmptyFile("cf.err");
63
/* 'cvf' should generate file list on stderr, empty stdout. */
64
r = systemf("%s cvf archive f l >cvf.out 2>cvf.err", testprog);
66
failure("'cv' writes filenames to stderr, nothing to stdout (SUSv2)\n"
67
"Note that GNU tar writes the file list to stdout by default.");
68
assertEmptyFile("cvf.out");
69
/* TODO: Verify cvf.err has file list in SUSv2-prescribed format. */
71
/* 'cvf -' should generate file list on stderr, archive on stdout. */
72
r = systemf("%s cvf - f l >cvf-.out 2>cvf-.err", testprog);
74
failure("cvf - should write archive to stdout");
75
/* TODO: Verify cvf-.out has archive. */
76
failure("cvf - should write file list to stderr (SUSv2)");
77
/* TODO: Verify cvf-.err has verbose file list. */
79
/* 'tf' should generate file list on stdout, empty stderr. */
80
r = systemf("%s tf archive >tf.out 2>tf.err", testprog);
82
assertEmptyFile("tf.err");
83
failure("'t' mode should write results to stdout");
84
/* TODO: Verify tf.out has file list. */
86
/* 'tvf' should generate file list on stdout, empty stderr. */
87
r = systemf("%s tvf archive >tvf.out 2>tvf.err", testprog);
89
assertEmptyFile("tvf.err");
90
failure("'tv' mode should write results to stdout");
91
/* TODO: Verify tvf.out has file list. */
93
/* 'tvf -' uses stdin, file list on stdout, empty stderr. */
94
r = systemf("%s tvf - < archive >tvf-.out 2>tvf-.err", testprog);
96
assertEmptyFile("tvf-.err");
97
/* TODO: Verify tvf-.out has file list. */
99
/* Basic 'xf' should generate no output on stdout or stderr. */
100
r = systemf("%s xf archive >xf.out 2>xf.err", testprog);
101
assertEqualInt(r, 0);
102
assertEmptyFile("xf.err");
103
assertEmptyFile("xf.out");
105
/* 'xvf' should generate list on stderr, empty stdout. */
106
r = systemf("%s xvf archive >xvf.out 2>xvf.err", testprog);
107
assertEqualInt(r, 0);
108
assertEmptyFile("xvf.out");
109
/* TODO: Verify xvf.err */
111
/* 'xvOf' should generate list on stderr, file contents on stdout. */
112
r = systemf("%s xvOf archive >xvOf.out 2>xvOf.err", testprog);
113
assertEqualInt(r, 0);
114
/* Verify xvOf.out is the file contents */
115
p = slurpfile(&s, "xvOf.out");
117
assertEqualMem(p, "abc", 3);
118
/* TODO: Verify xvf.err */
120
/* 'xvf -' should generate list on stderr, empty stdout. */
121
r = systemf("%s xvf - < archive >xvf-.out 2>xvf-.err", testprog);
122
assertEqualInt(r, 0);
123
assertEmptyFile("xvf-.out");
124
/* TODO: Verify xvf-.err */