[master] af0c665 Un-copy&paste the code to compare two strings in expect.
Poul-Henning Kamp
phk at FreeBSD.org
Wed Apr 26 22:39:05 CEST 2017
commit af0c665e38fb9e20039d43c7b7d1ceba78c2b867
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Apr 26 20:37:26 2017 +0000
Un-copy&paste the code to compare two strings in expect.
diff --git a/bin/varnishtest/flint.lnt b/bin/varnishtest/flint.lnt
index 0c2658c..ad1e024 100644
--- a/bin/varnishtest/flint.lnt
+++ b/bin/varnishtest/flint.lnt
@@ -24,7 +24,6 @@
//
-e732 // Loss of sign (arg. no. 2) (int to unsigned
-e713 // Loss of precision (assignment) (unsigned long long to long long)
--e574 // Signed-unsigned mix with relational
-emacro(835, STRTOU32_CHECK) // A zero has been given as ___ argument to operator '___'
-e788 // enum value not used in defaulted switch
diff --git a/bin/varnishtest/vtc.h b/bin/varnishtest/vtc.h
index ba0fb1c..996b199 100644
--- a/bin/varnishtest/vtc.h
+++ b/bin/varnishtest/vtc.h
@@ -132,3 +132,5 @@ void b64_settings(const struct http *hp, const char *s);
/* vtc_subr.c */
struct vsb *vtc_hex_to_bin(struct vtclog *vl, const char *arg);
+void vtc_expect(struct vtclog *, const char *, const char *, const char *,
+ const char *, const char *);
diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c
index 557f90f..044581e 100644
--- a/bin/varnishtest/vtc_http.c
+++ b/bin/varnishtest/vtc_http.c
@@ -46,7 +46,6 @@
#include "vfil.h"
#include "vgz.h"
#include "vnum.h"
-#include "vre.h"
#include "vtcp.h"
#include "hpack.h"
@@ -345,13 +344,9 @@ static void
cmd_http_expect(CMD_ARGS)
{
struct http *hp;
- const char *lhs, *clhs;
+ const char *lhs;
char *cmp;
- const char *rhs, *crhs;
- vre_t *vre;
- const char *error;
- int erroroffset;
- int i, retval = -1;
+ const char *rhs;
(void)cmd;
(void)vl;
@@ -367,41 +362,7 @@ cmd_http_expect(CMD_ARGS)
cmp = av[1];
rhs = cmd_var_resolve(hp, av[2]);
- clhs = lhs ? lhs : "<undef>";
- crhs = rhs ? rhs : "<undef>";
-
- if (!strcmp(cmp, "~") || !strcmp(cmp, "!~")) {
- vre = VRE_compile(crhs, 0, &error, &erroroffset);
- if (vre == NULL)
- vtc_fatal(hp->vl, "REGEXP error: %s (@%d) (%s)",
- error, erroroffset, crhs);
- i = VRE_exec(vre, clhs, strlen(clhs), 0, 0, NULL, 0, 0);
- retval = (i >= 0 && *cmp == '~') || (i < 0 && *cmp == '!');
- VRE_free(&vre);
- } else if (!strcmp(cmp, "==")) {
- retval = strcmp(clhs, crhs) == 0;
- } else if (!strcmp(cmp, "!=")) {
- retval = strcmp(clhs, crhs) != 0;
- } else if (lhs == NULL || rhs == NULL) {
- // fail inequality comparisons if either side is undef'ed
- retval = 0;
- } else if (!strcmp(cmp, "<")) {
- retval = isless(VNUM(lhs), VNUM(rhs));
- } else if (!strcmp(cmp, ">")) {
- retval = isgreater(VNUM(lhs), VNUM(rhs));
- } else if (!strcmp(cmp, "<=")) {
- retval = islessequal(VNUM(lhs), VNUM(rhs));
- } else if (!strcmp(cmp, ">=")) {
- retval = isgreaterequal(VNUM(lhs), VNUM(rhs));
- }
-
- if (retval == -1)
- vtc_fatal(hp->vl,
- "EXPECT %s (%s) %s %s (%s) test not implemented",
- av[0], clhs, av[1], av[2], crhs);
- else
- vtc_log(hp->vl, retval ? 4 : 0, "EXPECT %s (%s) %s \"%s\" %s",
- av[0], clhs, cmp, crhs, retval ? "match" : "failed");
+ vtc_expect(vl, av[0], lhs, cmp, av[2], rhs);
}
static void
diff --git a/bin/varnishtest/vtc_http2.c b/bin/varnishtest/vtc_http2.c
index 796344e..c0271cb 100644
--- a/bin/varnishtest/vtc_http2.c
+++ b/bin/varnishtest/vtc_http2.c
@@ -46,8 +46,6 @@
#include "vfil.h"
#include "vgz.h"
-#include "vnum.h"
-#include "vre.h"
#include "hpack.h"
#include "vend.h"
@@ -2412,13 +2410,9 @@ cmd_expect(CMD_ARGS)
{
struct http *hp;
struct stream *s;
- const char *lhs, *clhs;
+ const char *lhs;
char *cmp;
- const char *rhs, *crhs;
- vre_t *vre;
- const char *error;
- int erroroffset;
- int i, retval = -1;
+ const char *rhs;
char buf[20];
(void)cmd;
@@ -2437,42 +2431,7 @@ cmd_expect(CMD_ARGS)
lhs = cmd_var_resolve(s, av[0], buf);
cmp = av[1];
rhs = cmd_var_resolve(s, av[2], buf);
-
- clhs = lhs ? lhs : "<undef>";
- crhs = rhs ? rhs : "<undef>";
-
- if (!strcmp(cmp, "~") || !strcmp(cmp, "!~")) {
- vre = VRE_compile(crhs, 0, &error, &erroroffset);
- if (vre == NULL)
- vtc_fatal(vl, "REGEXP error: %s (@%d) (%s)",
- error, erroroffset, crhs);
- i = VRE_exec(vre, clhs, strlen(clhs), 0, 0, NULL, 0, 0);
- retval = (i >= 0 && *cmp == '~') || (i < 0 && *cmp == '!');
- VRE_free(&vre);
- } else if (!strcmp(cmp, "==")) {
- retval = strcmp(clhs, crhs) == 0;
- } else if (!strcmp(cmp, "!=")) {
- retval = strcmp(clhs, crhs) != 0;
- } else if (lhs == NULL || rhs == NULL) {
- // fail inequality comparisons if either side is undef'ed
- retval = 0;
- } else if (!strcmp(cmp, "<")) {
- retval = isless(VNUM(lhs), VNUM(rhs));
- } else if (!strcmp(cmp, ">")) {
- retval = isgreater(VNUM(lhs), VNUM(rhs));
- } else if (!strcmp(cmp, "<=")) {
- retval = islessequal(VNUM(lhs), VNUM(rhs));
- } else if (!strcmp(cmp, ">=")) {
- retval = isgreaterequal(VNUM(lhs), VNUM(rhs));
- }
-
- if (retval == -1)
- vtc_fatal(vl,
- "EXPECT %s (%s) %s %s (%s) test not implemented",
- av[0], clhs, av[1], av[2], crhs);
- else
- vtc_log(vl, retval ? 4 : 0, "(s%d) EXPECT %s (%s) %s \"%s\" %s",
- s->id, av[0], clhs, cmp, crhs, retval ? "match" : "failed");
+ vtc_expect(vl, av[0], lhs, cmp, av[2], rhs);
AZ(pthread_mutex_unlock(&s->hp->mtx));
}
diff --git a/bin/varnishtest/vtc_subr.c b/bin/varnishtest/vtc_subr.c
index a898b12..c992cd9 100644
--- a/bin/varnishtest/vtc_subr.c
+++ b/bin/varnishtest/vtc_subr.c
@@ -28,11 +28,14 @@
#include "config.h"
+#include <math.h>
+#include <string.h>
#include <sys/types.h>
-#include "vtc.h"
-
#include "vct.h"
+#include "vnum.h"
+#include "vre.h"
+#include "vtc.h"
struct vsb *
vtc_hex_to_bin(struct vtclog *vl, const char *arg)
@@ -66,3 +69,61 @@ vtc_hex_to_bin(struct vtclog *vl, const char *arg)
AZ(VSB_finish(vsb));
return (vsb);
}
+
+void
+vtc_expect(struct vtclog *vl,
+ const char *olhs, const char *lhs,
+ const char *cmp,
+ const char *orhs, const char *rhs)
+{
+ vre_t *vre;
+ const char *error;
+ int erroroffset;
+ int i, j, retval = -1;
+ double fl, fr;
+
+ j = lhs == NULL || rhs == NULL;
+ if (lhs == NULL)
+ lhs = "<undef>";
+ if (rhs == NULL)
+ rhs = "<undef>";
+
+ if (!strcmp(cmp, "~") || !strcmp(cmp, "!~")) {
+ vre = VRE_compile(rhs, 0, &error, &erroroffset);
+ if (vre == NULL)
+ vtc_fatal(vl, "REGEXP error: %s (@%d) (%s)",
+ error, erroroffset, rhs);
+ i = VRE_exec(vre, lhs, strlen(lhs), 0, 0, NULL, 0, 0);
+ retval = (i >= 0 && *cmp == '~') || (i < 0 && *cmp == '!');
+ VRE_free(&vre);
+ } else if (!strcmp(cmp, "==")) {
+ retval = strcmp(lhs, rhs) == 0;
+ } else if (!strcmp(cmp, "!=")) {
+ retval = strcmp(lhs, rhs) != 0;
+ } else if (j) {
+ // fail inequality comparisons if either side is undef'ed
+ retval = 0;
+ } else {
+ fl = VNUM(lhs);
+ fr = VNUM(rhs);
+ if (!strcmp(cmp, "<"))
+ retval = isless(fl, fr);
+ else if (!strcmp(cmp, ">"))
+ retval = isgreater(fl, fr);
+ else if (!strcmp(cmp, "<="))
+ retval = islessequal(fl, fr);
+ else if (!strcmp(cmp, ">="))
+ retval = isgreaterequal(fl, fr);
+ }
+
+ if (retval == -1)
+ vtc_fatal(vl,
+ "EXPECT %s (%s) %s %s (%s) test not implemented",
+ olhs, lhs, cmp, orhs, rhs);
+ else if (retval == 0)
+ vtc_fatal(vl, "EXPECT %s (%s) %s \"%s\" failed",
+ olhs, lhs, cmp, rhs);
+ else
+ vtc_log(vl, 4, "EXPECT %s (%s) %s \"%s\" match",
+ olhs, lhs, cmp, rhs);
+}
More information about the varnish-commit
mailing list