summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-01-20 22:55:46 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-01-20 22:55:46 +0000
commite2762e29b6445ab6177b83521a279938a317605f (patch)
treef1daca9b424eb34693a3cb687aa7dba20226f4b0
parent7a6aee8ed3dc388c63c4711e3a8122b46d8740fb (diff)
downloadmandoc-e2762e29b6445ab6177b83521a279938a317605f.tar.gz
Added regression tests (just for prologue, for now).
Minor fixes in parsing prologue.
-rw-r--r--Makefile36
-rw-r--r--action.c41
-rw-r--r--argv.c1
-rw-r--r--private.h1
-rw-r--r--regress/test.empty0
-rw-r--r--regress/test.prologue.004
-rw-r--r--regress/test.prologue.014
-rw-r--r--regress/test.prologue.024
-rw-r--r--regress/test.prologue.034
-rw-r--r--regress/test.prologue.044
-rw-r--r--regress/test.prologue.054
-rw-r--r--regress/test.prologue.064
-rw-r--r--regress/test.prologue.074
-rw-r--r--regress/test.prologue.084
-rw-r--r--regress/test.prologue.094
-rw-r--r--regress/test.prologue.104
-rw-r--r--regress/test.prologue.114
-rw-r--r--regress/test.prologue.124
-rw-r--r--regress/test.prologue.134
-rw-r--r--regress/test.prologue.144
-rw-r--r--regress/test.prologue.154
-rw-r--r--regress/test.prologue.164
-rw-r--r--regress/test.prologue.174
-rw-r--r--regress/test.prologue.184
-rw-r--r--regress/test.prologue.193
-rw-r--r--regress/test.prologue.204
-rw-r--r--regress/test.prologue.214
-rw-r--r--regress/test.prologue.224
-rw-r--r--regress/test.prologue.234
-rw-r--r--regress/test.prologue.244
-rw-r--r--strings.c10
-rw-r--r--xstd.c8
32 files changed, 161 insertions, 35 deletions
diff --git a/Makefile b/Makefile
index 4d5500f2..0497c41f 100644
--- a/Makefile
+++ b/Makefile
@@ -33,6 +33,34 @@ CLEAN = $(BINS) $(LNS) $(LLNS) $(LIBS) $(OBJS)
INSTALL = $(SRCS) $(HEADS) Makefile Makefile.port DESCR $(MANS)
+FAIL = regress/test.empty \
+ regress/test.prologue.00 \
+ regress/test.prologue.01 \
+ regress/test.prologue.02 \
+ regress/test.prologue.03 \
+ regress/test.prologue.04 \
+ regress/test.prologue.06 \
+ regress/test.prologue.13 \
+ regress/test.prologue.15 \
+ regress/test.prologue.16 \
+ regress/test.prologue.18 \
+ regress/test.prologue.19 \
+ regress/test.prologue.21 \
+ regress/test.prologue.22 \
+ regress/test.prologue.23 \
+ regress/test.prologue.24
+
+SUCCEED = regress/test.prologue.05 \
+ regress/test.prologue.07 \
+ regress/test.prologue.08 \
+ regress/test.prologue.09 \
+ regress/test.prologue.10 \
+ regress/test.prologue.11 \
+ regress/test.prologue.12 \
+ regress/test.prologue.14 \
+ regress/test.prologue.17 \
+ regress/test.prologue.20
+
all: $(BINS)
lint: $(LLNS)
@@ -44,6 +72,14 @@ dist: mdocml-$(VERSION).tar.gz
port: mdocml-oport-$(VERSION).tar.gz
+regress::
+ @for f in $(FAIL); do \
+ echo "./mdocml $$f" ; \
+ ./mdocml $$f 2>/dev/null || continue ; exit 1 ; done
+ @for f in $(SUCCEED); do \
+ echo "./mdocml $$f" ; \
+ ./mdocml $$f 2>/dev/null || exit 1 ; done
+
install:
mkdir -p $(PREFIX)/bin/
mkdir -p $(PREFIX)/include/mdoc/
diff --git a/action.c b/action.c
index 98d2b042..d78803ea 100644
--- a/action.c
+++ b/action.c
@@ -246,6 +246,8 @@ post_dt(struct mdoc *mdoc)
if (NULL == mdoc->meta.title)
mdoc->meta.title = xstrdup("untitled");
+ mdoc_msg(mdoc, "title: %s", mdoc->meta.title);
+
return(post_prologue(mdoc));
}
@@ -279,46 +281,21 @@ post_os(struct mdoc *mdoc)
static int
post_dd(struct mdoc *mdoc)
{
- char date[64];
- size_t sz;
- char *p;
- struct mdoc_node *n;
+ char buf[64];
assert(MDOC_ELEM == mdoc->last->type);
assert(MDOC_Dd == mdoc->last->tok);
- n = mdoc->last->child;
assert(0 == mdoc->meta.date);
- date[0] = 0;
-
- sz = 64;
-
- for ( ; 0 == mdoc->meta.date && n; n = n->next) {
- assert(MDOC_TEXT == n->type);
- p = n->data.text.string;
- if (xstrcmp(p, "$Mdocdate$")) {
- mdoc->meta.date = time(NULL);
- continue;
- } else if (xstrcmp(p, "$")) {
- mdoc->meta.date = mdoc_atotime(date);
- continue;
- } else if (xstrcmp(p, "$Mdocdate:"))
- continue;
+ if ( ! xstrlcats(buf, mdoc->last->child, 64))
+ return(mdoc_err(mdoc, "macro parameters too long"));
+ if (0 == (mdoc->meta.date = mdoc_atotime(buf)))
+ return(mdoc_err(mdoc, "invalid parameter syntax"));
- if ( ! xstrlcat(date, n->data.text.string, sz))
- return(mdoc_nerr(mdoc, n, "invalid parameter syntax"));
- if (n->next && ! xstrlcat(date, " ", sz))
- return(mdoc_nerr(mdoc, n, "invalid parameter syntax"));
- }
+ mdoc_msg(mdoc, "date: %u", mdoc->meta.date);
- if (mdoc->meta.date && NULL == n)
- return(post_prologue(mdoc));
- else if (n)
- return(mdoc_err(mdoc, "invalid parameter syntax"));
- if ((mdoc->meta.date = mdoc_atotime(date)))
- return(post_prologue(mdoc));
- return(mdoc_err(mdoc, "invalid parameter syntax"));
+ return(post_prologue(mdoc));
}
diff --git a/argv.c b/argv.c
index 6be0ba60..dbcd3d4b 100644
--- a/argv.c
+++ b/argv.c
@@ -169,7 +169,6 @@ mdoc_args(struct mdoc *mdoc, int line,
if (MDOC_It == tok) {
n = mdoc->last->parent;
/* FIXME: scan for ARGS_TABSEP. */
-
}
if (0 == buf[*pos])
diff --git a/private.h b/private.h
index b4766b8f..1e80043f 100644
--- a/private.h
+++ b/private.h
@@ -161,6 +161,7 @@ int xstrlcats(char *, const struct mdoc_node *, size_t);
int xstrlcat(char *, const char *, size_t);
int xstrlcpy(char *, const char *, size_t);
int xstrcmp(const char *, const char *);
+int xstrncmp(const char *, const char *, size_t);
void *xcalloc(size_t, size_t);
char *xstrdup(const char *);
diff --git a/regress/test.empty b/regress/test.empty
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/regress/test.empty
diff --git a/regress/test.prologue.00 b/regress/test.prologue.00
new file mode 100644
index 00000000..66976084
--- /dev/null
+++ b/regress/test.prologue.00
@@ -0,0 +1,4 @@
+.Dd $Mdocdate: May 31 2007
+.Dt
+.Os
+.Sh NAME
diff --git a/regress/test.prologue.01 b/regress/test.prologue.01
new file mode 100644
index 00000000..d326eaaa
--- /dev/null
+++ b/regress/test.prologue.01
@@ -0,0 +1,4 @@
+.Dd $Mdocdate$
+.Dt
+.Os
+.Sh NAME
diff --git a/regress/test.prologue.02 b/regress/test.prologue.02
new file mode 100644
index 00000000..561e3822
--- /dev/null
+++ b/regress/test.prologue.02
@@ -0,0 +1,4 @@
+.Dd $Mdocdate May 31 2007 $
+.Dt
+.Os
+.Sh NAME
diff --git a/regress/test.prologue.03 b/regress/test.prologue.03
new file mode 100644
index 00000000..5dfa5522
--- /dev/null
+++ b/regress/test.prologue.03
@@ -0,0 +1,4 @@
+.Dd $Mdocdat$
+.Dt
+.Os
+.Sh NAME
diff --git a/regress/test.prologue.04 b/regress/test.prologue.04
new file mode 100644
index 00000000..3c823948
--- /dev/null
+++ b/regress/test.prologue.04
@@ -0,0 +1,4 @@
+.Dd June 40 1999
+.Dt
+.Os
+.Sh NAME
diff --git a/regress/test.prologue.05 b/regress/test.prologue.05
new file mode 100644
index 00000000..d7fd5b66
--- /dev/null
+++ b/regress/test.prologue.05
@@ -0,0 +1,4 @@
+.Dd June 1999
+.Dt
+.Os
+.Sh NAME
diff --git a/regress/test.prologue.06 b/regress/test.prologue.06
new file mode 100644
index 00000000..cd461a7e
--- /dev/null
+++ b/regress/test.prologue.06
@@ -0,0 +1,4 @@
+.Dd
+.Dt
+.Os
+.Sh NAME
diff --git a/regress/test.prologue.07 b/regress/test.prologue.07
new file mode 100644
index 00000000..d326eaaa
--- /dev/null
+++ b/regress/test.prologue.07
@@ -0,0 +1,4 @@
+.Dd $Mdocdate$
+.Dt
+.Os
+.Sh NAME
diff --git a/regress/test.prologue.08 b/regress/test.prologue.08
new file mode 100644
index 00000000..e590b07c
--- /dev/null
+++ b/regress/test.prologue.08
@@ -0,0 +1,4 @@
+.Dd May 31 2007
+.Dt
+.Os
+.Sh NAME
diff --git a/regress/test.prologue.09 b/regress/test.prologue.09
new file mode 100644
index 00000000..d1e742fa
--- /dev/null
+++ b/regress/test.prologue.09
@@ -0,0 +1,4 @@
+.Dd May 31, 2007
+.Dt
+.Os
+.Sh NAME
diff --git a/regress/test.prologue.10 b/regress/test.prologue.10
new file mode 100644
index 00000000..d326eaaa
--- /dev/null
+++ b/regress/test.prologue.10
@@ -0,0 +1,4 @@
+.Dd $Mdocdate$
+.Dt
+.Os
+.Sh NAME
diff --git a/regress/test.prologue.11 b/regress/test.prologue.11
new file mode 100644
index 00000000..def6a5a1
--- /dev/null
+++ b/regress/test.prologue.11
@@ -0,0 +1,4 @@
+.Dd $Mdocdate$
+.Dt test
+.Os
+.Sh NAME
diff --git a/regress/test.prologue.12 b/regress/test.prologue.12
new file mode 100644
index 00000000..3a789b0d
--- /dev/null
+++ b/regress/test.prologue.12
@@ -0,0 +1,4 @@
+.Dd $Mdocdate$
+.Dt test 1
+.Os
+.Sh NAME
diff --git a/regress/test.prologue.13 b/regress/test.prologue.13
new file mode 100644
index 00000000..8ba7f29b
--- /dev/null
+++ b/regress/test.prologue.13
@@ -0,0 +1,4 @@
+.Dd $Mdocdate$
+.Dt test 0
+.Os
+.Sh NAME
diff --git a/regress/test.prologue.14 b/regress/test.prologue.14
new file mode 100644
index 00000000..4cdda822
--- /dev/null
+++ b/regress/test.prologue.14
@@ -0,0 +1,4 @@
+.Dd $Mdocdate$
+.Dt test 1 alpha
+.Os
+.Sh NAME
diff --git a/regress/test.prologue.15 b/regress/test.prologue.15
new file mode 100644
index 00000000..bf94017a
--- /dev/null
+++ b/regress/test.prologue.15
@@ -0,0 +1,4 @@
+.Dd $Mdocdate$
+.Dt test 0 alfalfa
+.Os
+.Sh NAME
diff --git a/regress/test.prologue.16 b/regress/test.prologue.16
new file mode 100644
index 00000000..447652b7
--- /dev/null
+++ b/regress/test.prologue.16
@@ -0,0 +1,4 @@
+.Dd $Mdocdate$
+.Dt test alpha
+.Os
+.Sh NAME
diff --git a/regress/test.prologue.17 b/regress/test.prologue.17
new file mode 100644
index 00000000..6636c2bf
--- /dev/null
+++ b/regress/test.prologue.17
@@ -0,0 +1,4 @@
+.Dd $Mdocdate$
+.Dt test 1 AMD
+.Os
+.Sh NAME
diff --git a/regress/test.prologue.18 b/regress/test.prologue.18
new file mode 100644
index 00000000..d3a14f87
--- /dev/null
+++ b/regress/test.prologue.18
@@ -0,0 +1,4 @@
+.Dd $Mdocdate$
+.Dt test AMD
+.Os
+.Sh NAME
diff --git a/regress/test.prologue.19 b/regress/test.prologue.19
new file mode 100644
index 00000000..78d319b1
--- /dev/null
+++ b/regress/test.prologue.19
@@ -0,0 +1,3 @@
+.Dd $Mdocdate$
+.Dt test 1 AMD
+.Os
diff --git a/regress/test.prologue.20 b/regress/test.prologue.20
new file mode 100644
index 00000000..640d4e32
--- /dev/null
+++ b/regress/test.prologue.20
@@ -0,0 +1,4 @@
+.Dd $Mdocdate$
+.Dt test\ 1 1 AMD
+.Os
+.Sh NAME
diff --git a/regress/test.prologue.21 b/regress/test.prologue.21
new file mode 100644
index 00000000..0bcb5cc3
--- /dev/null
+++ b/regress/test.prologue.21
@@ -0,0 +1,4 @@
+.Dd $Mdocdate$
+.Dt test\ 1 1 AMD\
+.Os
+.Sh NAME
diff --git a/regress/test.prologue.22 b/regress/test.prologue.22
new file mode 100644
index 00000000..3467f490
--- /dev/null
+++ b/regress/test.prologue.22
@@ -0,0 +1,4 @@
+.Dd $Mdocdate$
+.Dt test 1 ;
+.Os
+.Sh NAME
diff --git a/regress/test.prologue.23 b/regress/test.prologue.23
new file mode 100644
index 00000000..cacd8fbf
--- /dev/null
+++ b/regress/test.prologue.23
@@ -0,0 +1,4 @@
+.Dd $Mdocdate$ ;
+.Dt test 1
+.Os
+.Sh NAME
diff --git a/regress/test.prologue.24 b/regress/test.prologue.24
new file mode 100644
index 00000000..15111dd3
--- /dev/null
+++ b/regress/test.prologue.24
@@ -0,0 +1,4 @@
+.Dd $Mdocdate$ ;
+.Dt test "1"
+.Os
+.Sh NAME
diff --git a/strings.c b/strings.c
index 631243e6..c07e6909 100644
--- a/strings.c
+++ b/strings.c
@@ -124,12 +124,18 @@ time_t
mdoc_atotime(const char *p)
{
struct tm tm;
+ char *pp;
(void)memset(&tm, 0, sizeof(struct tm));
- if (0 == strptime(p, "%b %d %Y", &tm))
+ if (xstrcmp(p, "$Mdocdate$"))
+ return(time(NULL));
+ if ((pp = strptime(p, "$Mdocdate$", &tm)) && 0 == *pp)
return(mktime(&tm));
- if (0 == strptime(p, "%b %d, %Y", &tm))
+ /* XXX - this matches "June 1999", which is wrong. */
+ if ((pp = strptime(p, "%b %d %Y", &tm)) && 0 == *pp)
+ return(mktime(&tm));
+ if ((pp = strptime(p, "%b %d, %Y", &tm)) && 0 == *pp)
return(mktime(&tm));
return(0);
diff --git a/xstd.c b/xstd.c
index b5820d70..a7262a61 100644
--- a/xstd.c
+++ b/xstd.c
@@ -33,6 +33,14 @@ extern size_t strlcat(char *, const char *, size_t);
extern size_t strlcpy(char *, const char *, size_t);
#endif
+
+int
+xstrncmp(const char *p1, const char *p2, size_t sz)
+{
+
+ return(0 == strncmp(p1, p2, sz));
+}
+
int
xstrcmp(const char *p1, const char *p2)
{