PR ada/81103
[official-gcc.git] / libgo / go / testing / helper_test.go
blobf5cb27c317bbc9d566a34780364daac608890ba3
1 // Copyright 2017 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 package testing
7 import (
8 "bytes"
9 "regexp"
10 "strings"
13 func TestTBHelper(t *T) {
14 var buf bytes.Buffer
15 ctx := newTestContext(1, newMatcher(regexp.MatchString, "", ""))
16 t1 := &T{
17 common: common{
18 signal: make(chan bool),
19 w: &buf,
21 context: ctx,
23 t1.Run("Test", testHelper)
25 want := `--- FAIL: Test (?s)
26 helperfuncs_test.go:12: 0
27 helperfuncs_test.go:33: 1
28 helperfuncs_test.go:21: 2
29 helperfuncs_test.go:35: 3
30 helperfuncs_test.go:42: 4
31 helperfuncs_test.go:47: 5
32 --- FAIL: Test/sub (?s)
33 helperfuncs_test.go:50: 6
34 helperfuncs_test.go:21: 7
35 helperfuncs_test.go:53: 8
37 lines := strings.Split(buf.String(), "\n")
38 durationRE := regexp.MustCompile(`\(.*\)$`)
39 for i, line := range lines {
40 line = strings.TrimSpace(line)
41 line = durationRE.ReplaceAllString(line, "(?s)")
42 lines[i] = line
44 got := strings.Join(lines, "\n")
45 if got != want {
46 t.Errorf("got output:\n\n%s\nwant:\n\n%s", got, want)
50 func TestTBHelperParallel(t *T) {
51 var buf bytes.Buffer
52 ctx := newTestContext(1, newMatcher(regexp.MatchString, "", ""))
53 t1 := &T{
54 common: common{
55 signal: make(chan bool),
56 w: &buf,
58 context: ctx,
60 t1.Run("Test", parallelTestHelper)
62 lines := strings.Split(strings.TrimSpace(buf.String()), "\n")
63 if len(lines) != 6 {
64 t.Fatalf("parallelTestHelper gave %d lines of output; want 6", len(lines))
66 want := "helperfuncs_test.go:21: parallel"
67 if got := strings.TrimSpace(lines[1]); got != want {
68 t.Errorf("got output line %q; want %q", got, want)