lang, util: Tests that depend on the fs should be sorted

This ensures they're deterministic on any file system.
This commit is contained in:
James Shubin
2018-12-28 18:00:08 -05:00
parent 443f489152
commit 880c4d2f48
2 changed files with 24 additions and 8 deletions

View File

@@ -546,11 +546,16 @@ func TestAstFunc1(t *testing.T) {
t.Errorf("FAIL: could not read through tests directory: %+v", err) t.Errorf("FAIL: could not read through tests directory: %+v", err)
return return
} }
sorted := []string{}
for _, f := range files { for _, f := range files {
if !f.IsDir() { if !f.IsDir() {
continue continue
} }
graphFile := f.Name() + ".graph" // expected graph file sorted = append(sorted, f.Name())
}
sort.Strings(sorted)
for _, f := range sorted {
graphFile := f + ".graph" // expected graph file
graphFileFull := dir + graphFile graphFileFull := dir + graphFile
info, err := os.Stat(graphFileFull) info, err := os.Stat(graphFileFull)
if err != nil || info.IsDir() { if err != nil || info.IsDir() {
@@ -574,12 +579,12 @@ func TestAstFunc1(t *testing.T) {
// add automatic test case // add automatic test case
testCases = append(testCases, test{ testCases = append(testCases, test{
name: fmt.Sprintf("dir: %s", f.Name()), name: fmt.Sprintf("dir: %s", f),
path: f.Name() + "/", path: f + "/",
fail: errStr != "", fail: errStr != "",
expstr: str, expstr: str,
}) })
//t.Logf("adding: %s", f.Name() + "/") //t.Logf("adding: %s", f + "/")
} }
names := []string{} names := []string{}

View File

@@ -23,6 +23,7 @@ import (
"bytes" "bytes"
"io/ioutil" "io/ioutil"
"os" "os"
"sort"
"testing" "testing"
"github.com/spf13/afero" "github.com/spf13/afero"
@@ -129,11 +130,16 @@ func TestCopyDiskToFs1(t *testing.T) {
t.Errorf("could not read through tests directory: %+v", err) t.Errorf("could not read through tests directory: %+v", err)
return return
} }
sorted := []string{}
for _, f := range files { for _, f := range files {
if !f.IsDir() { if !f.IsDir() {
continue continue
} }
treeFile := f.Name() + ".tree" // expected tree file sorted = append(sorted, f.Name())
}
sort.Strings(sorted)
for _, f := range sorted {
treeFile := f + ".tree" // expected tree file
treeFileFull := dir + treeFile treeFileFull := dir + treeFile
info, err := os.Stat(treeFileFull) info, err := os.Stat(treeFileFull)
if err != nil || info.IsDir() { if err != nil || info.IsDir() {
@@ -153,7 +159,7 @@ func TestCopyDiskToFs1(t *testing.T) {
afs := &afero.Afero{Fs: mmFs} // wrap so that we're implementing ioutil afs := &afero.Afero{Fs: mmFs} // wrap so that we're implementing ioutil
fs := &Fs{afs} fs := &Fs{afs}
if err := CopyDiskToFs(fs, dir+f.Name()+"/", "/", false); err != nil { if err := CopyDiskToFs(fs, dir+f+"/", "/", false); err != nil {
t.Errorf("copying to fs failed: %+v", err) t.Errorf("copying to fs failed: %+v", err)
return return
} }
@@ -185,11 +191,16 @@ func TestCopyDiskContentsToFs1(t *testing.T) {
t.Errorf("could not read through tests directory: %+v", err) t.Errorf("could not read through tests directory: %+v", err)
return return
} }
sorted := []string{}
for _, f := range files { for _, f := range files {
if !f.IsDir() { if !f.IsDir() {
continue continue
} }
treeFile := f.Name() + ".tree" // expected tree file sorted = append(sorted, f.Name())
}
sort.Strings(sorted)
for _, f := range sorted {
treeFile := f + ".tree" // expected tree file
treeFileFull := dir + treeFile treeFileFull := dir + treeFile
info, err := os.Stat(treeFileFull) info, err := os.Stat(treeFileFull)
if err != nil || info.IsDir() { if err != nil || info.IsDir() {
@@ -209,7 +220,7 @@ func TestCopyDiskContentsToFs1(t *testing.T) {
afs := &afero.Afero{Fs: mmFs} // wrap so that we're implementing ioutil afs := &afero.Afero{Fs: mmFs} // wrap so that we're implementing ioutil
fs := &Fs{afs} fs := &Fs{afs}
if err := CopyDiskContentsToFs(fs, dir+f.Name()+"/", "/", false); err != nil { if err := CopyDiskContentsToFs(fs, dir+f+"/", "/", false); err != nil {
t.Errorf("copying to fs failed: %+v", err) t.Errorf("copying to fs failed: %+v", err)
return return
} }