-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yangyile
committed
Dec 17, 2024
1 parent
aacef44
commit 01f26e8
Showing
9 changed files
with
104 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,52 @@ | ||
package erero | ||
package erero_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/stretchr/testify/require" | ||
"github.com/yyle88/erero" | ||
) | ||
|
||
func TestEro(t *testing.T) { | ||
require.Error(t, Ero(errors.New("abc"))) | ||
require.Error(t, erero.Ero(errors.New("abc"))) | ||
} | ||
|
||
func TestNew(t *testing.T) { | ||
require.Error(t, New("wrong")) | ||
require.Error(t, erero.New("wrong")) | ||
} | ||
|
||
func TestIse(t *testing.T) { | ||
var erx = errors.New("wrong") | ||
|
||
//当错误匹配时,就打印调试日志 | ||
require.True(t, Ise(erx, erx)) | ||
require.True(t, erero.Ise(erx, erx)) | ||
//当错误不匹配,就打印错误日志 | ||
require.False(t, Ise(erx, errors.New("wrong"))) | ||
require.False(t, erero.Ise(erx, errors.New("wrong"))) | ||
} | ||
|
||
func TestWro(t *testing.T) { | ||
erx := errors.New("abc") | ||
require.Error(t, WithMessage(erx, "wrong")) | ||
require.Error(t, Wro(erx)) //和前一行等效,能稍微省点代码 | ||
require.Error(t, erero.WithMessage(erx, "wrong")) | ||
require.Error(t, erero.Wro(erx)) //和前一行等效,能稍微省点代码 | ||
} | ||
|
||
func TestWithMessage(t *testing.T) { | ||
erx := errors.New("abc") | ||
require.Error(t, erero.WithMessage(erx, "wrong")) | ||
} | ||
|
||
func TestWithMessagef(t *testing.T) { | ||
erx := errors.New("abc") | ||
require.Error(t, erero.WithMessagef(erx, "wrong reason=%s", "reason")) | ||
} | ||
|
||
func TestWrap(t *testing.T) { | ||
erx := errors.New("abc") | ||
require.Error(t, erero.Wrap(erx, "wrong")) | ||
} | ||
|
||
func TestWrapf(t *testing.T) { | ||
erx := errors.New("abc") | ||
require.Error(t, erero.Wrapf(erx, "wrong reason=%s", "reason")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters