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/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/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 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/dom/test/sgml-parser.c b/src/dom/test/sgml-parser.c index 2afa7c6b1..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; @@ -256,6 +257,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 +305,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; diff --git a/src/dom/test/test-sgml-parser-basic b/src/dom/test/test-sgml-parser-basic index 791bbf4a9..4671b97ff 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 + printf "%s\n" "$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.' \ 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 diff --git a/src/mime/backend/Makefile b/src/mime/backend/Makefile index 909bf1dd3..7b0517681 100644 --- a/src/mime/backend/Makefile +++ b/src/mime/backend/Makefile @@ -16,17 +16,8 @@ mailcap-cache.o: mailcap.c TESTDEPS = \ common.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 include $(top_srcdir)/Makefile.lib diff --git a/src/protocol/ftp/Makefile b/src/protocol/ftp/Makefile index 115744b79..d48c8d850 100644 --- a/src/protocol/ftp/Makefile +++ b/src/protocol/ftp/Makefile @@ -3,17 +3,11 @@ include $(top_builddir)/Makefile.config OBJS = ftp.o parse.o -TEST_PROGS = ftp-parser +TEST_PROGS = \ + ftp-parser TESTDEPS = \ - $(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 + $(top_builddir)/src/protocol/ftp/parse.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