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

Go. Assertions for structures should be accurate #1809

Open
alisevych opened this issue Feb 17, 2023 · 2 comments
Open

Go. Assertions for structures should be accurate #1809

alisevych opened this issue Feb 17, 2023 · 2 comments
Assignees
Labels
ctg-bug Issue is a bug ctg-question Further information is requested lang-go Issue is related to Go support

Comments

@alisevych
Copy link
Member

alisevych commented Feb 17, 2023

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

@alisevych alisevych added ctg-bug Issue is a bug spec-ux Issue is influencing user experience lang-go Issue is related to Go support labels Feb 17, 2023
@alisevych alisevych added this to the 2023.03 Release milestone Mar 1, 2023
@alisevych alisevych added the ctg-question Further information is requested label Mar 2, 2023
@alisevych
Copy link
Member Author

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)

@alisevych
Copy link
Member Author

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

@alisevych alisevych removed the spec-ux Issue is influencing user experience label Mar 21, 2023
@alisevych alisevych removed this from the 2023.03 Release milestone Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ctg-bug Issue is a bug ctg-question Further information is requested lang-go Issue is related to Go support
Projects
Status: Todo
Development

No branches or pull requests

2 participants