From 75d8c5200483df82e6914458c20b5183a870c169 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Kripalani?= Date: Tue, 4 Jan 2022 17:42:24 +0000 Subject: [PATCH] tvx runner: exec: add support for multiple-level dirs. --- cmd/tvx/exec.go | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/cmd/tvx/exec.go b/cmd/tvx/exec.go index 15bb543a5..750684c36 100644 --- a/cmd/tvx/exec.go +++ b/cmd/tvx/exec.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "io" + "io/fs" "log" "os" "path/filepath" @@ -136,25 +137,31 @@ func processTipsetOpts() error { } func execVectorDir(path string, outdir string) error { - files, err := filepath.Glob(filepath.Join(path, "*")) - if err != nil { - return fmt.Errorf("failed to glob input directory %s: %w", path, err) - } - for _, f := range files { - outfile := strings.TrimSuffix(filepath.Base(f), filepath.Ext(f)) + ".out" + return filepath.WalkDir(path, func(path string, d fs.DirEntry, err error) error { + if err != nil { + return fmt.Errorf("failed while visiting path %s: %w", path, err) + } + if d.IsDir() || !strings.HasSuffix(path, "json") { + 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) outw, err := os.Create(outpath) if err != nil { 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. - _, _ = execVectorFile(new(conformance.LogReporter), f) + _, _ = execVectorFile(new(conformance.LogReporter), path) log.SetOutput(os.Stderr) _ = outw.Close() - } - return nil + + return nil + }) } func execVectorsStdin() error {