Skip to content

Commit

Permalink
testscript: fix race in setupfilenames test
Browse files Browse the repository at this point in the history
Also switch to using -race in go test ./... in CI config
  • Loading branch information
myitcv committed Jan 13, 2020
1 parent bf08ea5 commit 9ba619c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ before_install:
install: "echo no install step required"

script:
- go test ./...
- go test -race ./...
- go mod tidy

# https://github.com/golang/go/issues/27868#issuecomment-431413621
Expand Down
11 changes: 6 additions & 5 deletions testscript/testscript_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ func TestCRLFInput(t *testing.T) {
func TestScripts(t *testing.T) {
// TODO set temp directory.
testDeferCount := 0
var setupFilenames []string
Run(t, Params{
Dir: "testdata",
Cmds: map[string]func(ts *TestScript, neg bool, args []string){
Expand All @@ -104,9 +103,10 @@ func TestScripts(t *testing.T) {
testDeferCount--
})
},
"setup-filenames": func(ts *TestScript, neg bool, args []string) {
if !reflect.DeepEqual(args, setupFilenames) {
ts.Fatalf("setup did not see expected files; got %q want %q", setupFilenames, args)
"setup-filenames": func(ts *TestScript, neg bool, want []string) {
got := ts.Value("setupFilenames")
if !reflect.DeepEqual(want, got) {
ts.Fatalf("setup did not see expected files; got %q want %q", got, want)
}
},
"test-values": func(ts *TestScript, neg bool, args []string) {
Expand Down Expand Up @@ -159,10 +159,11 @@ func TestScripts(t *testing.T) {
if err != nil {
return fmt.Errorf("cannot read workdir: %v", err)
}
setupFilenames = nil
var setupFilenames []string
for _, info := range infos {
setupFilenames = append(setupFilenames, info.Name())
}
env.Values["setupFilenames"] = setupFilenames
env.Values["somekey"] = 1234
env.Vars = append(env.Vars,
"GONOSUMDB=*",
Expand Down

0 comments on commit 9ba619c

Please sign in to comment.