must_test.go 363 B

1234567891011121314151617181920212223242526
  1. //go:build go1.18
  2. package errors
  3. import (
  4. "testing"
  5. )
  6. func TestMust(t *testing.T) {
  7. if got := Must(10, nil); got != 10 {
  8. t.Fatalf("Expected %+v, got %+v", 10, got)
  9. }
  10. panics := func() (r bool) {
  11. defer func() {
  12. if recover() != nil {
  13. r = true
  14. }
  15. }()
  16. Must(10, New("test error"))
  17. return r
  18. }()
  19. if !panics {
  20. t.Fatal("Panic expected")
  21. }
  22. }