From d286305c5d6ecdd0f3ae341a607819738139f1ec Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Sat, 17 Jan 2009 16:47:02 +0000 Subject: Added tests to makefile. --- Makefile | 20 ++++++++ action.c | 46 ++++++++---------- validate.c | 156 ++++++++++++++++++++++++++++++++++++++----------------------- 3 files changed, 136 insertions(+), 86 deletions(-) diff --git a/Makefile b/Makefile index b0fcf0a3..1d14a893 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,20 @@ BINS = mdocml CLEAN = $(BINS) $(LNS) $(LLNS) $(LIBS) $(OBJS) +SUCCESS = test.1 test.7 test.8 test.9 test.11 test.11 test.12 test.16 \ + test.17 test.19 test.20 test.21 test.23 test.25 test.27 \ + test.28 test.29 test.31 test.32 test.33 test.34 test.35 \ + test.38 test.39 test.40 test.41 test.42 test.43 test.44 \ + test.45 test.46 test.47 test.49 test.51 test.52 test.53 \ + test.54 test.55 test.56 test.57 test.58 test.59 test.60 \ + test.62 test.67 test.68 test.71 test.72 test.73 test.74 \ + test.75 + +FAIL = test.0 test.2 test.3 test.4 test.5 test.6 test.13 test.14 \ + test.15 test.18 test.22 test.24 test.26 test.30 test.36 \ + test.37 test.48 test.50 test.61 test.63 test.64 test.65 \ + test.66 test.69 test.70 + all: $(BINS) lint: $(LLNS) @@ -28,6 +42,12 @@ mdocml: mdocml.o tree.o libmdoc.a clean: rm -f $(CLEAN) +regress: mdocml $(SUCCESS) $(FAIL) + @for f in $(SUCCESS) ; do \ + echo "./mdocml $$f" ; \ + ./mdocml $$f || exit 1 ; \ + done + llib-llibmdoc.ln: macro.ln mdoc.ln hash.ln strings.ln xstd.ln argv.ln validate.ln action.ln $(LINT) $(LINTFLAGS) -Clibmdoc mdoc.ln macro.ln hash.ln strings.ln xstd.ln argv.ln validate.ln action.ln diff --git a/action.c b/action.c index 1fdd513e..554fad58 100644 --- a/action.c +++ b/action.c @@ -1,4 +1,4 @@ -/* $Id: action.c,v 1.10 2009/01/17 16:15:27 kristaps Exp $ */ +/* $Id: action.c,v 1.11 2009/01/17 16:47:02 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -27,6 +27,7 @@ struct actions { int (*post)(struct mdoc *); }; +/* Per-macro action routines. */ static int post_sh(struct mdoc *); static int post_os(struct mdoc *); @@ -34,6 +35,8 @@ static int post_dt(struct mdoc *); static int post_dd(struct mdoc *); static int post_nm(struct mdoc *); +/* Array of macro action routines. */ + const struct actions mdoc_actions[MDOC_MAX] = { { NULL }, /* \" */ { post_dd }, /* Dd */ @@ -155,12 +158,12 @@ post_nm(struct mdoc *mdoc) if (mdoc->meta.name) return(1); - if ( ! xstrlcats(buf, mdoc->last->child, 64)) - return(mdoc_err(mdoc, "macro parameters too long")); + if (xstrlcats(buf, mdoc->last->child, 64)) { + mdoc->meta.name = xstrdup(buf); + return(1); + } - mdoc->meta.name = xstrdup(buf); - mdoc_msg(mdoc, "parsed name: %s", mdoc->meta.name); - return(1); + return(mdoc_err(mdoc, "macro parameters too long")); } @@ -172,14 +175,14 @@ post_sh(struct mdoc *mdoc) if (MDOC_HEAD != mdoc->last->type) return(1); - if ( ! xstrlcats(buf, mdoc->last->child, 64)) - return(mdoc_err(mdoc, "macro parameters too long")); - - if (SEC_CUSTOM != (sec = mdoc_atosec(buf))) - mdoc->sec_lastn = sec; - mdoc->sec_last = sec; + if (xstrlcats(buf, mdoc->last->child, 64)) { + if (SEC_CUSTOM != (sec = mdoc_atosec(buf))) + mdoc->sec_lastn = sec; + mdoc->sec_last = sec; + return(1); + } - return(1); + return(mdoc_err(mdoc, "macro parameters too long")); } @@ -223,9 +226,6 @@ post_dt(struct mdoc *mdoc) if (NULL == mdoc->meta.title) mdoc->meta.title = xstrdup("untitled"); - - mdoc_msg(mdoc, "parsed title: %s", mdoc->meta.title); - /* TODO: print vol2a functions. */ return(1); } @@ -243,7 +243,6 @@ post_os(struct mdoc *mdoc) return(mdoc_err(mdoc, "macro parameters too long")); mdoc->meta.os = xstrdup(buf[0] ? buf : "local"); - mdoc_msg(mdoc, "parsed operating system: %s", mdoc->meta.os); mdoc->sec_lastn = mdoc->sec_last = SEC_BODY; return(1); } @@ -285,19 +284,12 @@ post_dd(struct mdoc *mdoc) return(mdoc_nerr(mdoc, n, "invalid parameter syntax")); } - if (mdoc->meta.date && NULL == n) { - mdoc_msg(mdoc, "parsed time: %u since epoch", - mdoc->meta.date); + if (mdoc->meta.date && NULL == n) return(1); - } else if (n) + else if (n) return(mdoc_err(mdoc, "invalid parameter syntax")); - - if ((mdoc->meta.date = mdoc_atotime(date))) { - mdoc_msg(mdoc, "parsed time: %u since epoch", - mdoc->meta.date); + if ((mdoc->meta.date = mdoc_atotime(date))) return(1); - } - return(mdoc_err(mdoc, "invalid parameter syntax")); } diff --git a/validate.c b/validate.c index 70b15b32..95ca922a 100644 --- a/validate.c +++ b/validate.c @@ -1,4 +1,4 @@ -/* $Id: validate.c,v 1.36 2009/01/17 16:15:27 kristaps Exp $ */ +/* $Id: validate.c,v 1.37 2009/01/17 16:47:02 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -21,20 +21,22 @@ #include "private.h" - typedef int (*v_pre)(struct mdoc *, struct mdoc_node *); typedef int (*v_post)(struct mdoc *); - /* FIXME: some sections should only occur in specific msecs. */ /* FIXME: ignoring Pp. */ /* FIXME: math symbols. */ +/* FIXME: make sure prologue is complete. */ +/* FIXME: valid character-escape checks. */ struct valids { v_pre *pre; v_post *post; }; +/* Utility checks. */ + static int pre_check_parent(struct mdoc *, struct mdoc_node *, int, enum mdoc_type); static int pre_check_msecs(struct mdoc *, struct mdoc_node *, @@ -45,6 +47,8 @@ static int post_check_children_lt(struct mdoc *, int); static int post_check_children_gt(struct mdoc *, int); static int post_check_children_eq(struct mdoc *, int); +/* Specific pre-child-parse routines. */ + static int pre_display(struct mdoc *, struct mdoc_node *); static int pre_sh(struct mdoc *, struct mdoc_node *); static int pre_ss(struct mdoc *, struct mdoc_node *); @@ -61,19 +65,21 @@ static int pre_prologue(struct mdoc *, struct mdoc_node *); static int pre_prologue(struct mdoc *, struct mdoc_node *); static int pre_prologue(struct mdoc *, struct mdoc_node *); -static int head_err_ge1(struct mdoc *); -static int head_warn_ge1(struct mdoc *); -static int head_err_eq0(struct mdoc *); -static int elem_err_eq0(struct mdoc *); -static int elem_err_le1(struct mdoc *); -static int elem_err_le2(struct mdoc *); -static int elem_err_eq1(struct mdoc *); -static int elem_err_ge1(struct mdoc *); -static int elem_warn_eq0(struct mdoc *); -static int body_warn_ge1(struct mdoc *); -static int body_err_eq0(struct mdoc *); -static int elem_warn_ge1(struct mdoc *); -static int elem_bool(struct mdoc *); +/* Specific post-child-parse routines. */ + +static int herr_ge1(struct mdoc *); +static int hwarn_ge1(struct mdoc *); +static int herr_eq0(struct mdoc *); +static int eerr_eq0(struct mdoc *); +static int eerr_le1(struct mdoc *); +static int eerr_le2(struct mdoc *); +static int eerr_eq1(struct mdoc *); +static int eerr_ge1(struct mdoc *); +static int ewarn_eq0(struct mdoc *); +static int bwarn_ge1(struct mdoc *); +static int berr_eq0(struct mdoc *); +static int ewarn_ge1(struct mdoc *); +static int ebool(struct mdoc *); static int post_sh(struct mdoc *); static int post_bl(struct mdoc *); static int post_it(struct mdoc *); @@ -81,6 +87,10 @@ static int post_ex(struct mdoc *); static int post_an(struct mdoc *); static int post_at(struct mdoc *); static int post_xr(struct mdoc *); +static int post_nm(struct mdoc *); +static int post_root(struct mdoc *); + +/* Collections of pre-child-parse routines. */ static v_pre pres_prologue[] = { pre_prologue, NULL }; static v_pre pres_d1[] = { pre_display, NULL }; @@ -96,26 +106,27 @@ static v_pre pres_rv[] = { pre_rv, NULL }; static v_pre pres_an[] = { pre_an, NULL }; static v_pre pres_st[] = { pre_st, NULL }; -static v_post posts_bool[] = { elem_err_eq1, elem_bool, NULL }; -static v_post posts_bd[] = { head_err_eq0, body_warn_ge1, NULL }; -static v_post posts_text[] = { elem_err_ge1, NULL }; -static v_post posts_wtext[] = { elem_warn_ge1, NULL }; -static v_post posts_notext[] = { elem_err_eq0, NULL }; -static v_post posts_wline[] = { head_warn_ge1, body_err_eq0, NULL }; -static v_post posts_sh[] = { head_err_ge1, - body_warn_ge1, post_sh, NULL }; -static v_post posts_bl[] = { head_err_eq0, - body_warn_ge1, post_bl, NULL }; +/* Collections of post-child-parse routines. */ + +static v_post posts_bool[] = { eerr_eq1, ebool, NULL }; +static v_post posts_bd[] = { herr_eq0, bwarn_ge1, NULL }; +static v_post posts_text[] = { eerr_ge1, NULL }; +static v_post posts_wtext[] = { ewarn_ge1, NULL }; +static v_post posts_notext[] = { eerr_eq0, NULL }; +static v_post posts_wline[] = { hwarn_ge1, berr_eq0, NULL }; +static v_post posts_sh[] = { herr_ge1, bwarn_ge1, post_sh, NULL }; +static v_post posts_bl[] = { herr_eq0, bwarn_ge1, post_bl, NULL }; static v_post posts_it[] = { post_it, NULL }; -static v_post posts_ss[] = { head_err_ge1, NULL }; -static v_post posts_pp[] = { elem_warn_eq0, NULL }; -static v_post posts_d1[] = { head_err_ge1, NULL }; -static v_post posts_ex[] = { elem_err_le1, post_ex, NULL }; +static v_post posts_ss[] = { herr_ge1, NULL }; +static v_post posts_pp[] = { ewarn_eq0, NULL }; +static v_post posts_d1[] = { herr_ge1, NULL }; +static v_post posts_ex[] = { eerr_le1, post_ex, NULL }; static v_post posts_an[] = { post_an, NULL }; -static v_post posts_at[] = { elem_err_eq1, post_at, NULL }; -static v_post posts_xr[] = { elem_err_ge1, elem_err_le2, - post_xr, NULL }; +static v_post posts_at[] = { post_at, NULL }; +static v_post posts_xr[] = { eerr_ge1, eerr_le2, post_xr, NULL }; +static v_post posts_nm[] = { post_nm, NULL }; +/* Per-macro pre- and post-child-check routine collections. */ const struct valids mdoc_valids[MDOC_MAX] = { { NULL, NULL }, /* \" */ @@ -152,8 +163,7 @@ const struct valids mdoc_valids[MDOC_MAX] = { { NULL, posts_wtext }, /* In */ { NULL, posts_text }, /* Li */ { NULL, posts_wtext }, /* Nd */ - /* FIXME: check that name must be set/provided. */ - { NULL, NULL }, /* Nm */ + { NULL, posts_nm }, /* Nm */ { NULL, posts_wline }, /* Op */ { NULL, NULL }, /* Ot */ { NULL, NULL }, /* Pa */ @@ -300,8 +310,8 @@ pre_check_msecs(struct mdoc *mdoc, struct mdoc_node *node, for (i = 0; i < sz; i++) if (msecs[i] == mdoc->meta.msec) return(1); - return(mdoc_nwarn(mdoc, node, WARN_COMPAT, - "macro is not appropriate for this manual section")); + return(mdoc_nwarn(mdoc, node, WARN_COMPAT, "macro not " + "appropriate for manual section")); } @@ -323,7 +333,7 @@ pre_check_parent(struct mdoc *mdoc, struct mdoc_node *node, static int -body_err_eq0(struct mdoc *mdoc) +berr_eq0(struct mdoc *mdoc) { if (MDOC_BODY != mdoc->last->type) @@ -335,7 +345,7 @@ body_err_eq0(struct mdoc *mdoc) static int -body_warn_ge1(struct mdoc *mdoc) +bwarn_ge1(struct mdoc *mdoc) { if (MDOC_BODY != mdoc->last->type) @@ -347,7 +357,7 @@ body_warn_ge1(struct mdoc *mdoc) static int -elem_warn_eq0(struct mdoc *mdoc) +ewarn_eq0(struct mdoc *mdoc) { assert(MDOC_ELEM == mdoc->last->type); @@ -359,7 +369,7 @@ elem_warn_eq0(struct mdoc *mdoc) static int -elem_warn_ge1(struct mdoc *mdoc) +ewarn_ge1(struct mdoc *mdoc) { assert(MDOC_ELEM == mdoc->last->type); @@ -370,7 +380,7 @@ elem_warn_ge1(struct mdoc *mdoc) static int -elem_err_eq1(struct mdoc *mdoc) +eerr_eq1(struct mdoc *mdoc) { assert(MDOC_ELEM == mdoc->last->type); @@ -379,7 +389,7 @@ elem_err_eq1(struct mdoc *mdoc) static int -elem_err_le2(struct mdoc *mdoc) +eerr_le2(struct mdoc *mdoc) { assert(MDOC_ELEM == mdoc->last->type); @@ -388,7 +398,7 @@ elem_err_le2(struct mdoc *mdoc) static int -elem_err_le1(struct mdoc *mdoc) +eerr_le1(struct mdoc *mdoc) { assert(MDOC_ELEM == mdoc->last->type); @@ -397,7 +407,7 @@ elem_err_le1(struct mdoc *mdoc) static int -elem_err_eq0(struct mdoc *mdoc) +eerr_eq0(struct mdoc *mdoc) { assert(MDOC_ELEM == mdoc->last->type); @@ -406,7 +416,7 @@ elem_err_eq0(struct mdoc *mdoc) static int -elem_err_ge1(struct mdoc *mdoc) +eerr_ge1(struct mdoc *mdoc) { assert(MDOC_ELEM == mdoc->last->type); @@ -415,7 +425,7 @@ elem_err_ge1(struct mdoc *mdoc) static int -head_err_eq0(struct mdoc *mdoc) +herr_eq0(struct mdoc *mdoc) { if (MDOC_HEAD != mdoc->last->type) @@ -425,7 +435,7 @@ head_err_eq0(struct mdoc *mdoc) static int -head_warn_ge1(struct mdoc *mdoc) +hwarn_ge1(struct mdoc *mdoc) { if (MDOC_HEAD != mdoc->last->type) @@ -437,7 +447,7 @@ head_warn_ge1(struct mdoc *mdoc) static int -head_err_ge1(struct mdoc *mdoc) +herr_ge1(struct mdoc *mdoc) { if (MDOC_HEAD != mdoc->last->type) @@ -726,6 +736,21 @@ pre_prologue(struct mdoc *mdoc, struct mdoc_node *node) } +static int +post_nm(struct mdoc *mdoc) +{ + + assert(MDOC_ELEM == mdoc->last->type); + assert(MDOC_Nm == mdoc->last->tok); + if (mdoc->last->child) + return(1); + if (mdoc->meta.name) + return(1); + return(mdoc_err(mdoc, "macro `%s' has not been invoked with a name", + mdoc_macronames[MDOC_Nm])); +} + + static int post_xr(struct mdoc *mdoc) { @@ -751,7 +776,9 @@ post_at(struct mdoc *mdoc) assert(MDOC_ELEM == mdoc->last->type); assert(MDOC_At == mdoc->last->tok); - assert(mdoc->last->child); + + if (NULL == mdoc->last->child) + return(1); assert(MDOC_TEXT == mdoc->last->child->type); if (ATT_DEFAULT != mdoc_atoatt(mdoc->last->child->data.text.string)) @@ -919,7 +946,6 @@ post_it(struct mdoc *mdoc) } -/* Make sure that only `It' macros are our body-children. */ static int post_bl(struct mdoc *mdoc) { @@ -942,7 +968,7 @@ post_bl(struct mdoc *mdoc) static int -elem_bool(struct mdoc *mdoc) +ebool(struct mdoc *mdoc) { struct mdoc_node *n; @@ -958,7 +984,23 @@ elem_bool(struct mdoc *mdoc) } if (NULL == n) return(1); - return(mdoc_nerr(mdoc, n, "expected boolean value [on/off]")); + return(mdoc_nerr(mdoc, n, "expected boolean value")); +} + + +static int +post_root(struct mdoc *mdoc) +{ + + if (NULL == mdoc->last->child) + return(mdoc_err(mdoc, "document has no data")); + if (NULL == mdoc->meta.title) + return(mdoc_err(mdoc, "document has no incomplete prologue")); + if (NULL == mdoc->meta.os) + return(mdoc_err(mdoc, "document has no incomplete prologue")); + if (0 == mdoc->meta.date) + return(mdoc_err(mdoc, "document has no incomplete prologue")); + return(1); } @@ -991,8 +1033,6 @@ mdoc_valid_pre(struct mdoc *mdoc, struct mdoc_node *node) { v_pre *p; - /* TODO: character-escape checks. */ - if (MDOC_TEXT == node->type) return(1); assert(MDOC_ROOT != node->type); @@ -1013,10 +1053,8 @@ mdoc_valid_post(struct mdoc *mdoc) if (MDOC_TEXT == mdoc->last->type) return(1); - if (MDOC_ROOT == mdoc->last->type) { - /* TODO: make sure prologue is complete. */ - return(1); - } + if (MDOC_ROOT == mdoc->last->type) + return(post_root(mdoc)); if (NULL == mdoc_valids[mdoc->last->tok].post) return(1); -- cgit v1.2.3-56-ge451