github.com/unirita/cuto@v0.9.8-0.20160830082821-aa6652f877b7/testutil/capturer_test.go (about)

     1  package testutil
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"testing"
     7  )
     8  
     9  func TestCapturer_標準出力をキャプチャできる(t *testing.T) {
    10  	c := NewStdoutCapturer()
    11  	c.Start()
    12  	fmt.Println("test")
    13  	output := c.Stop()
    14  	if output != "test\n" {
    15  		t.Errorf("キャプチャ結果[%s]が想定と違う。", output)
    16  	}
    17  }
    18  
    19  func TestCapturer_標準エラー出力をキャプチャできる(t *testing.T) {
    20  	c := NewStderrCapturer()
    21  	c.Start()
    22  	fmt.Fprintln(os.Stderr, "test")
    23  	output := c.Stop()
    24  	if output != "test\n" {
    25  		t.Errorf("キャプチャ結果[%s]が想定と違う。", output)
    26  	}
    27  }