tvx runner: exec: add support for multiple-level dirs.

This commit is contained in:
Raúl Kripalani 2022-01-04 17:42:24 +00:00
parent 572114b8ba
commit 75d8c52004

View File

@ -5,6 +5,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/fs"
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
@ -136,25 +137,31 @@ func processTipsetOpts() error {
} }
func execVectorDir(path string, outdir string) error { func execVectorDir(path string, outdir string) error {
files, err := filepath.Glob(filepath.Join(path, "*")) return filepath.WalkDir(path, func(path string, d fs.DirEntry, err error) error {
if err != nil { if err != nil {
return fmt.Errorf("failed to glob input directory %s: %w", path, err) return fmt.Errorf("failed while visiting path %s: %w", path, err)
} }
for _, f := range files { if d.IsDir() || !strings.HasSuffix(path, "json") {
outfile := strings.TrimSuffix(filepath.Base(f), filepath.Ext(f)) + ".out" return nil
}
// Create an output file to capture the output from the run of the vector.
outfile := strings.TrimSuffix(filepath.Base(path), filepath.Ext(path)) + ".out"
outpath := filepath.Join(outdir, outfile) outpath := filepath.Join(outdir, outfile)
outw, err := os.Create(outpath) outw, err := os.Create(outpath)
if err != nil { if err != nil {
return fmt.Errorf("failed to create file %s: %w", outpath, err) return fmt.Errorf("failed to create file %s: %w", outpath, err)
} }
log.Printf("processing vector %s; sending output to %s", f, outpath) log.Printf("processing vector %s; sending output to %s", path, outpath)
// Actually run the vector.
log.SetOutput(io.MultiWriter(os.Stderr, outw)) // tee the output. log.SetOutput(io.MultiWriter(os.Stderr, outw)) // tee the output.
_, _ = execVectorFile(new(conformance.LogReporter), f) _, _ = execVectorFile(new(conformance.LogReporter), path)
log.SetOutput(os.Stderr) log.SetOutput(os.Stderr)
_ = outw.Close() _ = outw.Close()
}
return nil return nil
})
} }
func execVectorsStdin() error { func execVectorsStdin() error {