fstest/test_all: fix directories that tests are run in

- Don't build a binary for backend tests
- Run tests in their relevant directories
This commit is contained in:
Nick Craig-Wood 2018-10-23 17:31:11 +01:00
parent fe61cff079
commit 5c32b32011
4 changed files with 24 additions and 17 deletions

View File

@ -18,6 +18,7 @@ type Test struct {
FastList bool // if it is possible to add -fast-list to tests
AddBackend bool // set if Path needs the current backend appending
NoRetries bool // set if no retries should be performed
NoBinary bool // set to not build a binary in advance
}
// Backend describes a backend test
@ -54,6 +55,7 @@ func (b *Backend) MakeRuns(t *Test) (runs []*Run) {
FastList: fastlist,
NoRetries: t.NoRetries,
OneOnly: b.OneOnly,
NoBinary: t.NoBinary,
}
if t.AddBackend {
run.Path = path.Join(run.Path, b.Backend)

View File

@ -1,7 +1,8 @@
tests:
- path: backend
addbackend: true
noretries: true
addbackend: true
noretries: true
nobinary: true
- path: fs/operations
subdir: true
fastlist: true

View File

@ -41,6 +41,7 @@ type Run struct {
FastList bool // add -fast-list to tests
NoRetries bool // don't retry if set
OneOnly bool // only run test for this backend at once
NoBinary bool // set to not build a binary
// Internals
cmdLine []string
cmdString string
@ -179,6 +180,7 @@ func (r *Run) trial() {
cmd := exec.Command(cmdLine[0], cmdLine[1:]...)
cmd.Stderr = multiOut
cmd.Stdout = multiOut
cmd.Dir = r.Path
start := time.Now()
r.err = cmd.Run()
r.output = b.Bytes()
@ -226,25 +228,19 @@ func (r *Run) PackagePath() string {
return path.Join(GOPATH(), "src", r.Path)
}
// Chdir into the package directory
func (r *Run) Chdir() {
err := os.Chdir(r.PackagePath())
if err != nil {
log.Fatalf("Failed to chdir to package %q: %v", r.Path, err)
}
}
// MakeTestBinary makes the binary we will run
func (r *Run) MakeTestBinary() {
binary := r.BinaryPath()
binaryName := r.BinaryName()
log.Printf("%s: Making test binary %q", r.Path, binaryName)
cmdLine := []string{"go", "test", "-c", "-o", binary, testBase + r.Path}
cmdLine := []string{"go", "test", "-c"}
if *dryRun {
log.Printf("Not executing: %v", cmdLine)
return
}
err := exec.Command(cmdLine[0], cmdLine[1:]...).Run()
cmd := exec.Command(cmdLine[0], cmdLine[1:]...)
cmd.Dir = r.Path
err := cmd.Run()
if err != nil {
log.Fatalf("Failed to make test binary: %v", err)
}
@ -286,15 +282,21 @@ func (r *Run) Name() string {
// Init the Run
func (r *Run) Init() {
binary := r.BinaryPath()
r.cmdLine = []string{binary, "-test.v", "-test.timeout", timeout.String(), "-remote", r.Remote}
prefix := "-test."
if r.NoBinary {
prefix = "-"
r.cmdLine = []string{"go", "test"}
} else {
r.cmdLine = []string{"./" + r.BinaryName()}
}
r.cmdLine = append(r.cmdLine, prefix+"v", prefix+"timeout", timeout.String(), "-remote", r.Remote)
r.try = 1
if *verbose {
r.cmdLine = append(r.cmdLine, "-verbose")
fs.Config.LogLevel = fs.LogLevelDebug
}
if *runOnly != "" {
r.cmdLine = append(r.cmdLine, "-test.run", *runOnly)
r.cmdLine = append(r.cmdLine, prefix+"run", *runOnly)
}
if r.SubDir {
r.cmdLine = append(r.cmdLine, "-subdir")

View File

@ -109,8 +109,10 @@ func main() {
for _, run := range runs {
if _, found := done[run.Path]; !found {
done[run.Path] = struct{}{}
run.MakeTestBinary()
defer run.RemoveTestBinary()
if !run.NoBinary {
run.MakeTestBinary()
defer run.RemoveTestBinary()
}
}
}