To Reproduce
Generate tests for following code sample:
struct WithAnonymous {
union {
int i, j;
};
int m;
};
int count_equal_members(struct WithAnonymous st) {
if (st.i == st.m) {
return 2;
}
return 1;
}
Resulting tests are:
TEST(regression, count_equal_members_test_1)
{
int actual = count_equal_members(from_bytes<WithAnonymous>({0, 0, 0, 0, 0, 0, 0, 0}));
EXPECT_EQ(2, actual);
}
TEST(regression, count_equal_members_test_2)
{
int actual = count_equal_members(from_bytes<WithAnonymous>({2, 0, 0, 0, 0, 0, 0, 0}));
EXPECT_EQ(1, actual);
}
Note that parameter initialized using from_bytes function which doesn't look user friendly.
Expected that it would be initialized with explicit values
Similar to what is generated in case when union has identificator.
struct WithAnonymous {
union {
int i, j;
} io;
int m;
};
For sample above more readable tests are generated, where is from_bytes is not used.
TEST(regression, count_equal_members_test_1)
{
int actual = count_equal_members({
.io = {
.i = 0
// .j = 0
},
.m = 0
});
EXPECT_EQ(2, actual);
}
TEST(regression, count_equal_members_test_2)
{
int actual = count_equal_members({
.io = {
.i = 2
// .j = 2
},
.m = 0
});
EXPECT_EQ(1, actual);
}
To Reproduce
Generate tests for following code sample:
Resulting tests are:
Note that parameter initialized using
from_bytesfunction which doesn't look user friendly.Expected that it would be initialized with explicit values
Similar to what is generated in case when union has identificator.
For sample above more readable tests are generated, where is
from_bytesis not used.