Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use t.Helper() in all assertion methods #36

Merged
merged 2 commits into from Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions assert/any.go
Expand Up @@ -25,6 +25,7 @@ func That(t *testing.T, actual interface{}) AssertableAny {
// IsEqualTo asserts if the expected interface is equal to the assertable value
// It errors the tests if the compared values (actual VS expected) are not equal.
func (a AssertableAny) IsEqualTo(expected interface{}) AssertableAny {
a.t.Helper()
if !a.actual.IsEqualTo(expected) {
a.t.Error(shouldBeEqual(a.actual, expected))
}
Expand All @@ -34,6 +35,7 @@ func (a AssertableAny) IsEqualTo(expected interface{}) AssertableAny {
// IsNotEqualTo asserts if the expected interface is not qual to the assertable value
// It errors the tests if the compared values (actual VS expected) are equal.
func (a AssertableAny) IsNotEqualTo(expected interface{}) AssertableAny {
a.t.Helper()
if a.actual.IsEqualTo(expected) {
a.t.Error(shouldNotBeEqual(a.actual, expected))
}
Expand All @@ -42,6 +44,7 @@ func (a AssertableAny) IsNotEqualTo(expected interface{}) AssertableAny {

// IsNil asserts if the expected value is nil.
func (a AssertableAny) IsNil() AssertableAny {
a.t.Helper()
if !a.actual.IsNil() {
a.t.Error(shouldBeNil(a.actual))
}
Expand All @@ -50,6 +53,7 @@ func (a AssertableAny) IsNil() AssertableAny {

// IsNotNil asserts if the expected value is not nil.
func (a AssertableAny) IsNotNil() AssertableAny {
a.t.Helper()
if !a.actual.IsNotNil() {
a.t.Error(shouldNotBeNil(a.actual))
}
Expand All @@ -58,18 +62,21 @@ func (a AssertableAny) IsNotNil() AssertableAny {

// IsTrue asserts if the expected value is true.
func (a AssertableAny) IsTrue() AssertableAny {
a.t.Helper()
a.IsEqualTo(true)
return a
}

// IsFalse asserts if the expected value is false.
func (a AssertableAny) IsFalse() AssertableAny {
a.t.Helper()
a.IsEqualTo(false)
return a
}

// HasTypeOf asserts if the expected value has the type of a given value.
func (a AssertableAny) HasTypeOf(t reflect.Type) AssertableAny {
a.t.Helper()
if !a.actual.HasTypeOf(t) {
a.t.Error(shouldHaveType(a.actual, t))
}
Expand Down
3 changes: 3 additions & 0 deletions assert/bool.go
Expand Up @@ -34,6 +34,7 @@ func (a AssertableBool) IsEqualTo(expected interface{}) AssertableBool {
// IsNotEqualTo asserts if the expected bool is not equal to the assertable bool value
// It errors the tests if the compared values (actual VS expected) are equal.
func (a AssertableBool) IsNotEqualTo(expected interface{}) AssertableBool {
a.t.Helper()
if a.actual.IsEqualTo(expected) {
a.t.Error(shouldNotBeEqual(a.actual, expected))
}
Expand All @@ -42,10 +43,12 @@ func (a AssertableBool) IsNotEqualTo(expected interface{}) AssertableBool {

// IsTrue asserts if the expected bool value is true.
func (a AssertableBool) IsTrue() AssertableBool {
a.t.Helper()
return a.IsEqualTo(true)
}

// IsFalse asserts if the expected bool value is false.
func (a AssertableBool) IsFalse() AssertableBool {
a.t.Helper()
return a.IsEqualTo(false)
}
4 changes: 4 additions & 0 deletions assert/duration.go
Expand Up @@ -25,6 +25,7 @@ func ThatDuration(t *testing.T, actual time.Duration) AssertableDuration {
// IsEqualTo asserts if the expected time.Duration is equal to the assertable time.Duration value
// It errors the tests if the compared values (actual VS expected) are not equal.
func (a AssertableDuration) IsEqualTo(expected time.Duration) AssertableDuration {
a.t.Helper()
if a.actual.IsNotEqualTo(expected) {
a.t.Error(shouldBeEqual(a.actual, expected))
}
Expand All @@ -34,6 +35,7 @@ func (a AssertableDuration) IsEqualTo(expected time.Duration) AssertableDuration
// IsNotEqualTo asserts if the expected time.Duration is not equal to the assertable time.Duration value
// It errors the tests if the compared values (actual VS expected) are equal.
func (a AssertableDuration) IsNotEqualTo(expected time.Duration) AssertableDuration {
a.t.Helper()
if a.actual.IsEqualTo(expected) {
a.t.Error(shouldNotBeEqual(a.actual, expected))
}
Expand All @@ -43,6 +45,7 @@ func (a AssertableDuration) IsNotEqualTo(expected time.Duration) AssertableDurat
// IsShorterThan asserts if the assertable time.Duration value is shorter than the expected value
// It errors the tests if is not shorter.
func (a AssertableDuration) IsShorterThan(expected time.Duration) AssertableDuration {
a.t.Helper()
if !a.actual.IsShorterThan(expected) {
a.t.Error(shouldBeShorter(a.actual, expected))
}
Expand All @@ -52,6 +55,7 @@ func (a AssertableDuration) IsShorterThan(expected time.Duration) AssertableDura
// IsLongerThan asserts if the assertable time.v value is longer than the expected value
// It errors the tests if is not longer.
func (a AssertableDuration) IsLongerThan(expected time.Duration) AssertableDuration {
a.t.Helper()
if !a.actual.IsLongerThan(expected) {
a.t.Error(shouldBeLonger(a.actual, expected))
}
Expand Down
4 changes: 4 additions & 0 deletions assert/error.go
Expand Up @@ -23,6 +23,7 @@ func ThatError(t *testing.T, actual error) AssertableError {

// IsNil asserts if the expected error is nil.
func (a AssertableError) IsNil() AssertableError {
a.t.Helper()
errAnyValue := values.NewAnyValue(a.actual.Value())
if errAnyValue.IsNotNil() {
a.t.Error(shouldBeNil(errAnyValue))
Expand All @@ -32,6 +33,7 @@ func (a AssertableError) IsNil() AssertableError {

// IsNotNil asserts if the expected error is nil.
func (a AssertableError) IsNotNil() AssertableError {
a.t.Helper()
errAnyValue := values.NewAnyValue(a.actual.Value())
if errAnyValue.IsNil() {
a.t.Error(shouldNotBeNil(errAnyValue))
Expand All @@ -41,6 +43,7 @@ func (a AssertableError) IsNotNil() AssertableError {

// HasExactMessage asserts if the expected error contains exactly the given message.
func (a AssertableError) HasExactMessage(expectedMessage string) AssertableError {
a.t.Helper()
errAnyValue := values.NewAnyValue(a.actual.Value())
if errAnyValue.IsNil() {
a.t.Error(shouldContain(errAnyValue, expectedMessage))
Expand All @@ -56,6 +59,7 @@ func (a AssertableError) HasExactMessage(expectedMessage string) AssertableError

// IsSameAs asserts if the expected error is the same with the given error.
func (a AssertableError) IsSameAs(err error) AssertableError {
a.t.Helper()
actualAnyValue := values.NewAnyValue(a.actual.Value())
expectedAnyValue := values.NewAnyValue(err)

Expand Down
6 changes: 6 additions & 0 deletions assert/int.go
Expand Up @@ -24,6 +24,7 @@ func ThatInt(t *testing.T, actual int) AssertableInt {
// IsEqualTo asserts if the expected int is equal to the assertable int value
// It errors the tests if the compared values (actual VS expected) are not equal.
func (a AssertableInt) IsEqualTo(expected int) AssertableInt {
a.t.Helper()
if !a.actual.IsEqualTo(expected) {
a.t.Error(shouldBeEqual(a.actual, expected))
}
Expand All @@ -33,6 +34,7 @@ func (a AssertableInt) IsEqualTo(expected int) AssertableInt {
// IsNotEqualTo asserts if the expected int is not equal to the assertable int value
// It errors the tests if the compared values (actual VS expected) are equal.
func (a AssertableInt) IsNotEqualTo(expected int) AssertableInt {
a.t.Helper()
if a.actual.IsEqualTo(expected) {
a.t.Error(shouldNotBeEqual(a.actual, expected))
}
Expand All @@ -42,6 +44,7 @@ func (a AssertableInt) IsNotEqualTo(expected int) AssertableInt {
// IsGreaterThan asserts if the assertable int value is greater than the expected value
// It errors the tests if is not greater.
func (a AssertableInt) IsGreaterThan(expected int) AssertableInt {
a.t.Helper()
if !a.actual.IsGreaterThan(expected) {
a.t.Error(shouldBeGreater(a.actual, expected))
}
Expand All @@ -51,6 +54,7 @@ func (a AssertableInt) IsGreaterThan(expected int) AssertableInt {
// IsGreaterThanOrEqualTo asserts if the assertable int value is greater than or equal to the expected value
// It errors the tests if is not greater.
func (a AssertableInt) IsGreaterThanOrEqualTo(expected int) AssertableInt {
a.t.Helper()
if !a.actual.IsGreaterOrEqualTo(expected) {
a.t.Error(shouldBeGreaterOrEqual(a.actual, expected))
}
Expand All @@ -60,6 +64,7 @@ func (a AssertableInt) IsGreaterThanOrEqualTo(expected int) AssertableInt {
// IsLessThan asserts if the assertable int value is less than the expected value
// It errors the tests if is not greater.
func (a AssertableInt) IsLessThan(expected int) AssertableInt {
a.t.Helper()
if !a.actual.IsLessThan(expected) {
a.t.Error(shouldBeLessThan(a.actual, expected))
}
Expand All @@ -69,6 +74,7 @@ func (a AssertableInt) IsLessThan(expected int) AssertableInt {
// IsLessThanOrEqualTo asserts if the assertable int value is less than or equal to the expected value
// It errors the tests if is not greater.
func (a AssertableInt) IsLessThanOrEqualTo(expected int) AssertableInt {
a.t.Helper()
if !a.actual.IsLessOrEqualTo(expected) {
a.t.Error(shouldBeLessOrEqual(a.actual, expected))
}
Expand Down
15 changes: 13 additions & 2 deletions assert/map.go
Expand Up @@ -25,6 +25,7 @@ func ThatMap(t *testing.T, actual interface{}) AssertableMap {
// IsEqualTo asserts if the expected map is equal to the assertable map value
// It errors the tests if the compared values (actual VS expected) are not equal.
func (a AssertableMap) IsEqualTo(expected interface{}) AssertableMap {
a.t.Helper()
if !values.IsMap(a.actual.Value()) {
a.t.Error(shouldBeMap(a.actual))
return a
Expand All @@ -39,6 +40,7 @@ func (a AssertableMap) IsEqualTo(expected interface{}) AssertableMap {
// IsNotEqualTo asserts if the expected map is not equal to the assertable map value
// It errors the tests if the compared values (actual VS expected) are equal.
func (a AssertableMap) IsNotEqualTo(expected interface{}) AssertableMap {
a.t.Helper()
if !values.IsMap(a.actual.Value()) {
a.t.Error(shouldBeMap(a.actual))
return a
Expand All @@ -52,6 +54,7 @@ func (a AssertableMap) IsNotEqualTo(expected interface{}) AssertableMap {
// HasSize asserts if the assertable string map has the expected length size
// It errors the test if it doesn't have the expected size.
func (a AssertableMap) HasSize(size int) AssertableMap {
a.t.Helper()
if !values.IsMap(a.actual.Value()) {
a.t.Error(shouldBeMap(a.actual))
return a
Expand All @@ -64,6 +67,7 @@ func (a AssertableMap) HasSize(size int) AssertableMap {

// IsEmpty asserts if the assertable string map is empty or not.
func (a AssertableMap) IsEmpty() AssertableMap {
a.t.Helper()
if !values.IsMap(a.actual.Value()) {
a.t.Error(shouldBeMap(a.actual))
return a
Expand All @@ -76,6 +80,7 @@ func (a AssertableMap) IsEmpty() AssertableMap {

// IsNotEmpty asserts if the assertable string map is not empty.
func (a AssertableMap) IsNotEmpty() AssertableMap {
a.t.Helper()
if !values.IsMap(a.actual.Value()) {
a.t.Error(shouldBeMap(a.actual))
return a
Expand All @@ -92,6 +97,7 @@ func (a AssertableMap) IsNotEmpty() AssertableMap {
// * the key is not comparable
// * the asserted type is not a map.
func (a AssertableMap) HasKey(elements interface{}) AssertableMap {
a.t.Helper()
if !values.IsMap(a.actual.Value()) {
a.t.Error(shouldBeMap(a.actual))
return a
Expand All @@ -108,6 +114,7 @@ func (a AssertableMap) HasKey(elements interface{}) AssertableMap {
// * the key is not comparable
// * the asserted type is not a map.
func (a AssertableMap) HasValue(elements interface{}) AssertableMap {
a.t.Helper()
if !values.IsMap(a.actual.Value()) {
a.t.Error(shouldBeMap(a.actual))
return a
Expand All @@ -120,10 +127,11 @@ func (a AssertableMap) HasValue(elements interface{}) AssertableMap {

// HasEntry asserts if the assertable map has the given entry
// It errors the test if
// * they entry can't be found
// * the entry can't be found
// * the key is not comparable
// * the asserted type is not a map.
func (a AssertableMap) HasEntry(value types.MapEntry) AssertableMap {
a.t.Helper()
if !values.IsMap(a.actual.Value()) {
a.t.Error(shouldBeMap(a.actual))
return a
Expand All @@ -140,6 +148,7 @@ func (a AssertableMap) HasEntry(value types.MapEntry) AssertableMap {
// * the key is not comparable
// * the asserted type is not a map.
func (a AssertableMap) HasNotKey(elements interface{}) AssertableMap {
a.t.Helper()
if !values.IsMap(a.actual.Value()) {
a.t.Error(shouldBeMap(a.actual))
return a
Expand All @@ -156,6 +165,7 @@ func (a AssertableMap) HasNotKey(elements interface{}) AssertableMap {
// * the key is not comparable
// * the asserted type is not a map.
func (a AssertableMap) HasNotValue(elements interface{}) AssertableMap {
a.t.Helper()
if !values.IsMap(a.actual.Value()) {
a.t.Error(shouldBeMap(a.actual))
return a
Expand All @@ -168,10 +178,11 @@ func (a AssertableMap) HasNotValue(elements interface{}) AssertableMap {

// HasNotEntry asserts if the assertable map has not the given entry
// It errors the test if
// * they entry can be found
// * the entry can be found
// * the key is not comparable
// * the asserted type is not a map.
func (a AssertableMap) HasNotEntry(value types.MapEntry) AssertableMap {
a.t.Helper()
if !values.IsMap(a.actual.Value()) {
a.t.Error(shouldBeMap(a.actual))
return a
Expand Down
8 changes: 8 additions & 0 deletions assert/slice.go
Expand Up @@ -40,6 +40,7 @@ func ThatSlice(t *testing.T, actual interface{}, opts ...SliceOpt) AssertableSli
// IsEqualTo asserts if the expected slice is equal to the assertable slice value
// It errors the tests if the compared values (actual VS expected) are not equal.
func (a AssertableSlice) IsEqualTo(expected interface{}) AssertableSlice {
a.t.Helper()
if !a.actual.IsEqualTo(expected) {
a.t.Error(shouldBeEqual(a.actual, expected))
}
Expand All @@ -49,6 +50,7 @@ func (a AssertableSlice) IsEqualTo(expected interface{}) AssertableSlice {
// IsNotEqualTo asserts if the expected slice is not equal to the assertable slice value
// It errors the tests if the compared values (actual VS expected) are equal.
func (a AssertableSlice) IsNotEqualTo(expected interface{}) AssertableSlice {
a.t.Helper()
if a.actual.IsEqualTo(expected) {
a.t.Error(shouldNotBeEqual(a.actual, expected))
}
Expand All @@ -58,6 +60,7 @@ func (a AssertableSlice) IsNotEqualTo(expected interface{}) AssertableSlice {
// HasSize asserts if the assertable string slice has the expected length size
// It errors the test if it doesn't have the expected size.
func (a AssertableSlice) HasSize(size int) AssertableSlice {
a.t.Helper()
if !a.actual.HasSize(size) {
a.t.Error(shouldHaveSize(a.actual, size))
}
Expand All @@ -66,6 +69,7 @@ func (a AssertableSlice) HasSize(size int) AssertableSlice {

// IsEmpty asserts if the assertable string slice is empty or not.
func (a AssertableSlice) IsEmpty() AssertableSlice {
a.t.Helper()
if a.actual.IsNotEmpty() {
a.t.Error(shouldBeEmpty(a.actual))
}
Expand All @@ -74,6 +78,7 @@ func (a AssertableSlice) IsEmpty() AssertableSlice {

// IsNotEmpty asserts if the assertable string slice is not empty.
func (a AssertableSlice) IsNotEmpty() AssertableSlice {
a.t.Helper()
if a.actual.IsEmpty() {
a.t.Error(shouldNotBeEmpty(a.actual))
}
Expand All @@ -83,6 +88,7 @@ func (a AssertableSlice) IsNotEmpty() AssertableSlice {
// Contains asserts if the assertable string slice contains the given element(s)
// It errors the test if it does not contain it/them.
func (a AssertableSlice) Contains(elements interface{}) AssertableSlice {
a.t.Helper()
if a.actual.DoesNotContain(elements) {
a.t.Error(shouldContain(a.actual, elements))
}
Expand All @@ -92,6 +98,7 @@ func (a AssertableSlice) Contains(elements interface{}) AssertableSlice {
// ContainsOnly asserts if the assertable string slice contains only the given element(s)
// It errors the test if it does not contain it/them.
func (a AssertableSlice) ContainsOnly(elements interface{}) AssertableSlice {
a.t.Helper()
if !a.actual.ContainsOnly(elements) {
a.t.Error(shouldContainOnly(a.actual, elements))
}
Expand All @@ -101,6 +108,7 @@ func (a AssertableSlice) ContainsOnly(elements interface{}) AssertableSlice {
// DoesNotContain asserts if the assertable string slice does not contain the given element
// It errors the test if it contains it/them.
func (a AssertableSlice) DoesNotContain(elements interface{}) AssertableSlice {
a.t.Helper()
if a.actual.Contains(elements) {
a.t.Error(shouldNotContain(a.actual, elements))
}
Expand Down