I have a question about how to "drive" a flex bison based parser scanner in a unit test.
The final solution will be a command parser available or telnet to a target board. I have a fully working flex bison implementation using stdin.
Right now my focus is on getting a unit test running for the command parser.
I would like to be able to provide a "const string" to the parser (a command) and then test that the corresponding command is invoked in the application (in a application stub).
I do not know how to setup flex and bison for this. Please find the test case below:
status_cmd_test.c:
#include "CUnit/Basic.h"
#include "cmd_stub.h"
void scan_string(const char* str);
void testSTATUS_OK(void)
{
scan_string("status\n\0\0");
CU_ASSERT(1 == status_sub_nrof_invokes())
}
Excerpt from cmd_lexer.l:
void scan_string(const char* str)
{
YY_BUFFER_STATE buf;
buf = yy_scan_string(str);
yylex();
yy_delete_buffer(buf);
}
cmd_parser.y does not contain any c-code, only bison grammar.
Excerpt from cmd_test.c (has the int main() where the cunit code is located)
if (NULL == CU_add_test(suite_p, "test of status", testSTATUS_OK))
{
CU_cleanup_registry();
return CU_get_error();
}
/* Run all tests using the CUnit Basic interface */
CU_basic_set_mode(CU_BRM_VERBOSE);
CU_basic_run_tests();
CU_cleanup_registry();
return CU_get_error();
I have tried to understand the documentation by I do not know how to drive bison ( yyparse() or something like that).
Can anyone give me a hint?
/ Mikael