Skip to content
Permalink
Browse files

Improve coverage in perl/exec module.

  • Loading branch information...
dwsteele committed May 13, 2019
1 parent 4315325 commit 2d2bec842a2c424d5a36c98dc3a465da1696caf4
Showing with 72 additions and 26 deletions.
  1. +4 −0 doc/xml/release.xml
  2. +45 −25 src/perl/exec.c
  3. +1 −1 test/define.yaml
  4. +22 −0 test/src/module/perl/execTest.c
@@ -159,6 +159,10 @@
<p>Improve log performance, simplify macros, rename <code>logWill()</code> to <code>logAny()</code>.</p>
</release-item>

<release-item>
<p>Improve coverage in <file>perl/exec</file> module.</p>
</release-item>

<release-item>
<p>Use <code>THROW_ON_SYS_ERROR*()</code> to improve code coverage.</p>
</release-item>
@@ -77,24 +77,17 @@ perlMain(void)
/***********************************************************************************************************************************
Dynamic module loader
***********************************************************************************************************************************/
XS_EUPXS(embeddedModuleGet);
XS_EUPXS(embeddedModuleGet)
static const char *
embeddedModuleGetInternal(const char *moduleName)
{
// Ensure all parameters were passed
dVAR; dXSARGS;

if (items != 1) // {uncovered_branch - no invalid calls}
croak_xs_usage(cv, "moduleName"); // {+uncovered}

// Get module name
const char *moduleName = (const char *)SvPV_nolen(ST(0)); // {uncoverable_branch - Perl macro}
dXSTARG; // {uncoverable_branch - Perl macro}
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(STRINGZ, moduleName);
FUNCTION_TEST_END();

// Find module
const char *result = NULL;

for (unsigned int moduleIdx = 0; // {uncovered - no invalid modules in embedded Perl}
moduleIdx < sizeof(embeddedModule) / sizeof(EmbeddedModule); moduleIdx++)
for (unsigned int moduleIdx = 0; moduleIdx < sizeof(embeddedModule) / sizeof(EmbeddedModule); moduleIdx++)
{
if (strcmp(embeddedModule[moduleIdx].name, moduleName) == 0)
{
@@ -104,11 +97,25 @@ XS_EUPXS(embeddedModuleGet)
}

// Error if the module was not found
if (result == NULL) // {uncovered_branch - no invalid modules in embedded Perl}
croak("unable to load embedded module '%s'", moduleName); // {+uncovered}
if (result == NULL)
THROW_FMT(AssertError, "unable to load embedded module '%s'", moduleName);

FUNCTION_TEST_RETURN(result);
}

XS_EUPXS(embeddedModuleGet);
XS_EUPXS(embeddedModuleGet)
{
dVAR; dXSARGS;
(void)cv;

// Get module name
CHECK(items == 1);
const char *moduleName = (const char *)SvPV_nolen(ST(0)); // {uncoverable_branch - Perl macro}
dXSTARG; // {uncoverable_branch - Perl macro}

// Return module data
sv_setpv(TARG, result);
sv_setpv(TARG, embeddedModuleGetInternal(moduleName));
XSprePUSH;
PUSHTARG; // {uncoverable_branch - Perl macro}

@@ -210,6 +217,27 @@ perlInit(void)
/***********************************************************************************************************************************
Execute main function in Perl
***********************************************************************************************************************************/
static int perlExecResult(int code, bool errorC, const char *message)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(INT, code);
FUNCTION_TEST_PARAM(BOOL, errorC);
FUNCTION_TEST_PARAM(STRINGZ, message);
FUNCTION_TEST_END();

int result = code;

if (code >= errorTypeCode(&AssertError))
{
if (errorC)
RETHROW();
else
THROW_CODE(code, strlen(message) == 0 ? PERL_EMBED_ERROR : message);
}

FUNCTION_TEST_RETURN(result);
}

int
perlExec(void)
{
@@ -226,15 +254,7 @@ perlExec(void)
bool errorC = (int)SvIV(get_sv("bErrorC", 0)); // {uncoverable_branch - Perl macro}
char *message = SvPV_nolen(get_sv("strMessage", 0)); // {uncoverable_branch - Perl macro}

if (code >= errorTypeCode(&AssertError)) // {uncovered_branch - tested in integration}
{
if (errorC) // {+uncovered}
RETHROW(); // {+uncovered}
else
THROW_CODE(code, strlen(message) == 0 ? PERL_EMBED_ERROR : message); // {+uncovered}
}

FUNCTION_LOG_RETURN(INT, code); // {+uncovered}
FUNCTION_LOG_RETURN(INT, perlExecResult(code, errorC, message));
}

/***********************************************************************************************************************************
@@ -362,7 +362,7 @@ unit:

# ----------------------------------------------------------------------------------------------------------------------------
- name: exec
total: 2
total: 4
perlReq: true

coverage:
@@ -37,6 +37,28 @@ testRun(void)
"command with one option and params");
}

// *****************************************************************************************************************************
if (testBegin("embeddedModuleGetInternal()"))
{
TEST_ERROR(embeddedModuleGetInternal(BOGUS_STR), AssertError, "unable to load embedded module 'BOGUS'");
}

// *****************************************************************************************************************************
if (testBegin("perlExecResult()"))
{
TRY_BEGIN()
{
THROW(PathMissingError, "test message");
}
CATCH_ANY()
{
TEST_ERROR(perlExecResult(errorTypeCode(&PathMissingError), true, NULL), PathMissingError, "test message");
}
TRY_END();

TEST_RESULT_INT(perlExecResult(0, false, NULL), 0, "test success");
}

// *****************************************************************************************************************************
if (testBegin("perlInit(), perlExec(), and perlFree()"))
{

0 comments on commit 2d2bec8

Please sign in to comment.
You can’t perform that action at this time.