Skip to content

Commit

Permalink
Fixed code to avoid "golang/go#51442" bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nao1215 committed Sep 18, 2022
1 parent a6dae4c commit f524fc6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
15 changes: 10 additions & 5 deletions cmd/remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"runtime"
"strings"
"testing"
"time"

"github.com/google/go-cmp/cmp"
"github.com/nao1215/gup/internal/file"
Expand Down Expand Up @@ -316,10 +315,16 @@ func mockStdin(t *testing.T, dummyInput string) (funcDefer func(), err error) {
t.Helper()

oldOsStdin := os.Stdin
tmpFile, err := os.CreateTemp(t.TempDir(), time.Now().GoString())

if err != nil {
return nil, err
var tmpFile *os.File
var e error
if runtime.GOOS != "windows" {
tmpFile, e = os.CreateTemp(t.TempDir(), strings.ReplaceAll(t.Name(), "/", ""))
} else {
// See https://github.com/golang/go/issues/51442
tmpFile, err = os.CreateTemp(os.TempDir(), strings.ReplaceAll(t.Name(), "/", ""))
}
if e != nil {
return nil, e
}

content := []byte(dummyInput)
Expand Down
16 changes: 11 additions & 5 deletions internal/print/print_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"errors"
"io"
"os"
"runtime"
"strings"
"testing"
"time"

"github.com/google/go-cmp/cmp"
)
Expand Down Expand Up @@ -294,10 +294,16 @@ func mockStdin(t *testing.T, dummyInput string) (funcDefer func(), err error) {
t.Helper()

oldOsStdin := os.Stdin
tmpFile, err := os.CreateTemp(t.TempDir(), time.Now().GoString())

if err != nil {
return nil, err
var tmpFile *os.File
var e error
if runtime.GOOS != "windows" {
tmpFile, e = os.CreateTemp(t.TempDir(), strings.ReplaceAll(t.Name(), "/", ""))
} else {
// See https://github.com/golang/go/issues/51442
tmpFile, e = os.CreateTemp(os.TempDir(), strings.ReplaceAll(t.Name(), "/", ""))
}
if e != nil {
return nil, e
}

content := []byte(dummyInput)
Expand Down

0 comments on commit f524fc6

Please sign in to comment.