Open
Description
Description
If user code accepts file name as parameter then opens and read it, then UTBot generates improper file names and tests fail with errors.
To Reproduce
Generate and run tests for following code (extracted from #507):
int read_first_char(char * name) {
FILE *file = fopen(name, "r");
if (file == NULL) return -1;
int c = fgetc(file);
// fclose(file);
if (c == 'Y') return 'Y';
if (c == 'Z') return 'Z';
return '0';
}
Expected behavior
Regression tests pass
Actual behavior
Many regression tests fail. Below is one of such tests.
TEST(regression, read_first_char_test_1)
{
write_to_file("../../../tests/src/A", "Y");
char name[] = {'A', '\0', 'c', 'c', 'c', 'a', 'c', 'c', 'c', '\0'};
int actual = read_first_char(name);
EXPECT_EQ(89, actual);
char expected_name[] = {'A', '\0', 'c', 'c', 'c', 'a', 'c', 'c', 'c', '\0'};
for (int it_17_0 = 0; it_17_0 < 10; it_17_0 ++) {
EXPECT_EQ(expected_name[it_17_0], name[it_17_0]);
}
}
Note that file name initialized with:
char name[] = {'A', '\0', 'c', 'c', 'c', 'a', 'c', 'c', 'c', '\0'};
Should it contain actual path to the file, then EXPECT_EQ(89, actual)
would pass:
char name[] = "../../../tests/src/A";
Metadata
Metadata
Assignees
Type
Projects
Status
Todo