gitlab.com/apertussolutions/u-root@v7.0.0+incompatible/cmds/core/elvish/sys/waitforread_unix_test.go (about)

     1  // +build !windows,!plan9
     2  
     3  package sys
     4  
     5  import (
     6  	"io"
     7  	"os"
     8  	"testing"
     9  )
    10  
    11  func TestWaitForRead(t *testing.T) {
    12  	r0, w0, err := os.Pipe()
    13  	mustNil(err)
    14  	r1, w1, err := os.Pipe()
    15  	mustNil(err)
    16  	defer closeAll(r0, w0, r1, w1)
    17  
    18  	w0.WriteString("x")
    19  	ready, err := WaitForRead(r0, r1)
    20  	if err != nil {
    21  		t.Error("WaitForRead errors:", err)
    22  	}
    23  	if !ready[0] {
    24  		t.Error("Want ready[0]")
    25  	}
    26  	if ready[1] {
    27  		t.Error("Don't want ready[1]")
    28  	}
    29  }
    30  
    31  func closeAll(files ...io.Closer) {
    32  	for _, file := range files {
    33  		file.Close()
    34  	}
    35  }