[master] 1824ba01d varnishtest: Turn the ${date} macro into a function
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Mon Jul 5 15:48:05 UTC 2021
commit 1824ba01d8401c9548cf5e4d9b9ba5aa2ddda20c
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Thu Jun 17 16:10:16 2021 +0200
varnishtest: Turn the ${date} macro into a function
diff --git a/bin/varnishtest/vtc.c b/bin/varnishtest/vtc.c
index 2eb2e5d43..1a4988cbb 100644
--- a/bin/varnishtest/vtc.c
+++ b/bin/varnishtest/vtc.c
@@ -44,7 +44,6 @@
#include "vav.h"
#include "vrnd.h"
-#include "vtim.h"
#define MAX_TOKENS 200
@@ -238,17 +237,6 @@ macro_cat(struct vtclog *vl, struct vsb *vsb, const char *b, const char *e)
assert(argc >= 2);
- if (!strcmp(argv[1], "date")) {
- double t = VTIM_real();
- retval = malloc(VTIM_FORMAT_SIZE);
- AN(retval);
- VTIM_format(t, retval);
- VSB_cat(vsb, retval);
- free(retval);
- VAV_Free(argv);
- return;
- }
-
AZ(pthread_mutex_lock(¯o_mtx));
VTAILQ_FOREACH(m, ¯o_list, list) {
CHECK_OBJ_NOTNULL(m, MACRO_MAGIC);
diff --git a/bin/varnishtest/vtc_main.c b/bin/varnishtest/vtc_main.c
index 141dac1e5..c646c6574 100644
--- a/bin/varnishtest/vtc_main.c
+++ b/bin/varnishtest/vtc_main.c
@@ -647,6 +647,32 @@ ip_magic(void)
extmacro_def("bad_ip", NULL, "%s", "192.0.2.255");
}
+/**********************************************************************
+ * Macros
+ */
+
+static char * v_matchproto_(macro_f)
+macro_func_date(int argc, char *const *argv, const char **err)
+{
+ double t;
+ char *s;
+
+ assert(argc >= 2);
+ AN(argv);
+ AN(err);
+
+ if (argc > 2) {
+ *err = "macro does not take arguments";
+ return (NULL);
+ }
+
+ t = VTIM_real();
+ s = malloc(VTIM_FORMAT_SIZE);
+ AN(s);
+ VTIM_format(t, s);
+ return (s);
+}
+
/**********************************************************************
* Main
*/
@@ -727,6 +753,8 @@ main(int argc, char * const *argv)
cwd = getcwd(buf, sizeof buf);
extmacro_def("pwd", NULL, "%s", cwd);
+ extmacro_def("date", macro_func_date, NULL);
+
vmod_path = NULL;
params_vsb = VSB_new_auto();
More information about the varnish-commit
mailing list