From b79c94617cb0966c0bff6aa576652c7b9fa893af Mon Sep 17 00:00:00 2001 From: Patroklos Papapetrou Date: Mon, 18 Oct 2021 11:16:51 +0300 Subject: [PATCH] use t.Helper() in all assertion methods --- assert/any.go | 7 +++++++ assert/bool.go | 4 ++++ assert/duration.go | 4 ++++ assert/error.go | 4 ++++ assert/int.go | 6 ++++++ assert/map.go | 15 +++++++++++++-- assert/slice.go | 8 ++++++++ assert/string.go | 22 ++++++++++++++++++++++ assert/structs.go | 2 ++ assert/time.go | 7 +++++++ 10 files changed, 77 insertions(+), 2 deletions(-) diff --git a/assert/any.go b/assert/any.go index 43d2a90..35569ea 100644 --- a/assert/any.go +++ b/assert/any.go @@ -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)) } @@ -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)) } @@ -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)) } @@ -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)) } @@ -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)) } diff --git a/assert/bool.go b/assert/bool.go index a1bfdd3..d4e71f7 100644 --- a/assert/bool.go +++ b/assert/bool.go @@ -24,6 +24,7 @@ func ThatBool(t *testing.T, actual bool) AssertableBool { // IsEqualTo asserts if the expected bool is equal to the assertable bool value // It errors the tests if the compared values (actual VS expected) are not equal. func (a AssertableBool) IsEqualTo(expected interface{}) AssertableBool { + a.t.Helper() if !a.actual.IsEqualTo(expected) { a.t.Error(shouldBeEqual(a.actual, expected)) } @@ -33,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)) } @@ -41,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) } diff --git a/assert/duration.go b/assert/duration.go index d314364..504ae39 100644 --- a/assert/duration.go +++ b/assert/duration.go @@ -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)) } @@ -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)) } @@ -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)) } @@ -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)) } diff --git a/assert/error.go b/assert/error.go index 780ad9f..dbcb27f 100644 --- a/assert/error.go +++ b/assert/error.go @@ -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)) @@ -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)) @@ -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)) @@ -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) diff --git a/assert/int.go b/assert/int.go index 58e0ceb..57e578e 100644 --- a/assert/int.go +++ b/assert/int.go @@ -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)) } @@ -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)) } @@ -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)) } @@ -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)) } @@ -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)) } @@ -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)) } diff --git a/assert/map.go b/assert/map.go index 8da2f5a..b953bfb 100644 --- a/assert/map.go +++ b/assert/map.go @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/assert/slice.go b/assert/slice.go index da97325..28aae2d 100644 --- a/assert/slice.go +++ b/assert/slice.go @@ -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)) } @@ -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)) } @@ -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)) } @@ -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)) } @@ -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)) } @@ -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)) } @@ -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)) } @@ -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)) } diff --git a/assert/string.go b/assert/string.go index 1246d46..7403bfc 100644 --- a/assert/string.go +++ b/assert/string.go @@ -48,6 +48,7 @@ func ThatString(t *testing.T, actual string, opts ...StringOpt) AssertableString // IsEqualTo asserts if the expected string is equal to the assertable string value // It errors the tests if the compared values (actual VS expected) are not equal. func (a AssertableString) IsEqualTo(expected interface{}) AssertableString { + a.t.Helper() if !a.actual.IsEqualTo(expected) { a.t.Error(shouldBeEqual(a.actual, expected)) } @@ -57,6 +58,7 @@ func (a AssertableString) IsEqualTo(expected interface{}) AssertableString { // IsNotEqualTo asserts if the expected string is not equal to the assertable string value // It errors the tests if the compared values (actual VS expected) are equal. func (a AssertableString) IsNotEqualTo(expected interface{}) AssertableString { + a.t.Helper() if a.actual.IsEqualTo(expected) { a.t.Error(shouldNotBeEqual(a.actual, expected)) } @@ -66,6 +68,7 @@ func (a AssertableString) IsNotEqualTo(expected interface{}) AssertableString { // IsEmpty asserts if the expected string is empty // It errors the tests if the string is not empty. func (a AssertableString) IsEmpty() AssertableString { + a.t.Helper() if a.actual.IsNotEmpty() { a.t.Error(shouldBeEmpty(a.actual)) } @@ -75,6 +78,7 @@ func (a AssertableString) IsEmpty() AssertableString { // IsLowerCase asserts if the expected string is lower case // It errors the tests if the string is not lower case. func (a AssertableString) IsLowerCase() AssertableString { + a.t.Helper() if !a.actual.IsLowerCase() { a.t.Error(shouldBeLowerCase(a.actual)) } @@ -84,6 +88,7 @@ func (a AssertableString) IsLowerCase() AssertableString { // IsUpperCase asserts if the expected string is upper case // It errors the tests if the string is not upper case. func (a AssertableString) IsUpperCase() AssertableString { + a.t.Helper() if !a.actual.IsUpperCase() { a.t.Error(shouldBeUpperCase(a.actual)) } @@ -93,6 +98,7 @@ func (a AssertableString) IsUpperCase() AssertableString { // IsNotEmpty asserts if the expected string is not empty // It errors the tests if the string is empty. func (a AssertableString) IsNotEmpty() AssertableString { + a.t.Helper() if a.actual.IsEmpty() { a.t.Error(shouldNotBeEmpty(a.actual)) } @@ -102,6 +108,7 @@ func (a AssertableString) IsNotEmpty() AssertableString { // Contains asserts if the assertable string contains the given element(s) // It errors the test if it does not contain it. func (a AssertableString) Contains(substring string) AssertableString { + a.t.Helper() if a.actual.DoesNotContain(substring) { a.t.Error(shouldContain(a.actual, substring)) } @@ -111,6 +118,7 @@ func (a AssertableString) Contains(substring string) AssertableString { // ContainsIgnoringCase asserts if the assertable string contains the given element(s) case insensitively // It errors the test if it does not contain it. func (a AssertableString) ContainsIgnoringCase(substring string) AssertableString { + a.t.Helper() if !a.actual.ContainsIgnoringCase(substring) { a.t.Error(shouldContainIgnoringCase(a.actual, substring)) } @@ -120,6 +128,7 @@ func (a AssertableString) ContainsIgnoringCase(substring string) AssertableStrin // ContainsOnly asserts if the assertable string only contains the given substring // It errors the test if it does not contain it. func (a AssertableString) ContainsOnly(substring string) AssertableString { + a.t.Helper() if !a.actual.ContainsOnly(substring) { a.t.Error(shouldContainOnly(a.actual, substring)) } @@ -129,6 +138,7 @@ func (a AssertableString) ContainsOnly(substring string) AssertableString { // ContainsOnlyOnce asserts if the assertable string contains the given substring only once // It errors the test if it does not contain it or contains more than once. func (a AssertableString) ContainsOnlyOnce(substring string) AssertableString { + a.t.Helper() if !a.actual.ContainsOnlyOnce(substring) { a.t.Error(shouldContainOnlyOnce(a.actual, substring)) } @@ -138,6 +148,7 @@ func (a AssertableString) ContainsOnlyOnce(substring string) AssertableString { // ContainsWhitespaces asserts if the assertable string contains at least one whitespace // It errors the test if it does not contain any. func (a AssertableString) ContainsWhitespaces() AssertableString { + a.t.Helper() if !a.actual.ContainsWhitespaces() { a.t.Error(shouldContainWhiteSpace(a.actual)) } @@ -147,6 +158,7 @@ func (a AssertableString) ContainsWhitespaces() AssertableString { // DoesNotContainAnyWhitespaces asserts if the assertable string contains no whitespace // It errors the test if it does contain any. func (a AssertableString) DoesNotContainAnyWhitespaces() AssertableString { + a.t.Helper() if a.actual.ContainsWhitespaces() { a.t.Error(shouldNotContainAnyWhiteSpace(a.actual)) } @@ -156,6 +168,7 @@ func (a AssertableString) DoesNotContainAnyWhitespaces() AssertableString { // ContainsOnlyWhitespaces asserts if the assertable string contains only whitespaces // It errors the test if it contains any other character. func (a AssertableString) ContainsOnlyWhitespaces() AssertableString { + a.t.Helper() if !a.actual.ContainsOnlyWhitespaces() { a.t.Error(shouldContainOnlyWhiteSpaces(a.actual)) } @@ -165,6 +178,7 @@ func (a AssertableString) ContainsOnlyWhitespaces() AssertableString { // DoesNotContainOnlyWhitespaces asserts if the assertable string does not contain only whitespaces // It errors the test if it contains only whitespaces. func (a AssertableString) DoesNotContainOnlyWhitespaces() AssertableString { + a.t.Helper() if a.actual.ContainsOnlyWhitespaces() { a.t.Error(shouldNotContainOnlyWhiteSpaces(a.actual)) } @@ -174,6 +188,7 @@ func (a AssertableString) DoesNotContainOnlyWhitespaces() AssertableString { // DoesNotContain asserts if the assertable string does not contain the given substring // It errors the test if it contains it. func (a AssertableString) DoesNotContain(substring string) AssertableString { + a.t.Helper() if a.actual.Contains(substring) { a.t.Error(shouldNotContain(a.actual, substring)) } @@ -183,6 +198,7 @@ func (a AssertableString) DoesNotContain(substring string) AssertableString { // StartsWith asserts if the assertable string starts with the given substring // It errors the test if it doesn't start with the given substring. func (a AssertableString) StartsWith(substring string) AssertableString { + a.t.Helper() if !a.actual.StartsWith(substring) { a.t.Error(shouldStartWith(a.actual, substring)) } @@ -192,6 +208,7 @@ func (a AssertableString) StartsWith(substring string) AssertableString { // DoesNotStartWith asserts if the assertable string doesn't start with the given substring // It errors the test if it starts with the given substring. func (a AssertableString) DoesNotStartWith(substring string) AssertableString { + a.t.Helper() if a.actual.StartsWith(substring) { a.t.Error(shouldNotStartWith(a.actual, substring)) } @@ -201,6 +218,7 @@ func (a AssertableString) DoesNotStartWith(substring string) AssertableString { // EndsWith asserts if the assertable string ends with the given substring // It errors the test if it doesn't end with the given substring. func (a AssertableString) EndsWith(substring string) AssertableString { + a.t.Helper() if !a.actual.EndsWith(substring) { a.t.Error(shouldEndWith(a.actual, substring)) } @@ -210,6 +228,7 @@ func (a AssertableString) EndsWith(substring string) AssertableString { // DoesNotEndWith asserts if the assertable string doesn't end with the given substring // It errors the test if it end with the given substring. func (a AssertableString) DoesNotEndWith(substring string) AssertableString { + a.t.Helper() if a.actual.EndsWith(substring) { a.t.Error(shouldNotEndWith(a.actual, substring)) } @@ -219,6 +238,7 @@ func (a AssertableString) DoesNotEndWith(substring string) AssertableString { // HasSameSizeAs asserts if the assertable string has the same size with the given string // It errors the test if they don't have the same size. func (a AssertableString) HasSameSizeAs(substring string) AssertableString { + a.t.Helper() if !(a.actual.HasSize(len(substring))) { a.t.Error(shouldHaveSameSizeAs(a.actual, substring)) } @@ -228,6 +248,7 @@ func (a AssertableString) HasSameSizeAs(substring string) AssertableString { // HasSizeLessThan asserts if the assertable string's length is less than the size of the given string // It errors the test if they don't have the same size. func (a AssertableString) HasSizeLessThan(substring string) AssertableString { + a.t.Helper() if !(a.actual.HasSizeLessThan(len(substring))) { a.t.Error(shouldHaveLessSizeThan(a.actual, substring)) } @@ -237,6 +258,7 @@ func (a AssertableString) HasSizeLessThan(substring string) AssertableString { // ContainsOnlyDigits asserts if the expected string contains only digits // It errors the tests if the string has other characters than digits. func (a AssertableString) ContainsOnlyDigits() AssertableString { + a.t.Helper() if !(a.actual.HasDigitsOnly()) { a.t.Error(shouldContainOnlyDigits(a.actual)) } diff --git a/assert/structs.go b/assert/structs.go index d9a5a42..09f7b04 100644 --- a/assert/structs.go +++ b/assert/structs.go @@ -24,6 +24,7 @@ func ThatStruct(t *testing.T, actual interface{}) AssertableStruct { // IsEqualTo asserts if the expected structure is equal to the assertable structure value // It errors the tests if the compared values (actual VS expected) are not equal. func (s AssertableStruct) IsEqualTo(expected interface{}) AssertableStruct { + s.t.Helper() if !s.actual.IsEqualTo(expected) { s.t.Error(shouldBeEqual(s.actual, expected)) } @@ -33,6 +34,7 @@ func (s AssertableStruct) IsEqualTo(expected interface{}) AssertableStruct { // IsNotEqualTo asserts if the expected structure is not equal to the assertable structure value // It errors the tests if the compared values (actual VS expected) are equal. func (s AssertableStruct) IsNotEqualTo(expected interface{}) AssertableStruct { + s.t.Helper() if s.actual.IsEqualTo(expected) { s.t.Error(shouldNotBeEqual(s.actual, expected)) } diff --git a/assert/time.go b/assert/time.go index 747d711..3585d9f 100644 --- a/assert/time.go +++ b/assert/time.go @@ -25,6 +25,7 @@ func ThatTime(t *testing.T, actual time.Time) AssertableTime { // IsSameAs asserts if the expected time.Time is equal to the assertable time.Time value // It errors the tests if the compared values (actual VS expected) are not equal. func (a AssertableTime) IsSameAs(expected time.Time) AssertableTime { + a.t.Helper() if a.actual.IsNotSameAs(expected) { a.t.Error(shouldBeEqual(a.actual, expected)) } @@ -34,6 +35,7 @@ func (a AssertableTime) IsSameAs(expected time.Time) AssertableTime { // IsAlmostSameAs asserts if the expected time.Time is almost equal to the assertable time.Time value // It errors the tests if the compared values (actual VS expected) are not equal. func (a AssertableTime) IsAlmostSameAs(expected time.Time) AssertableTime { + a.t.Helper() if !a.actual.IsAlmostSameAs(expected) { a.t.Error(shouldBeAlmostSame(a.actual, expected)) } @@ -43,6 +45,7 @@ func (a AssertableTime) IsAlmostSameAs(expected time.Time) AssertableTime { // IsNotTheSameAs asserts if the expected time.Time is not equal to the assertable time.Time value // It errors the tests if the compared values (actual VS expected) are equal. func (a AssertableTime) IsNotTheSameAs(expected time.Time) AssertableTime { + a.t.Helper() if a.actual.IsSameAs(expected) { a.t.Error(shouldNotBeEqual(a.actual, expected)) } @@ -52,6 +55,7 @@ func (a AssertableTime) IsNotTheSameAs(expected time.Time) AssertableTime { // IsBefore asserts if the assertable time.Time value is before the expected value // It errors the tests if is not greater. func (a AssertableTime) IsBefore(expected time.Time) AssertableTime { + a.t.Helper() if !a.actual.IsBefore(expected) { a.t.Error(shouldBeGreater(a.actual, expected)) } @@ -61,6 +65,7 @@ func (a AssertableTime) IsBefore(expected time.Time) AssertableTime { // IsAfter asserts if the assertable time.Time value is after the expected value // It errors the tests if is not later. func (a AssertableTime) IsAfter(expected time.Time) AssertableTime { + a.t.Helper() if !a.actual.IsAfter(expected) { a.t.Error(shouldBeGreaterOrEqual(a.actual, expected)) } @@ -70,6 +75,7 @@ func (a AssertableTime) IsAfter(expected time.Time) AssertableTime { // IsDefined asserts if the expected time.Time is defined. // It errors the tests if the value is not defined. func (a AssertableTime) IsDefined() AssertableTime { + a.t.Helper() if a.actual.IsNotDefined() { a.t.Error(shouldBeDefined(a.actual)) } @@ -79,6 +85,7 @@ func (a AssertableTime) IsDefined() AssertableTime { // IsNotDefined asserts if the expected time.Time is not defined. // It errors the tests if the value is defined. func (a AssertableTime) IsNotDefined() AssertableTime { + a.t.Helper() if a.actual.IsDefined() { a.t.Error(shouldNotBeDefined(a.actual)) }