Commit 35561bcb authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Implement relational expects (>, >=, < & <=)

You have to be careful when you use them though: They compare strings.
parent fe1f9b11
...@@ -220,7 +220,7 @@ cmd_http_expect(CMD_ARGS) ...@@ -220,7 +220,7 @@ cmd_http_expect(CMD_ARGS)
vre_t *vre; vre_t *vre;
const char *error; const char *error;
int erroroffset; int erroroffset;
int i; int i, retval = -1;
(void)cmd; (void)cmd;
(void)vl; (void)vl;
...@@ -236,37 +236,33 @@ cmd_http_expect(CMD_ARGS) ...@@ -236,37 +236,33 @@ cmd_http_expect(CMD_ARGS)
cmp = av[1]; cmp = av[1];
rhs = cmd_var_resolve(hp, av[2]); rhs = cmd_var_resolve(hp, av[2]);
if (!strcmp(cmp, "==")) { if (!strcmp(cmp, "==")) {
if (strcmp(lhs, rhs)) retval = strcmp(lhs, rhs) == 0;
vtc_log(hp->vl, 0, "EXPECT %s (%s) %s %s (%s) failed", } else if (!strcmp(cmp, "<")) {
av[0], lhs, av[1], av[2], rhs); retval = strcmp(lhs, rhs) < 0;
else } else if (!strcmp(cmp, "<=")) {
vtc_log(hp->vl, 4, "EXPECT %s (%s) %s %s (%s) match", retval = strcmp(lhs, rhs) <= 0;
av[0], lhs, av[1], av[2], rhs); } else if (!strcmp(cmp, ">=")) {
retval = strcmp(lhs, rhs) >= 0;
} else if (!strcmp(cmp, ">")) {
retval = strcmp(lhs, rhs) > 0;
} else if (!strcmp(cmp, "!=")) { } else if (!strcmp(cmp, "!=")) {
if (!strcmp(lhs, rhs)) retval = strcmp(lhs, rhs) != 0;
vtc_log(hp->vl, 0, "EXPECT %s (%s) %s %s (%s) failed",
av[0], lhs, av[1], av[2], rhs);
else
vtc_log(hp->vl, 4, "EXPECT %s (%s) %s %s (%s) match",
av[0], lhs, av[1], av[2], rhs);
} else if (!strcmp(cmp, "~") || !strcmp(cmp, "!~")) { } else if (!strcmp(cmp, "~") || !strcmp(cmp, "!~")) {
vre = VRE_compile(rhs, 0, &error, &erroroffset); vre = VRE_compile(rhs, 0, &error, &erroroffset);
if (vre == NULL) if (vre == NULL)
vtc_log(hp->vl, 0, "REGEXP error: %s (@%d) (%s)", vtc_log(hp->vl, 0, "REGEXP error: %s (@%d) (%s)",
error, erroroffset, rhs); error, erroroffset, rhs);
i = VRE_exec(vre, lhs, strlen(lhs), 0, 0, NULL, 0, 0); i = VRE_exec(vre, lhs, strlen(lhs), 0, 0, NULL, 0, 0);
if ((i >= 0 && *cmp == '~') || (i < 0 && *cmp == '!')) retval = (i >= 0 && *cmp == '~') || (i < 0 && *cmp == '!');
vtc_log(hp->vl, 4, "EXPECT %s (%s) %s \"%s\" match",
av[0], lhs, cmp, rhs);
else
vtc_log(hp->vl, 0, "EXPECT %s (%s) %s \"%s\" failed",
av[0], lhs, cmp, rhs);
VRE_free(&vre); VRE_free(&vre);
} else { }
if (retval == -1)
vtc_log(hp->vl, 0, vtc_log(hp->vl, 0,
"EXPECT %s (%s) %s %s (%s) test not implemented", "EXPECT %s (%s) %s %s (%s) test not implemented",
av[0], lhs, av[1], av[2], rhs); av[0], lhs, av[1], av[2], rhs);
} else
vtc_log(hp->vl, retval ? 4 : 0, "EXPECT %s (%s) %s \"%s\" %s",
av[0], lhs, cmp, rhs, retval ? "match" : "failed");
} }
/********************************************************************** /**********************************************************************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment