@@ -22,6 +22,12 @@ import (
2222const (
2323 IOPreferenceUndefinedNopCloser pipe.IOPreference = iota + 100
2424 IOPreferenceFileNopCloser
25+
26+ // expectNil is a test-only expectation token meaning that the
27+ // stage should be passed a `nil` stdin / stdout (which happens at
28+ // the beginning / end of a pipeline when no overall stdin / stdout
29+ // is configured). It is not a real `IOPreference`.
30+ expectNil
2531)
2632
2733func file (t * testing.T ) * os.File {
@@ -143,7 +149,7 @@ func prefString(pref pipe.IOPreference) string {
143149 return "other"
144150 case pipe .IOPreferenceFile :
145151 return "*os.File"
146- case pipe . IOPreferenceNil :
152+ case expectNil :
147153 return "nil"
148154 case IOPreferenceUndefinedNopCloser :
149155 return "nopCloser(other)"
@@ -200,7 +206,7 @@ func TestPipeTypes(t *testing.T) {
200206 name : "func" ,
201207 opts : []pipe.Option {},
202208 stages : []pipe.Stage {
203- newPipeSniffingFunc (pipe . IOPreferenceNil , pipe . IOPreferenceNil ),
209+ newPipeSniffingFunc (expectNil , expectNil ),
204210 },
205211 },
206212 {
@@ -209,7 +215,7 @@ func TestPipeTypes(t *testing.T) {
209215 pipe .WithStdin (file (t )),
210216 },
211217 stages : []pipe.Stage {
212- newPipeSniffingFunc (IOPreferenceFileNopCloser , pipe . IOPreferenceNil ),
218+ newPipeSniffingFunc (IOPreferenceFileNopCloser , expectNil ),
213219 },
214220 },
215221 {
@@ -218,7 +224,7 @@ func TestPipeTypes(t *testing.T) {
218224 pipe .WithStdout (file (t )),
219225 },
220226 stages : []pipe.Stage {
221- newPipeSniffingFunc (pipe . IOPreferenceNil , IOPreferenceFileNopCloser ),
227+ newPipeSniffingFunc (expectNil , IOPreferenceFileNopCloser ),
222228 },
223229 },
224230 {
@@ -227,7 +233,7 @@ func TestPipeTypes(t *testing.T) {
227233 pipe .WithStdoutCloser (file (t )),
228234 },
229235 stages : []pipe.Stage {
230- newPipeSniffingFunc (pipe . IOPreferenceNil , pipe .IOPreferenceFile ),
236+ newPipeSniffingFunc (expectNil , pipe .IOPreferenceFile ),
231237 },
232238 },
233239 {
@@ -244,7 +250,7 @@ func TestPipeTypes(t *testing.T) {
244250 name : "cmd" ,
245251 opts : []pipe.Option {},
246252 stages : []pipe.Stage {
247- newPipeSniffingCmd (pipe . IOPreferenceNil , pipe . IOPreferenceNil ),
253+ newPipeSniffingCmd (expectNil , expectNil ),
248254 },
249255 },
250256 {
@@ -253,7 +259,7 @@ func TestPipeTypes(t *testing.T) {
253259 pipe .WithStdin (file (t )),
254260 },
255261 stages : []pipe.Stage {
256- newPipeSniffingCmd (IOPreferenceFileNopCloser , pipe . IOPreferenceNil ),
262+ newPipeSniffingCmd (IOPreferenceFileNopCloser , expectNil ),
257263 },
258264 },
259265 {
@@ -262,7 +268,7 @@ func TestPipeTypes(t *testing.T) {
262268 pipe .WithStdout (file (t )),
263269 },
264270 stages : []pipe.Stage {
265- newPipeSniffingCmd (pipe . IOPreferenceNil , IOPreferenceFileNopCloser ),
271+ newPipeSniffingCmd (expectNil , IOPreferenceFileNopCloser ),
266272 },
267273 },
268274 {
@@ -271,7 +277,7 @@ func TestPipeTypes(t *testing.T) {
271277 pipe .WithStdoutCloser (file (t )),
272278 },
273279 stages : []pipe.Stage {
274- newPipeSniffingCmd (pipe . IOPreferenceNil , pipe .IOPreferenceFile ),
280+ newPipeSniffingCmd (expectNil , pipe .IOPreferenceFile ),
275281 },
276282 },
277283 {
@@ -301,7 +307,7 @@ func TestPipeTypes(t *testing.T) {
301307 pipe .WithStdout (file (t )),
302308 },
303309 stages : []pipe.Stage {
304- newPipeSniffingFunc (pipe . IOPreferenceNil , pipe .IOPreferenceFile ),
310+ newPipeSniffingFunc (expectNil , pipe .IOPreferenceFile ),
305311 newPipeSniffingCmd (pipe .IOPreferenceFile , IOPreferenceFileNopCloser ),
306312 },
307313 },
@@ -312,23 +318,23 @@ func TestPipeTypes(t *testing.T) {
312318 },
313319 stages : []pipe.Stage {
314320 newPipeSniffingCmd (IOPreferenceUndefinedNopCloser , pipe .IOPreferenceFile ),
315- newPipeSniffingFunc (pipe .IOPreferenceFile , pipe . IOPreferenceNil ),
321+ newPipeSniffingFunc (pipe .IOPreferenceFile , expectNil ),
316322 },
317323 },
318324 {
319325 name : "cmd-cmd" ,
320326 opts : []pipe.Option {},
321327 stages : []pipe.Stage {
322- newPipeSniffingCmd (pipe . IOPreferenceNil , pipe .IOPreferenceFile ),
323- newPipeSniffingCmd (pipe .IOPreferenceFile , pipe . IOPreferenceNil ),
328+ newPipeSniffingCmd (expectNil , pipe .IOPreferenceFile ),
329+ newPipeSniffingCmd (pipe .IOPreferenceFile , expectNil ),
324330 },
325331 },
326332 {
327333 name : "hybrid1" ,
328334 opts : []pipe.Option {},
329335 stages : []pipe.Stage {
330336 newPipeSniffingStage (
331- pipe .IOPreferenceUndefined , pipe . IOPreferenceNil ,
337+ pipe .IOPreferenceUndefined , expectNil ,
332338 pipe .IOPreferenceUndefined , pipe .IOPreferenceUndefined ,
333339 ),
334340 newPipeSniffingStage (
@@ -337,7 +343,7 @@ func TestPipeTypes(t *testing.T) {
337343 ),
338344 newPipeSniffingStage (
339345 pipe .IOPreferenceUndefined , pipe .IOPreferenceFile ,
340- pipe .IOPreferenceUndefined , pipe . IOPreferenceNil ,
346+ pipe .IOPreferenceUndefined , expectNil ,
341347 ),
342348 },
343349 },
@@ -346,7 +352,7 @@ func TestPipeTypes(t *testing.T) {
346352 opts : []pipe.Option {},
347353 stages : []pipe.Stage {
348354 newPipeSniffingStage (
349- pipe .IOPreferenceUndefined , pipe . IOPreferenceNil ,
355+ pipe .IOPreferenceUndefined , expectNil ,
350356 pipe .IOPreferenceUndefined , pipe .IOPreferenceFile ,
351357 ),
352358 newPipeSniffingStage (
@@ -355,7 +361,7 @@ func TestPipeTypes(t *testing.T) {
355361 ),
356362 newPipeSniffingStage (
357363 pipe .IOPreferenceUndefined , pipe .IOPreferenceUndefined ,
358- pipe .IOPreferenceUndefined , pipe . IOPreferenceNil ,
364+ pipe .IOPreferenceUndefined , expectNil ,
359365 ),
360366 },
361367 },
0 commit comments