Skip to content

[go1.20] Update test run example native override #1296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2024
Merged
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
30 changes: 5 additions & 25 deletions compiler/natives/src/testing/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ package testing
import (
"fmt"
"os"
"strings"
"time"
)

func runExample(eg InternalExample) (ok bool) {
if *chatty {
if chatty.on {
fmt.Printf("=== RUN %s\n", eg.Name)
}

Expand All @@ -24,12 +23,12 @@ func runExample(eg InternalExample) (ok bool) {
}
os.Stdout = w

finished := false
start := time.Now()
ok = true

// Clean up in a deferred call so we can recover if the example panics.
defer func() {
dstr := fmtDuration(time.Now().Sub(start))
timeSpent := time.Since(start)

// Close file, restore stdout, get output.
w.Close()
Expand All @@ -41,31 +40,12 @@ func runExample(eg InternalExample) (ok bool) {
os.Exit(1)
}

var fail string
err := recover()
got := strings.TrimSpace(string(out))
want := strings.TrimSpace(eg.Output)
if eg.Unordered {
if sortLines(got) != sortLines(want) && err == nil {
fail = fmt.Sprintf("got:\n%s\nwant (unordered):\n%s\n", string(out), eg.Output)
}
} else {
if got != want && err == nil {
fail = fmt.Sprintf("got:\n%s\nwant:\n%s\n", got, want)
}
}
if fail != "" || err != nil {
fmt.Printf("--- FAIL: %s (%s)\n%s", eg.Name, dstr, fail)
ok = false
} else if *chatty {
fmt.Printf("--- PASS: %s (%s)\n", eg.Name, dstr)
}
if err != nil {
panic(err)
}
ok = eg.processRunResult(string(out), timeSpent, finished, err)
}()

// Run example.
eg.F()
finished = true
return
}
Loading