Revised and extended tests, convert to standard output format.
This commit is contained in:
@@ -21,42 +21,91 @@
|
||||
#include "errlog.h"
|
||||
|
||||
int
|
||||
check(char *str, char *expect)
|
||||
check(const char *str, const char *expect)
|
||||
{
|
||||
char *got = macEnvExpand(str);
|
||||
if(expect && !got) {
|
||||
printf("Expand \"%s'\". Got NULL, expected \"%s\".\n", str, expect);
|
||||
return 1;
|
||||
int bad = 0;
|
||||
static int count = 0;
|
||||
if (expect && !got) {
|
||||
printf("\t#Got NULL, expected \"%s\".\n", expect);
|
||||
bad = 1;
|
||||
}
|
||||
if (!expect && got) {
|
||||
printf("Expand \"%s'\". Got \"%s\", expected NULL.\n", str, got);
|
||||
return 1;
|
||||
else if (!expect && got) {
|
||||
printf("\t#Got \"%s\", expected NULL.\n", got);
|
||||
bad = 1;
|
||||
}
|
||||
if(expect && got && strcmp(got, expect)) {
|
||||
printf("Expand \"%s'\". Got \"%s\", expected \"%s\".\n", str, got, expect);
|
||||
return 1;
|
||||
else if (expect && got && strcmp(got, expect)) {
|
||||
printf("\t#Got \"%s\", expected \"%s\".\n", got, expect);
|
||||
bad = 1;
|
||||
}
|
||||
return 0;
|
||||
/* This output format follows the perl standard: */
|
||||
printf("%sok %d - \"%s\".\n", (bad ? "not " : ""), ++count, str);
|
||||
return bad;
|
||||
}
|
||||
|
||||
int macEnvExpandTest(void)
|
||||
{
|
||||
int bad = 0;
|
||||
int warn = 0;
|
||||
|
||||
/* Announce the number of calls to check() present in the code below: */
|
||||
printf("1..%d\n", 30);
|
||||
|
||||
bad |= check ("FOO", "FOO");
|
||||
|
||||
bad |= check ("${FOO}", NULL); warn++;
|
||||
bad |= check ("${FOO=}", "");
|
||||
bad |= check ("x${FOO=}y", "xy");
|
||||
bad |= check ("${FOO=BAR}", "BAR");
|
||||
bad |= check ("x${FOO=BAR}y", "xBARy");
|
||||
|
||||
printf ("Expect one message about failure to expand ${FOOBAR}.\n");
|
||||
epicsEnvSet("FOO","BLETCH");
|
||||
epicsEnvSet("BAR","GLEEP");
|
||||
bad |= check ("${FOO}", "BLETCH");
|
||||
bad |= check ("x${FOO}y", "xBLETCHy");
|
||||
bad |= check ("x${FOO}y${FOO}z", "xBLETCHyBLETCHz");
|
||||
bad |= check ("${FOO=BAR}", "BLETCH");
|
||||
bad |= check ("x${FOO=BAR}y", "xBLETCHy");
|
||||
bad |= check ("${FOO=${BAZ}}", "BLETCH");
|
||||
bad |= check ("x${FOO=${BAZ}}y", "xBLETCHy");
|
||||
bad |= check ("${BAR=${FOO}}", "BLETCH");
|
||||
bad |= check ("x${BAR=${FOO}}y", "xBLETCHy");
|
||||
bad |= check ("w${BAR=x${FOO}y}z", "wxBLETCHyz");
|
||||
|
||||
epicsEnvSet("BAR","GLEEP");
|
||||
bad |= check ("${FOO}/${BAR}", "BLETCH/GLEEP");
|
||||
bad |= !check ("${FOOBAR}", NULL);
|
||||
bad |= check ("x${FOO}/${BAR}y", "xBLETCH/GLEEPy");
|
||||
bad |= check ("${BAR=${FOO}}", "GLEEP");
|
||||
|
||||
epicsEnvSet("BLETCH","BAR");
|
||||
bad |= check ("${${FOO}}", "BAR");
|
||||
bad |= check ("x${${FOO}}y", "xBARy");
|
||||
bad |= check ("${${FOO}=GRIBBLE}", "BAR");
|
||||
bad |= check ("x${${FOO}=GRIBBLE}y", "xBARy");
|
||||
|
||||
epicsEnvSet("BLETCH","${BAR}");
|
||||
bad |= check ("${${FOO}}", "GLEEP");
|
||||
|
||||
epicsEnvSet("FOO","${BAR}");
|
||||
bad |= check ("${FOO}","GLEEP");
|
||||
|
||||
epicsEnvSet("BAR","${BAZ}");
|
||||
bad |= check ("${FOO}", NULL); warn++;
|
||||
|
||||
epicsEnvSet("BAR","${BAZ=GRIBBLE}");
|
||||
bad |= check ("${FOO}", "GRIBBLE");
|
||||
|
||||
epicsEnvSet("BAR","${STR1}");
|
||||
epicsEnvSet("STR1","VAL1");
|
||||
epicsEnvSet("STR2","VAL2");
|
||||
bad |= check ("${FOO}", "VAL1");
|
||||
|
||||
epicsEnvSet("BAR","${STR2}");
|
||||
bad |= check ("${FOO}", "VAL2");
|
||||
|
||||
epicsEnvSet("BAR","${FOO}");
|
||||
bad |= check ("${FOO}", NULL); warn++;
|
||||
|
||||
printf("# Expect %d warning messages here:\n", warn);
|
||||
errlogFlush();
|
||||
return bad;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user