bugfix - now stdin returns 0 if the heredoc body is empty
This commit is contained in:
parent
5e84f1b022
commit
c2e4324236
@ -486,8 +486,15 @@ shellmatta_retCode_t shellmatta_processData(shellmatta_handle_t handle,
|
||||
inst->stdinIdx ++;
|
||||
}
|
||||
/** -# calculate length and terminate stdin string */
|
||||
if(inst->stdinIdx < inst->lastNewlineIdx)
|
||||
{
|
||||
inst->stdinLength = inst->lastNewlineIdx - inst->stdinIdx;
|
||||
inst->buffer[inst->lastNewlineIdx] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
inst->stdinLength = 0u;
|
||||
}
|
||||
|
||||
/** -# calculate length and terminate argument string */
|
||||
inst->inputCount = inst->hereStartIdx;
|
||||
|
@ -175,6 +175,38 @@ TEST_CASE( "shellmatta heredoc test" ) {
|
||||
REQUIRE( strcmp(dummyData, doSomethingArguments) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE( "shellmatta heredoc test empty" ) {
|
||||
|
||||
shellmatta_instance_t inst;
|
||||
shellmatta_handle_t handle;
|
||||
char buffer[1024];
|
||||
char historyBuffer[1024];
|
||||
char *dummyData = (char*)"do this ";
|
||||
|
||||
shellmatta_doInit( &inst,
|
||||
&handle,
|
||||
buffer,
|
||||
sizeof(buffer),
|
||||
historyBuffer,
|
||||
sizeof(historyBuffer),
|
||||
"shellmatta->",
|
||||
NULL,
|
||||
writeFct);
|
||||
shellmatta_addCmd(handle, &doSomethingCmd);
|
||||
|
||||
doSomethingArguments = NULL;
|
||||
doSomethingLength = 0u;
|
||||
|
||||
shellmatta_processData(handle, (char*)"do this << EOF\r\n"
|
||||
"EOF\r\n"
|
||||
, 21);
|
||||
|
||||
CHECK( doSomethingStdinLength == 0u);
|
||||
CHECK( NULL == doSomethingStdin );
|
||||
CHECK( doSomethingLength == 8u);
|
||||
REQUIRE( strcmp(dummyData, doSomethingArguments) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE( "shellmatta remove function" ) {
|
||||
|
||||
shellmatta_instance_t inst;
|
||||
|
Loading…
Reference in New Issue
Block a user