github.com/aristanetworks/goarista@v0.0.0-20240514173732-cca2755bbd44/test/panic_test.go (about)

     1  // Copyright (c) 2015 Arista Networks, Inc.
     2  // Use of this source code is governed by the Apache License 2.0
     3  // that can be found in the COPYING file.
     4  
     5  package test
     6  
     7  import (
     8  	"errors"
     9  	"testing"
    10  )
    11  
    12  func TestShouldPanic(t *testing.T) {
    13  	ShouldPanic(t, func() { panic("Here we are") })
    14  
    15  	ShouldPanicWith(t, "Here we are", func() { panic("Here we are") })
    16  	ShouldPanicWith(t, 42, func() { panic(42) })
    17  	ShouldPanicWith(t, struct{ foo string }{foo: "panic"},
    18  		func() { panic(struct{ foo string }{foo: "panic"}) })
    19  
    20  	ShouldPanicWithStr(t, "foo", func() { panic("foo") })
    21  	ShouldPanicWithStr(t, "foo", func() { panic(errors.New("foo")) })
    22  }