Skip to content

Commit

Permalink
fix old runtime to have error exit when in run mode
Browse files Browse the repository at this point in the history
  • Loading branch information
verdverm committed Jun 30, 2020
1 parent 1beae66 commit 7be3a43
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion script/runtime/cmd_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (ts *Script) CmdExec(neg int, args []string) {
ts.Fatalf("test timed out while running command")
} else if neg == 0 {
ts.Fatalf("unexpected exec command failure")
}
} // XXX, else we shouldn't get here?
}
}

Expand Down
2 changes: 2 additions & 0 deletions script/runtime/script_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ Script:
1. params commands, incase of overrides
2. buildin commands
3. fallback on exec ...
?. functions, sometimes they feel like they could be done this way, but we probably want to wait for a real parser and parentheses
*/

// the command name
Expand Down Expand Up @@ -171,6 +172,7 @@ Script:
// Final phase ended.
ts.rewind()
ts.markTime()

if !ts.stopped {
if ts.params.Mode == "test" {
fmt.Fprintf(&ts.log, "PASS\n")
Expand Down
24 changes: 22 additions & 2 deletions script/runtime/script_testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ func RunT(t T, p Params) {
file := file
name := strings.TrimSuffix(filepath.Base(file), ".hls")
t.Run(name, func(t T) {

t.Parallel()

ts := &Script{
t: t,
testTempDir: testTempDir,
Expand All @@ -97,6 +99,7 @@ func RunT(t T, p Params) {
scriptFiles: make(map[string]string),
scriptUpdates: make(map[string]string),
}

defer func() {
if p.TestWork || *testWork {
return
Expand All @@ -108,8 +111,17 @@ func RunT(t T, p Params) {
os.Remove(testTempDir)
}
}()

ts.run()
})

if ts.failed {
os.Exit(1)
}

// TODO, check for errors / "exit != 0""
// perhaps only when in run mode?
// (need to think about this, likely configurable with sensible defaults for test v run v shell)
})// see also cmd_exec.go:58
}
}

Expand Down Expand Up @@ -142,6 +154,14 @@ func (ts *Script) Logf(format string, args ...interface{}) {
// fatalf aborts the test with the given failure message.
func (ts *Script) Fatalf(format string, args ...interface{}) {
fmt.Fprintf(&ts.log, "FAIL: %s:%d: %s\n", ts.file, ts.lineno, fmt.Sprintf(format, args...))
ts.t.FailNow()

if ts.params.Mode == "run" {
ts.stopped = true
ts.failed = true
}

if ts.params.Mode == "test" {
ts.t.FailNow()
}
}

1 change: 1 addition & 0 deletions script/runtime/script_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Script struct {
stderr string // standard error from last 'go' command; for 'stderr' command
status int // status code from exec or http

failed bool // test wants to stop early with failed state
stopped bool // test wants to stop early
start time.Time // time phase started

Expand Down

0 comments on commit 7be3a43

Please sign in to comment.