gotest.tools/gotestsum@v1.11.0/testjson/internal/withfails/fails_test.go (about) 1 // +build stubpkg 2 3 /*Package withfails is used to generate testdata for the testjson package. 4 */ 5 package withfails 6 7 import ( 8 "fmt" 9 "os" 10 "strings" 11 "testing" 12 "time" 13 ) 14 15 func TestPassed(t *testing.T) {} 16 17 func TestPassedWithLog(t *testing.T) { 18 t.Log("this is a log") 19 } 20 21 func TestPassedWithStdout(t *testing.T) { 22 fmt.Println("this is a Print") 23 } 24 25 func TestSkipped(t *testing.T) { 26 t.Skip() 27 } 28 29 func TestSkippedWitLog(t *testing.T) { 30 t.Skip("the skip message") 31 } 32 33 func TestFailed(t *testing.T) { 34 t.Fatal("this failed") 35 } 36 37 func TestWithStderr(t *testing.T) { 38 fmt.Fprintln(os.Stderr, "this is stderr") 39 } 40 41 func TestFailedWithStderr(t *testing.T) { 42 fmt.Fprintln(os.Stderr, "this is stderr") 43 t.Fatal("also failed") 44 } 45 46 func TestParallelTheFirst(t *testing.T) { 47 t.Parallel() 48 time.Sleep(10 * time.Millisecond) 49 } 50 51 func TestParallelTheSecond(t *testing.T) { 52 t.Parallel() 53 time.Sleep(6 * time.Millisecond) 54 } 55 56 func TestParallelTheThird(t *testing.T) { 57 t.Parallel() 58 time.Sleep(2 * time.Millisecond) 59 } 60 61 func TestNestedWithFailure(t *testing.T) { 62 for _, name := range []string{"a", "b", "c", "d"} { 63 t.Run(name, func(t *testing.T) { 64 if strings.HasSuffix(t.Name(), "c") { 65 t.Fatal("failed") 66 } 67 t.Run("sub", func(t *testing.T) {}) 68 }) 69 } 70 } 71 72 func TestNestedSuccess(t *testing.T) { 73 for _, name := range []string{"a", "b", "c", "d"} { 74 t.Run(name, func(t *testing.T) { 75 t.Run("sub", func(t *testing.T) {}) 76 }) 77 } 78 }