r4767 - trunk/varnish-cache/bin/varnishtest
phk at varnish-cache.org
phk at varnish-cache.org
Wed May 5 10:16:32 CEST 2010
Author: phk
Date: 2010-05-05 10:16:31 +0200 (Wed, 05 May 2010)
New Revision: 4767
Modified:
trunk/varnish-cache/bin/varnishtest/vtc.c
trunk/varnish-cache/bin/varnishtest/vtc.h
trunk/varnish-cache/bin/varnishtest/vtc_client.c
Log:
Give a sensible message on attempting to expand an undefined macro
Modified: trunk/varnish-cache/bin/varnishtest/vtc.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc.c 2010-05-05 08:15:50 UTC (rev 4766)
+++ trunk/varnish-cache/bin/varnishtest/vtc.c 2010-05-05 08:16:31 UTC (rev 4767)
@@ -149,23 +149,23 @@
}
struct vsb *
-macro_expand(const char *name)
+macro_expand(struct vtclog *vl, const char *text)
{
struct vsb *vsb;
- char *p, *q;
+ char *p, *q, *m;
vsb = vsb_newauto();
AN(vsb);
- while (*name != '\0') {
- p = strstr(name, "${");
+ while (*text != '\0') {
+ p = strstr(text, "${");
if (p == NULL) {
- vsb_cat(vsb, name);
+ vsb_cat(vsb, text);
break;
}
- vsb_bcat(vsb, name, p - name);
+ vsb_bcat(vsb, text, p - text);
q = strchr(p, '}');
if (q == NULL) {
- vsb_cat(vsb, name);
+ vsb_cat(vsb, text);
break;
}
assert(p[0] == '$');
@@ -173,8 +173,13 @@
assert(q[0] == '}');
p += 2;
*q = '\0';
- vsb_cat(vsb, macro_get(p));
- name = q + 1;
+ m = macro_get(p);
+ if (m == NULL) {
+ vtc_log(vl, 0, "Macro ${%s} not found", p);
+ return (NULL);
+ }
+ vsb_printf(vsb, "{MACRO NOT FOUND: %s}", p);
+ text = q + 1;
}
vsb_finish(vsb);
return (vsb);
@@ -301,7 +306,7 @@
*token_e[tn] = '\0'; /*lint !e771 */
if (NULL == strstr(token_s[tn], "${"))
continue;
- token_exp[tn] = macro_expand(token_s[tn]);
+ token_exp[tn] = macro_expand(vl, token_s[tn]);
token_s[tn] = vsb_data(token_exp[tn]);
token_e[tn] = strchr(token_s[tn], '\0');
}
Modified: trunk/varnish-cache/bin/varnishtest/vtc.h
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc.h 2010-05-05 08:15:50 UTC (rev 4766)
+++ trunk/varnish-cache/bin/varnishtest/vtc.h 2010-05-05 08:16:31 UTC (rev 4767)
@@ -78,4 +78,4 @@
void macro_def(struct vtclog *vl, const char *instance, const char *name,
const char *fmt, ...);
-struct vsb *macro_expand(const char *name);
+struct vsb *macro_expand(struct vtclog *vl, const char *text);
Modified: trunk/varnish-cache/bin/varnishtest/vtc_client.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_client.c 2010-05-05 08:15:50 UTC (rev 4766)
+++ trunk/varnish-cache/bin/varnishtest/vtc_client.c 2010-05-05 08:16:31 UTC (rev 4767)
@@ -86,12 +86,13 @@
CAST_OBJ_NOTNULL(c, priv, CLIENT_MAGIC);
AN(*c->connect);
+ vl = vtc_logopen(c->name);
+
p = strdup(c->connect);
- vsb = macro_expand(p);
+ AN(p);
+ vsb = macro_expand(vl, p);
AN(vsb);
- vl = vtc_logopen(c->name);
-
if (c->repeat == 0)
c->repeat = 1;
if (c->repeat != 1)
More information about the varnish-commit
mailing list