From 113077ce00c372c7085f94f07eaa27a214f8f90a Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sat, 26 May 2007 10:26:38 +0200 Subject: [PATCH 1/7] Revert "Refactor test-sgml-parser-basic to work with non-bash shells" This reverts commit 3f93148c9b131069aa5ee8b655652da40e1a4b70. --- src/dom/test/test-sgml-parser-basic | 37 ++++++++++------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/src/dom/test/test-sgml-parser-basic b/src/dom/test/test-sgml-parser-basic index 791bbf4a9..fc8e45e6b 100755 --- a/src/dom/test/test-sgml-parser-basic +++ b/src/dom/test/test-sgml-parser-basic @@ -11,28 +11,18 @@ correctly in the DOM tree. . "$TEST_LIB" -test_output_equals_file () { - desc="$1"; shift - src="$1"; shift - file="$1"; shift - - URI="test:$(normalize "$desc")" - - sgml-parser --uri "$URI" --src "$src" > output - echo "#document: $URI" > expected - sed 's/^/ /' < "$file" >> expected - - test_expect_success "$desc" 'cmp output expected' -} - test_output_equals () { desc="$1"; shift src="$1"; shift out="$1"; shift - echo "$out" | sed -n '2,$p' > expected+ + URI="test:$(normalize "$desc")" - test_output_equals_file "$desc" "$src" "expected+" + sgml-parser --uri "$URI" --src "$src" > output + echo "#document: $URI" > expected + echo "$out" | sed -n '2,$p' | sed 's/^/ /' >> expected + + test_expect_success "$desc" 'cmp output expected' } @@ -194,21 +184,18 @@ entity-reference: # #text: - entity-reference: #xx' -cat > expected2 < encoding="UTF8" - attribute: encoding -> UTF8 -#text: \\n...\\n -proc-instruction: ecmascript -> var val=2;\\n -EOF - -test_output_equals_file \ +test_output_equals \ 'Parse processing instructions.' \ ' ... ' \ -expected2 +' +proc-instruction: xml -> encoding="UTF8" + attribute: encoding -> UTF8 +#text: \n...\n +proc-instruction: ecmascript -> var val=2;\n' test_output_equals \ 'Parse XML processing instructions.' \ From 17a76257f8c6f8228eac9d6698c76ed2969ea8b2 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sat, 26 May 2007 10:42:51 +0200 Subject: [PATCH 2/7] Use printf to handle test string containing escapes more portable Works with both bash and dash. This reintroduces the fix to the test-sgml-parser-basic test, and also fixes test-sgml-parser-incremental and test-sgml-parser-lines, which Witek has reported as failing. --- src/dom/test/test-sgml-parser-basic | 2 +- src/dom/test/test-sgml-parser-incremental | 4 ++-- src/dom/test/test-sgml-parser-lines | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/dom/test/test-sgml-parser-basic b/src/dom/test/test-sgml-parser-basic index fc8e45e6b..4671b97ff 100755 --- a/src/dom/test/test-sgml-parser-basic +++ b/src/dom/test/test-sgml-parser-basic @@ -20,7 +20,7 @@ test_output_equals () { sgml-parser --uri "$URI" --src "$src" > output echo "#document: $URI" > expected - echo "$out" | sed -n '2,$p' | sed 's/^/ /' >> expected + printf "%s\n" "$out" | sed -n '2,$p' | sed 's/^/ /' >> expected test_expect_success "$desc" 'cmp output expected' } diff --git a/src/dom/test/test-sgml-parser-incremental b/src/dom/test/test-sgml-parser-incremental index 81038b834..291884705 100755 --- a/src/dom/test/test-sgml-parser-incremental +++ b/src/dom/test/test-sgml-parser-incremental @@ -19,10 +19,10 @@ test_incremental_parsing () { URI="test:$(normalize "$desc")" echo "#document: $URI" > expected - echo "$out" | sed -n '2,$p' | sed -e 's/^/ /' >> expected + printf "%s\n" "$out" | sed -n '2,$p' | sed -e 's/^/ /' >> expected for size in 1 2 3 4 5 6 7 8 9 10 15 20 25 50; do - echo -n "$src" | sgml-parser --uri "$URI" --stdin "$size" > output + printf "%s" "$src" | sgml-parser --uri "$URI" --stdin "$size" > output test_run_ 'cmp output expected' if [ "$?" != 0 -o "$eval_ret" != 0 ] diff --git a/src/dom/test/test-sgml-parser-lines b/src/dom/test/test-sgml-parser-lines index 6c0c71e11..d5a67889a 100755 --- a/src/dom/test/test-sgml-parser-lines +++ b/src/dom/test/test-sgml-parser-lines @@ -55,10 +55,10 @@ test_output_line_numbers \ 7 8' \ 8 - + test_output_line_numbers \ 'Check line numbers. (IIII)' \ -$'1\r\f 2\v\n 3\r\n 4\t\f 5' \ +"$(printf "1\r\f 2\v\n 3\r\n 4\t\f 5")" \ 5 - + test_done From ad6addbd92b651a330c736742a3666c184197a1c Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sat, 26 May 2007 12:40:06 +0200 Subject: [PATCH 3/7] DOM test: refactor options parsing in sgml-parser Introduce get_opt() to do the tedious work of getting the right argument for options expecting them and handles both '--opt=arg' and '--opt arg'. As a side effect it also removes an unneeded assignment of the source string for stdin. --- src/dom/test/sgml-parser.c | 74 ++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 44 deletions(-) diff --git a/src/dom/test/sgml-parser.c b/src/dom/test/sgml-parser.c index 2afa7c6b1..b39d1c78b 100644 --- a/src/dom/test/sgml-parser.c +++ b/src/dom/test/sgml-parser.c @@ -256,6 +256,29 @@ void die(const char *msg, ...) exit(!!NULL); } +static int +get_opt(char **argref, const char *name, int *argi, int argc, char *argv[], + const char *expect_msg) +{ + char *arg = *argref; + int namelen = strlen(name); + + if (strncmp(arg, name, namelen)) + return 0; + + arg += namelen; + if (*arg == '=') { + (*argref) = arg + 1; + } else { + (*argi)++; + if ((*argi) >= argc) + die("--%s expects %s", name, expect_msg); + (*argref) = argv[(*argi)]; + } + + return 1; +} + int main(int argc, char *argv[]) { @@ -281,54 +304,17 @@ main(int argc, char *argv[]) arg += 2; - if (!strncmp(arg, "uri", 3)) { - arg += 3; - if (*arg == '=') { - arg++; - set_dom_string(&uri, arg, strlen(arg)); - } else { - i++; - if (i >= argc) - die("--uri expects a URI"); - set_dom_string(&uri, argv[i], strlen(argv[i])); - } + if (get_opt(&arg, "uri", &i, argc, argv, "a URI")) { + set_dom_string(&uri, arg, strlen(arg)); - } else if (!strncmp(arg, "src", 3)) { - arg += 3; - if (*arg == '=') { - arg++; - set_dom_string(&source, arg, strlen(arg)); - } else { - i++; - if (i >= argc) - die("--src expects a string"); - set_dom_string(&source, argv[i], strlen(argv[i])); - } + } else if (get_opt(&arg, "src", &i, argc, argv, "a string")) { + set_dom_string(&source, arg, strlen(arg)); - } else if (!strncmp(arg, "stdin", 5)) { - arg += 5; - if (*arg == '=') { - arg++; - read_stdin = atoi(arg); - set_dom_string(&source, arg, strlen(arg)); - } else { - i++; - if (i >= argc) - die("--stdin expects a number"); - read_stdin = atoi(argv[i]); - } + } else if (get_opt(&arg, "stdin", &i, argc, argv, "a number")) { + read_stdin = atoi(arg); flags |= SGML_PARSER_INCREMENTAL; - } else if (!strncmp(arg, "normalize", 9)) { - arg += 9; - if (*arg == '=') { - arg++; - } else { - i++; - if (i >= argc) - die("--normalize expects a string"); - arg = argv[i]; - } + } else if (get_opt(&arg, "normalize", &i, argc, argv, "a string")) { normalize = 1; normalize_flags = parse_dom_config(arg, ','); type = SGML_PARSER_TREE; From 67188584eae89a62c60cc775d37fe2b8decf4ae7 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sat, 26 May 2007 13:08:03 +0200 Subject: [PATCH 4/7] DOM test: make die() in sgml-parser static --- src/dom/test/sgml-parser.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dom/test/sgml-parser.c b/src/dom/test/sgml-parser.c index b39d1c78b..5446ccd7a 100644 --- a/src/dom/test/sgml-parser.c +++ b/src/dom/test/sgml-parser.c @@ -242,7 +242,8 @@ sgml_error_function(struct sgml_parser *parser, struct dom_string *string, return DOM_CODE_OK; } -void die(const char *msg, ...) +static void +die(const char *msg, ...) { va_list args; From 56f692ef08d9b110476ceb4766cedc63a5a800d3 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sat, 26 May 2007 13:10:55 +0200 Subject: [PATCH 5/7] DOM test: add test/ to SUBDIRS so DOM test is run for 'make test' --- src/dom/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dom/Makefile b/src/dom/Makefile index cdff0bab3..e86f3433e 100644 --- a/src/dom/Makefile +++ b/src/dom/Makefile @@ -1,7 +1,7 @@ top_builddir=../.. include $(top_builddir)/Makefile.config -SUBDIRS = css sgml +SUBDIRS = css sgml test OBJS = configuration.o node.o select.o stack.o scanner.o SUBDIRS-$(CONFIG_DEBUG) += test From 8bfab2242e268c0b52ea530ce282caa1ca9d0486 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sat, 26 May 2007 13:43:37 +0200 Subject: [PATCH 6/7] Fix 'make test' dependency when building test utility programs Problems was caused by undefined symbols: src/util/conv.c:308: undefined reference to `is_cp_utf8' src/util/conv.c:320: undefined reference to `cp2u' --- Makefile.config.in | 4 ++++ src/mime/backend/Makefile | 4 ++++ src/protocol/ftp/Makefile | 7 ++++++- src/util/Makefile | 4 ---- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Makefile.config.in b/Makefile.config.in index b6802b174..2426ddf8f 100644 --- a/Makefile.config.in +++ b/Makefile.config.in @@ -182,6 +182,10 @@ MAKE_COLOR = @MAKE_COLOR@ LIB_O_NAME = lib.o +# Reverse a CONFIG_* string +# Usage $(call not,$(CONFIG_FOO)) +not = $(if $(findstring yes,$(1)),no,yes) + ### This is here because Makefile.config is usually the first thing ### we get and sometimes the all rule can be implicit, yet we want ### it always as the default one. So this should make sure it always diff --git a/src/mime/backend/Makefile b/src/mime/backend/Makefile index 909bf1dd3..10582421d 100644 --- a/src/mime/backend/Makefile +++ b/src/mime/backend/Makefile @@ -16,6 +16,7 @@ mailcap-cache.o: mailcap.c TESTDEPS = \ common.o \ + $(top_builddir)/src/intl/charsets.o \ $(top_builddir)/src/osdep/osdep.o \ $(top_builddir)/src/osdep/stub.o \ $(top_builddir)/src/util/conv.o \ @@ -28,5 +29,8 @@ TESTDEPS = \ TESTDEPS-$(CONFIG_NLS) += $(top_builddir)/src/intl/gettext/lib.o TESTDEPS-$(CONFIG_DEBUG) += $(top_builddir)/src/util/memdebug.o +TESTDEPS-$(call not,$(CONFIG_SMALL)) += \ + $(top_builddir)/src/util/fastfind.o \ + include $(top_srcdir)/Makefile.lib diff --git a/src/protocol/ftp/Makefile b/src/protocol/ftp/Makefile index 115744b79..cd805b623 100644 --- a/src/protocol/ftp/Makefile +++ b/src/protocol/ftp/Makefile @@ -3,9 +3,11 @@ include $(top_builddir)/Makefile.config OBJS = ftp.o parse.o -TEST_PROGS = ftp-parser +TEST_PROGS = \ + ftp-parser TESTDEPS = \ + $(top_builddir)/src/intl/charsets.o \ $(top_builddir)/src/osdep/stub.o \ $(top_builddir)/src/protocol/date.o \ $(top_builddir)/src/protocol/ftp/parse.o \ @@ -16,4 +18,7 @@ TESTDEPS = \ $(top_builddir)/src/util/string.o \ $(top_builddir)/src/util/time.o +TESTDEPS-$(call not,$(CONFIG_SMALL)) += \ + $(top_builddir)/src/util/fastfind.o \ + include $(top_srcdir)/Makefile.lib diff --git a/src/util/Makefile b/src/util/Makefile index 9c3f47a82..17b032276 100644 --- a/src/util/Makefile +++ b/src/util/Makefile @@ -3,10 +3,6 @@ include $(top_builddir)/Makefile.config INCLUDES += $(GNUTLS_CFLAGS) $(OPENSSL_CFLAGS) -# Reverse a CONFIG_* string -# Usage $(call not,$(CONFIG_FOO)) -not = $(if $(findstring yes,$(1)),no,yes) - OBJS-$(call not,$(CONFIG_SMALL)) += fastfind.o OBJS-$(CONFIG_CSS) += scanner.o OBJS-$(CONFIG_DEBUG) += memdebug.o From ba66ff37db59493eecd8d4bf0675df837b31b679 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sat, 26 May 2007 14:04:29 +0200 Subject: [PATCH 7/7] Simplify TESTDEPS maintainance by adding common objects in Makefile.lib --- Makefile.lib | 15 +++++++++++++++ src/dom/test/Makefile | 7 +------ src/mime/backend/Makefile | 15 +-------------- src/protocol/ftp/Makefile | 13 +------------ 4 files changed, 18 insertions(+), 32 deletions(-) diff --git a/Makefile.lib b/Makefile.lib index 3dd693845..96c851858 100644 --- a/Makefile.lib +++ b/Makefile.lib @@ -191,6 +191,21 @@ test-default: ifdef TEST_PROGS TESTDEPS-$(CONFIG_DEBUG) += $(top_builddir)/src/util/memdebug.o +TESTDEPS-$(call not,$(CONFIG_SMALL)) += \ + $(top_builddir)/src/util/fastfind.o \ + +# Add most of the basic utility library to the test dependencies. +TESTDEPS += \ + $(top_builddir)/src/intl/charsets.o \ + $(top_builddir)/src/osdep/stub.o \ + $(top_builddir)/src/util/conv.o \ + $(top_builddir)/src/util/error.o \ + $(top_builddir)/src/util/file.o \ + $(top_builddir)/src/util/hash.o \ + $(top_builddir)/src/util/memory.o \ + $(top_builddir)/src/util/string.o \ + $(top_builddir)/src/util/time.o + TESTDEPS += $(TESTDEPS-yes) TEST_LIB=$(top_srcdir)/test/libtest.sh diff --git a/src/dom/test/Makefile b/src/dom/test/Makefile index 27ae7afe6..0fd3a89f1 100644 --- a/src/dom/test/Makefile +++ b/src/dom/test/Makefile @@ -8,11 +8,6 @@ TEST_PROGS = \ sgml-parser TESTDEPS = \ - $(top_builddir)/src/dom/$(LIB_O_NAME) \ - $(top_builddir)/src/util/error.o \ - $(top_builddir)/src/osdep/stub.o \ - $(top_builddir)/src/util/hash.o \ - $(top_builddir)/src/util/string.o \ - $(top_builddir)/src/util/memory.o + $(top_builddir)/src/dom/$(LIB_O_NAME) include $(top_srcdir)/Makefile.lib diff --git a/src/mime/backend/Makefile b/src/mime/backend/Makefile index 10582421d..7b0517681 100644 --- a/src/mime/backend/Makefile +++ b/src/mime/backend/Makefile @@ -16,21 +16,8 @@ mailcap-cache.o: mailcap.c TESTDEPS = \ common.o \ - $(top_builddir)/src/intl/charsets.o \ - $(top_builddir)/src/osdep/osdep.o \ - $(top_builddir)/src/osdep/stub.o \ - $(top_builddir)/src/util/conv.o \ - $(top_builddir)/src/util/error.o \ - $(top_builddir)/src/util/file.o \ - $(top_builddir)/src/util/hash.o \ - $(top_builddir)/src/util/memory.o \ - $(top_builddir)/src/util/string.o \ - $(top_builddir)/src/util/time.o + $(top_builddir)/src/osdep/osdep.o TESTDEPS-$(CONFIG_NLS) += $(top_builddir)/src/intl/gettext/lib.o -TESTDEPS-$(CONFIG_DEBUG) += $(top_builddir)/src/util/memdebug.o -TESTDEPS-$(call not,$(CONFIG_SMALL)) += \ - $(top_builddir)/src/util/fastfind.o \ - include $(top_srcdir)/Makefile.lib diff --git a/src/protocol/ftp/Makefile b/src/protocol/ftp/Makefile index cd805b623..d48c8d850 100644 --- a/src/protocol/ftp/Makefile +++ b/src/protocol/ftp/Makefile @@ -7,18 +7,7 @@ TEST_PROGS = \ ftp-parser TESTDEPS = \ - $(top_builddir)/src/intl/charsets.o \ - $(top_builddir)/src/osdep/stub.o \ $(top_builddir)/src/protocol/date.o \ - $(top_builddir)/src/protocol/ftp/parse.o \ - $(top_builddir)/src/util/conv.o \ - $(top_builddir)/src/util/error.o \ - $(top_builddir)/src/util/hash.o \ - $(top_builddir)/src/util/memory.o \ - $(top_builddir)/src/util/string.o \ - $(top_builddir)/src/util/time.o - -TESTDEPS-$(call not,$(CONFIG_SMALL)) += \ - $(top_builddir)/src/util/fastfind.o \ + $(top_builddir)/src/protocol/ftp/parse.o include $(top_srcdir)/Makefile.lib