TestCaptureOutputToFile tests CaptureOutputToFile.
(t *testing.T)
| 115 | |
| 116 | // TestCaptureOutputToFile tests CaptureOutputToFile. |
| 117 | func TestCaptureOutputToFile(t *testing.T) { |
| 118 | assert := asrt.New(t) |
| 119 | restoreOutput, err := util.CaptureOutputToFile() |
| 120 | assert.NoError(err) |
| 121 | text := util.RandString(128) |
| 122 | fmt.Println("randstring-println=" + text) |
| 123 | c := exec.Command("sh", "-c", fmt.Sprintf("echo randstring-stdout=%s; echo 1>&2 randstring-stderr=%s", text, text)) |
| 124 | c.Stdout = os.Stdout |
| 125 | c.Stderr = os.Stderr |
| 126 | err = c.Start() |
| 127 | assert.NoError(err) |
| 128 | err = c.Wait() |
| 129 | assert.NoError(err) |
| 130 | |
| 131 | out := restoreOutput() |
| 132 | |
| 133 | assert.Contains(out, "randstring-println="+text) |
| 134 | assert.Contains(out, "randstring-stdout="+text) |
| 135 | assert.Contains(out, "randstring-stderr="+text) |
| 136 | } |
| 137 | |
| 138 | // TestConfirmTo ensures that the confirmation prompt works as expected. |
| 139 | func TestConfirmTo(t *testing.T) { |
nothing calls this directly
no test coverage detected