From 0fcb7ecc3daf709147256a45c1d1cbf670e12df2 Mon Sep 17 00:00:00 2001 From: Grant Nelson Date: Fri, 19 Apr 2024 12:34:28 -0600 Subject: [PATCH] Update test run example native override --- compiler/natives/src/testing/example.go | 30 +++++-------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/compiler/natives/src/testing/example.go b/compiler/natives/src/testing/example.go index bf8d06482..b80ae2e99 100644 --- a/compiler/natives/src/testing/example.go +++ b/compiler/natives/src/testing/example.go @@ -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) } @@ -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() @@ -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 }