Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions ztest/ztest.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@
//
// Tests of either style can be skipped by setting the skip field to a non-empty
// string. A message containing the string will be written to the test log.
//
// Environment variables:
//
// ZTEST_PATH - Path to super executable for script tests
// ZTEST_TAG - Only run tests with matching tag
// ZTEST_VECTOR - Override "vector:" setting in YAML (true/false)
package ztest

import (
Expand Down Expand Up @@ -151,6 +157,22 @@ func ShellPath() string {
return os.Getenv("ZTEST_PATH")
}

// VectorOverride returns the vector override setting from the ZTEST_VECTOR
// environment variable. It returns:
// - (true, true) if ZTEST_VECTOR=true
// - (false, true) if ZTEST_VECTOR=false
// - (false, false) if ZTEST_VECTOR is unset or invalid
func VectorOverride() (bool, bool) {
switch strings.ToLower(os.Getenv("ZTEST_VECTOR")) {
case "true", "1", "yes":
return true, true
case "false", "0", "no":
return false, true
default:
return false, false
}
}

type Bundle struct {
FileName string
Test *ZTest
Expand Down Expand Up @@ -344,14 +366,23 @@ func (z *ZTest) ShouldSkip(path string) string {
return ""
}

// effectiveVector returns the effective vector setting for this test,
// taking into account any ZTEST_VECTOR environment variable override.
func (z *ZTest) effectiveVector() bool {
if value, ok := VectorOverride(); ok {
return value
}
return z.Vector
}

func (z *ZTest) RunScript(ctx context.Context, shellPath, testDir string, tempDir func() string) error {
if err := z.check(); err != nil {
return fmt.Errorf("bad yaml format: %w", err)
}
serr := runsh(ctx, shellPath, testDir, tempDir(), z)
if !z.Vector {
return serr
if !z.effectiveVector() {
return runsh(ctx, shellPath, testDir, tempDir(), z)
}
serr := runsh(ctx, shellPath, testDir, tempDir(), z)
if serr != nil {
serr = fmt.Errorf("=== sequence ===\n%w", serr)
}
Expand All @@ -368,7 +399,7 @@ func (z *ZTest) RunInternal(ctx context.Context) error {
}
outputFlags := append([]string{"-f=sup", "-pretty=0"}, strings.Fields(z.OutputFlags)...)
inputFlags := strings.Fields(z.InputFlags)
if z.Vector {
if z.effectiveVector() {
verr := z.diffInternal(runInternal(ctx, z.SPQ, z.Input, outputFlags, inputFlags, true))
if verr != nil {
verr = fmt.Errorf("=== vector ===\n%w", verr)
Expand Down