Skip to content

Go. Assertions for structures should be accurate #1809

Description

@alisevych

Description

Now tests generated for Go structures have assertNotEquals for the whole structure.
Actual and expected structures have only one different field.
If some other field is different in actual and expected structures, the test will pass too.

Context

for example:
utbot-go/go-samples/simple/supported_types_go_ut_test.go see TestStructWithNanByUtGoFuzzer

Actual behavior

assert.NotEqual(t, Structure{int: -1, int8: 1, int16: 32767, int32: -1, int64: -1, uint: 18446744073709551615, uint8: 0, uint16: 1, uint32: 0, uint64: 18446744073709551615, uintptr: 18446744073709551615, float32: 0.02308184, float64: math.NaN(), complex64: complex(float32(0.02308184), float32(0.02308184)), complex128: complex(0.9412491794821144, 0.9412491794821144), byte: 0, rune: -1, string: "", bool: false}, actualVal)

Expected behavior

assert.NotEqual(t, math.NaN(), actualVal.float64)

Environment

IntelliJ IDEA 2022.1 - 2022.2 Ultimate/Community
GoLand 2022.2

Activity

  1. added
    ctg-bugIssue is a bug
    spec-uxIssue is influencing user experience
    lang-goIssue is related to Go support
    on Feb 17, 2023
  2. added this to the 2023.03 Release milestone on Mar 1, 2023
  3. alisevych commented on Mar 2, 2023

    @alisevych
    MemberAuthor

    Can we identify which fields has changed from initial ones?
    Then can make assertNotEquals for them only.

    Other possible solutions are:

    • also add assertEquals for other fields of the structure? Like the following:
    assert.NotEqual(t, math.NaN(), actualVal.float64)
    assert.Equal(t, -1, actualVal.int)
    assert.Equal(t, 1, actualVal.int8)
    ...
    • Or it would be better to use one assertEquals for the whole structure? Like:
    assert.Equal(t, Structure{int: -1, int8: 1, int16: 32767, int32: -1, int64: -1, uint: 18446744073709551615, uint8: 0, uint16: 1, uint32: 0, uint64: 18446744073709551615, uintptr: 18446744073709551615, float32: 0.7815346, float64: 0.3332183994766498, complex64: complex(float32(0.7815346), float32(0.7815346)), complex128: complex(0.3332183994766498, 0.3332183994766498), byte: 0, rune: -1, string: "", bool: false}, actualVal)
  4. alisevych commented on Mar 2, 2023

    @alisevych
    MemberAuthor

    During discussion of the issue @Markoutte suggested an assertion approach, that can be useful for all languages:

  5. removed
    spec-uxIssue is influencing user experience
    on Mar 21, 2023
  6. removed this from the 2023.03 Release milestone on Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ctg-bugIssue is a bugctg-questionFurther information is requestedlang-goIssue is related to Go support

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions