| 1701 | } |
| 1702 | |
| 1703 | func TestWriteFile_WritesInputToFileCreatingItIfNecessary(t *testing.T) { |
| 1704 | t.Parallel() |
| 1705 | want := "Hello, world" |
| 1706 | path := t.TempDir() + "/" + t.Name() |
| 1707 | wrote, err := script.Echo(want).WriteFile(path) |
| 1708 | if err != nil { |
| 1709 | t.Fatal(err) |
| 1710 | } |
| 1711 | if int(wrote) != len(want) { |
| 1712 | t.Fatalf("want %d bytes written, got %d", len(want), int(wrote)) |
| 1713 | } |
| 1714 | got, err := script.File(path).String() |
| 1715 | if err != nil { |
| 1716 | t.Fatal(err) |
| 1717 | } |
| 1718 | if got != want { |
| 1719 | t.Errorf("want %q, got %q", want, got) |
| 1720 | } |
| 1721 | } |
| 1722 | |
| 1723 | // partialErrReader returns 1 and a non-EOF error on reading. |
| 1724 | type partialErrReader struct{} |