Skip to content

UTBot cannot run test for old-style declared function #495

Closed
@tyuldashev

Description

@tyuldashev

Description
In case 'C' method used 'old-style' declaration UTBot does not properly generate '.h' file and later cannot compile it for test execution.

To Reproduce
Steps to reproduce the behavior:

  • Generate code for following method
int sum(a, b)
int a;
int b;
{
    return a + b;
}
  • The generated tests in '.cpp' file looks pretty normal
  • Try to run generated tests

Expected behavior
Tests are supposed to be executed.

Actual behavior
Execution fails with error: "1 actions failed during building and running tests." . Log contains following errors:

In file included from /home/utbot/remote/SampleDocker2/tests/makefiles/src/../../../tests/src/old_syntax_dot_c_test.cpp:5:
/home/utbot/remote/SampleDocker2/tests/makefiles/src/../../../tests/src/old_syntax_dot_c_test.h:63:37: error: unknown type name 'a'
extern "C" int sum_src_old_syntax_c(a, b);
                                    ^
/home/utbot/remote/SampleDocker2/tests/makefiles/src/../../../tests/src/old_syntax_dot_c_test.h:63:40: error: unknown type name 'b'
extern "C" int sum_src_old_syntax_c(a, b);
                                       ^
/home/utbot/remote/SampleDocker2/tests/makefiles/src/../../../tests/src/old_syntax_dot_c_test.h:64:16: error: unknown type name 'a'
static int sum(a, b) {
               ^
/home/utbot/remote/SampleDocker2/tests/makefiles/src/../../../tests/src/old_syntax_dot_c_test.h:64:19: error: unknown type name 'b'
static int sum(a, b) {
                  ^
/home/utbot/remote/SampleDocker2/tests/makefiles/src/../../../tests/src/old_syntax_dot_c_test.h:65:29: error: use of undeclared identifier 'a'
return sum_src_old_syntax_c(a, b);
                            ^
/home/utbot/remote/SampleDocker2/tests/makefiles/src/../../../tests/src/old_syntax_dot_c_test.h:65:32: error: use of undeclared identifier 'b'
return sum_src_old_syntax_c(a, b);
                               ^
6 errors generated.
....

That's because generated header file for test has following declaration:

extern "C" int sum_src_old_syntax_c(a, b);
static int sum(a, b) {
return sum_src_old_syntax_c(a, b);
}

Additional information
Please note that even this syntax is not widely used in modern applications it could be found in old, but still active projects. For instance I found it in zlib library (2k Forks, 3.9k Start on GitHub, 40 commits in last month). So I believe that we should not put this case on hold.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingwrong generationInadequate or empty test suite generated

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions