UTBotCpp icon indicating copy to clipboard operation
UTBotCpp copied to clipboard

Concatenate string written to test file

Open tyuldashev opened this issue 3 years ago • 0 comments

Description Currently test file content is formed from number of adjacent one-letter stings. It would take less space and would be easier to read if that would be just one string.

To Reproduce Steps to reproduce the behavior:

  1. Generate tests for code which are using files, for instance use following code (extraction from file.c:
int file_fgets(FILE *fA) {
  char a[8];
  fgets(a, 6, fA);
  if (a[0] == 'u' && a[1] == 't' && a[2] == 'b' && a[3] == 'o' && a[4] == 't') {
    return 1;
  }
  return 0;
}

Actual behavior Tests stary with following code:

TEST(regression, file_fgets_test_1)
{
    write_to_file("../../../tests/src/A", "ut\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n""\n");
    write_to_file("../../../tests/src/B", "\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0");
    write_to_file("../../../tests/src/C", "\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0""\0");

...
}

Note that strings written to file consists of one letter strings. While I believe it would be more convenient to concatenate them before test generation so they would look:

TEST(regression, file_fgets_test_1)
{
    write_to_file("../../../tests/src/A", "ut\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
    write_to_file("../../../tests/src/B", "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
    write_to_file("../../../tests/src/C", "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");

...

tyuldashev avatar Oct 18 '22 11:10 tyuldashev