2018-23-01 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / libgo / go / testing / helperfuncs_test.go
blob7cb2e2cc56de47c4e80df38aeafad15905cbb766
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 "sync"
9 // The line numbering of this file is important for TestTBHelper.
11 func notHelper(t *T, msg string) {
12 t.Error(msg)
15 func helper(t *T, msg string) {
16 t.Helper()
17 t.Error(msg)
20 func notHelperCallingHelper(t *T, msg string) {
21 helper(t, msg)
24 func helperCallingHelper(t *T, msg string) {
25 t.Helper()
26 helper(t, msg)
29 func testHelper(t *T) {
30 // Check combinations of directly and indirectly
31 // calling helper functions.
32 notHelper(t, "0")
33 helper(t, "1")
34 notHelperCallingHelper(t, "2")
35 helperCallingHelper(t, "3")
37 // Check a function literal closing over t that uses Helper.
38 fn := func(msg string) {
39 t.Helper()
40 t.Error(msg)
42 fn("4")
44 // Check that calling Helper from inside this test entry function
45 // doesn't have an effect.
46 t.Helper()
47 t.Error("5")
49 t.Run("sub", func(t *T) {
50 helper(t, "6")
51 notHelperCallingHelper(t, "7")
52 t.Helper()
53 t.Error("8")
57 func parallelTestHelper(t *T) {
58 var wg sync.WaitGroup
59 for i := 0; i < 5; i++ {
60 wg.Add(1)
61 go func() {
62 notHelperCallingHelper(t, "parallel")
63 wg.Done()
64 }()
66 wg.Wait()