Skip to content

Commit

Permalink
support multiple expected outputs per input
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Mitchell <[email protected]>
  • Loading branch information
starpit committed Dec 1, 2024
1 parent 95fc592 commit d2b9e5f
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 12 deletions.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions demos/data-prep-kit/universal/resize/env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
max_rows_per_table: 125
6 changes: 6 additions & 0 deletions pkg/boot/bat.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ func (t BuildAndTester) RunDir(ctx context.Context, group *errgroup.Group, dir,

// Run one build&test for the application specified in `sourcePath`, storing the build in `binaryFullPath`
func (t BuildAndTester) Run(ctx context.Context, sourcePath, binaryRelPath, binaryFullPath string) error {
select {
case <-ctx.Done():
return nil
default:
}

binaryName := filepath.Base(binaryFullPath)

if err := builder.Build(
Expand Down
5 changes: 4 additions & 1 deletion pkg/boot/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ func (t Tester) prepareInputs(testData hlir.TestData, stageDir string) (inputs [
expectedDir := build.TestDataDirForExpected(stageDir)
for _, test := range testData {
inputs = append(inputs, filepath.Join(inputDir, test.Input))
outputs = append(outputs, filepath.Join(expectedDir, test.Expected))

for _, expected := range test.Expected {
outputs = append(outputs, filepath.Join(expectedDir, expected))
}
}

if t.Options.Verbose() {
Expand Down
23 changes: 15 additions & 8 deletions pkg/fe/builder/overlay/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"regexp"
"runtime"
"slices"
"strconv"
"strings"

"github.com/dustin/go-humanize/english"
Expand Down Expand Up @@ -274,21 +275,27 @@ func (b filesystemBuilder) addTestData(spec *hlir.Spec, sourcePath, templatePath
// Hmm, check if it exists with a .gz extension
output = filepath.Join(expectedDir, input.Name()+".gz")
if _, err := os.Stat(output); err != nil {
// Hmm, check if it exists with an _0 extension
// Hmm, check if it exists with _0, _1, ... extensions
idx := strings.Index(input.Name(), ".")
output = ""
if idx >= 0 {
output = filepath.Join(expectedDir, input.Name()[:idx]+"_0"+input.Name()[idx:])
if _, err := os.Stat(output); err != nil {
output = ""
outputNum := 0
for {
output = filepath.Join(expectedDir, input.Name()[:idx]+"_"+strconv.Itoa(outputNum)+input.Name()[idx:])
if _, err := os.Stat(output); err != nil {
break
}
test.Expected = append(test.Expected, filepath.Base(output))
outputNum++
}
}
} else {
test.Expected = []string{filepath.Base(output)}
}
} else {
test.Expected = []string{filepath.Base(output)}
}

if output != "" {
test.Expected = filepath.Base(output)
} else {
if len(test.Expected) == 0 {
// Then the application does not provided expected output
fmt.Fprintf(os.Stderr, "%s Warning: expected output not provided for %s\n", colors.Yellow.Render(b.appname), input.Name())
}
Expand Down
8 changes: 5 additions & 3 deletions pkg/ir/hlir/testdata.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package hlir

type TestDatum struct {
Name string
Input string
Expected string
Name string
Input string

// Each Input may provide 0 or more Expected outputs, hence the array
Expected []string
}

type TestData = []TestDatum

0 comments on commit d2b9e5f

Please sign in to comment.