getError_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package gatecode
  2. import (
  3. "errors"
  4. "fmt"
  5. "github.com/gogf/gf/v2/errors/gcode"
  6. "github.com/gogf/gf/v2/errors/gerror"
  7. "runtime"
  8. "strings"
  9. "testing"
  10. )
  11. func TestGError(t *testing.T) {
  12. err := errors.New("1")
  13. err = gerror.Wrap(err, "2")
  14. err = gerror.Wrap(err, "3")
  15. t.Log(err, nil)
  16. t.Log(fmt.Sprintf("%s", err), "3: 2: 1")
  17. t.Log(fmt.Sprintf("%v", err), "3: 2: 1")
  18. }
  19. func TestGCode(t *testing.T) {
  20. err1 := errors.New("permission denied")
  21. err2 := gerror.WrapCode(gcode.New(10000, "aaaa", nil), err1, "Custom Error")
  22. fmt.Println(err2.Error())
  23. fmt.Println(gerror.Code(err2))
  24. err3 := gerror.Wrap(err2, "sss")
  25. fmt.Println(err3)
  26. }
  27. func TestGErr(t *testing.T) {
  28. err := errors.New("permission denied")
  29. c := gerror.Code(err)
  30. t.Log(c == gcode.CodeNil)
  31. t.Log("www", c.Detail())
  32. cc := gerror.Stack(err)
  33. t.Log(cc)
  34. ccc := gerror.Code(nil)
  35. t.Log(ccc.Detail())
  36. }
  37. func TestErrorCodeIncrease(t *testing.T) {
  38. c1 := getErrCode(1000)
  39. c2 := getErrCode(2000)
  40. for i := 0; i < 10; i++ {
  41. fmt.Println(c1())
  42. }
  43. for i := 0; i < 10; i++ {
  44. fmt.Println(c2())
  45. }
  46. }
  47. func TestErrCode(t *testing.T) {
  48. fmt.Println(runtime.Version())
  49. fmt.Println("GLOBAL_ERR_NIL =>", GLOBAL_ERR_NIL, int(GLOBAL_ERR_NIL), GLOBAL_ERR_NIL.String())
  50. }
  51. func TestName(t *testing.T) {
  52. t.Log(demo())
  53. }
  54. func demo(e ...string) string {
  55. return strings.Join(e, ",")
  56. }