summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorXavier Roche <xroche@users.noreply.github.com>2013-06-02 10:17:05 +0000
committerXavier Roche <xroche@users.noreply.github.com>2013-06-02 10:17:05 +0000
commit5882fbd039bb8e7ae825cba500ccef1686e5b015 (patch)
treee39f2b04adb3300e2f09200560ae926d42eba452 /tests
parenta94987b93ecad02ca1b077fe784b5d08fb1b6ec4 (diff)
Added minimalistic unit tests for HTTrack (about time :p)
Diffstat (limited to 'tests')
-rwxr-xr-xtests/00_runnable.test5
-rwxr-xr-xtests/01_engine-charset.test5
-rwxr-xr-xtests/01_engine-entities.test5
-rwxr-xr-xtests/01_engine-idna.test10
-rwxr-xr-xtests/01_engine-simplify.test9
-rwxr-xr-xtests/10_crawl-simple.test4
-rw-r--r--tests/Makefile.am7
-rw-r--r--tests/Makefile.in421
-rwxr-xr-xtests/crawl-test.sh176
9 files changed, 642 insertions, 0 deletions
diff --git a/tests/00_runnable.test b/tests/00_runnable.test
new file mode 100755
index 0000000..4ec3bfb
--- /dev/null
+++ b/tests/00_runnable.test
@@ -0,0 +1,5 @@
+#!/bin/bash
+#
+
+# check that httrack starts
+httrack --version >/dev/null
diff --git a/tests/01_engine-charset.test b/tests/01_engine-charset.test
new file mode 100755
index 0000000..5975530
--- /dev/null
+++ b/tests/01_engine-charset.test
@@ -0,0 +1,5 @@
+#!/bin/bash
+#
+
+# minimalistic charset test
+test "$(httrack -O /dev/null -#3 "iso-8859-1" "café")" == "café" || exit 1
diff --git a/tests/01_engine-entities.test b/tests/01_engine-entities.test
new file mode 100755
index 0000000..6beb75d
--- /dev/null
+++ b/tests/01_engine-entities.test
@@ -0,0 +1,5 @@
+#!/bin/bash
+#
+
+# basic entities handling (with boggy entities handling)
+test "$(httrack -O /dev/null -#6 "&foo;&nbsp;th&eacute;&amp;caf&#xe9;&#e9;&#x3082;&#12398;&#x306e;&#x3051;&#x59eb;")" == "&foo; thé&café&#e9;もののけ姫" || exit 1
diff --git a/tests/01_engine-idna.test b/tests/01_engine-idna.test
new file mode 100755
index 0000000..1c98e66
--- /dev/null
+++ b/tests/01_engine-idna.test
@@ -0,0 +1,10 @@
+#!/bin/bash
+#
+
+# IDNA routine
+test "$(httrack -O /dev/null -#4 "www.café.com")" == "www.xn--caf-dma.com" || exit 1
+test "$(httrack -O /dev/null -#4 "www.もののけ姫-the-movie.com")" == "www.xn---the-movie-g63irla2z8297c.com" || exit 1
+
+# reverse IDNA
+test "$(httrack -O /dev/null -#5 "www.xn--caf-dma.com")" == "www.café.com" || exit 1
+test "$(httrack -O /dev/null -#5 "www.xn---the-movie-g63irla2z8297c.com")" == "www.もののけ姫-the-movie.com" || exit 1
diff --git a/tests/01_engine-simplify.test b/tests/01_engine-simplify.test
new file mode 100755
index 0000000..b257af2
--- /dev/null
+++ b/tests/01_engine-simplify.test
@@ -0,0 +1,9 @@
+#!/bin/bash
+#
+
+# simplify engine
+test "$(httrack -O /dev/null -#1 ./foo/bar/)" == "simplified=foo/bar/" || exit 1
+test "$(httrack -O /dev/null -#1 ./foo/bar)" == "simplified=foo/bar" || exit 1
+test "$(httrack -O /dev/null -#1 ./foo/./bar)" == "simplified=foo/bar" || exit 1
+test "$(httrack -O /dev/null -#1 ./foo/bar/.././tmp/foobar)" == "simplified=foo/tmp/foobar" || exit 1
+test "$(httrack -O /dev/null -#1 ./foo/bar/.././tmp/foobar/../foobaz)" == "simplified=foo/tmp/foobaz" || exit 1
diff --git a/tests/10_crawl-simple.test b/tests/10_crawl-simple.test
new file mode 100755
index 0000000..a05364b
--- /dev/null
+++ b/tests/10_crawl-simple.test
@@ -0,0 +1,4 @@
+#!/bin/bash
+#
+
+bash crawl-test.sh --errors 0 --files 5 httrack http://ut.httrack.com/simple/basic.html
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..a1e740b
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,7 @@
+EXTRA_DIST = defs $(TESTS)
+
+TESTS_ENVIRONMENT =
+TESTS_ENVIRONMENT += LD_LIBRARY_PATH=$(top_builddir)/src/.libs:$$LD_LIBRARY_PATH
+TESTS_ENVIRONMENT += PATH=$(top_builddir)/src/.libs:$$PATH
+
+TESTS = *.test
diff --git a/tests/Makefile.in b/tests/Makefile.in
new file mode 100644
index 0000000..732c025
--- /dev/null
+++ b/tests/Makefile.in
@@ -0,0 +1,421 @@
+# Makefile.in generated by automake 1.9.6 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005 Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+top_builddir = ..
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+INSTALL = @INSTALL@
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+subdir = tests
+DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4/check_zlib.m4 \
+ $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \
+ $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
+ $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/snprintf.m4 \
+ $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+SOURCES =
+DIST_SOURCES =
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMDEP_FALSE = @AMDEP_FALSE@
+AMDEP_TRUE = @AMDEP_TRUE@
+AMTAR = @AMTAR@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFAULT_CFLAGS = @DEFAULT_CFLAGS@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DL_LIBS = @DL_LIBS@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GREP = @GREP@
+ICONV_LIBS = @ICONV_LIBS@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LFS_FLAG = @LFS_FLAG@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+MAINT = @MAINT@
+MAINTAINER_MODE_FALSE = @MAINTAINER_MODE_FALSE@
+MAINTAINER_MODE_TRUE = @MAINTAINER_MODE_TRUE@
+MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OPENSSL_LIBS = @OPENSSL_LIBS@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+SOCKET_LIBS = @SOCKET_LIBS@
+STRIP = @STRIP@
+THREADS_CFLAGS = @THREADS_CFLAGS@
+THREADS_LIBS = @THREADS_LIBS@
+V6_FLAG = @V6_FLAG@
+VERSION = @VERSION@
+VERSION_INFO = @VERSION_INFO@
+ac_ct_AR = @ac_ct_AR@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
+am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
+am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
+am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+EXTRA_DIST = defs $(TESTS)
+TESTS_ENVIRONMENT = \
+ LD_LIBRARY_PATH=$(top_builddir)/src/.libs:$$LD_LIBRARY_PATH \
+ PATH=$(top_builddir)/src/.libs:$$PATH
+TESTS = *.test
+all: all-am
+
+.SUFFIXES:
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
+ && exit 0; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu tests/Makefile'; \
+ cd $(top_srcdir) && \
+ $(AUTOMAKE) --gnu tests/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+
+distclean-libtool:
+ -rm -f libtool
+uninstall-info-am:
+tags: TAGS
+TAGS:
+
+ctags: CTAGS
+CTAGS:
+
+
+check-TESTS: $(TESTS)
+ @failed=0; all=0; xfail=0; xpass=0; skip=0; \
+ srcdir=$(srcdir); export srcdir; \
+ list='$(TESTS)'; \
+ if test -n "$$list"; then \
+ for tst in $$list; do \
+ if test -f ./$$tst; then dir=./; \
+ elif test -f $$tst; then dir=; \
+ else dir="$(srcdir)/"; fi; \
+ if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \
+ all=`expr $$all + 1`; \
+ case " $(XFAIL_TESTS) " in \
+ *" $$tst "*) \
+ xpass=`expr $$xpass + 1`; \
+ failed=`expr $$failed + 1`; \
+ echo "XPASS: $$tst"; \
+ ;; \
+ *) \
+ echo "PASS: $$tst"; \
+ ;; \
+ esac; \
+ elif test $$? -ne 77; then \
+ all=`expr $$all + 1`; \
+ case " $(XFAIL_TESTS) " in \
+ *" $$tst "*) \
+ xfail=`expr $$xfail + 1`; \
+ echo "XFAIL: $$tst"; \
+ ;; \
+ *) \
+ failed=`expr $$failed + 1`; \
+ echo "FAIL: $$tst"; \
+ ;; \
+ esac; \
+ else \
+ skip=`expr $$skip + 1`; \
+ echo "SKIP: $$tst"; \
+ fi; \
+ done; \
+ if test "$$failed" -eq 0; then \
+ if test "$$xfail" -eq 0; then \
+ banner="All $$all tests passed"; \
+ else \
+ banner="All $$all tests behaved as expected ($$xfail expected failures)"; \
+ fi; \
+ else \
+ if test "$$xpass" -eq 0; then \
+ banner="$$failed of $$all tests failed"; \
+ else \
+ banner="$$failed of $$all tests did not behave as expected ($$xpass unexpected passes)"; \
+ fi; \
+ fi; \
+ dashes="$$banner"; \
+ skipped=""; \
+ if test "$$skip" -ne 0; then \
+ skipped="($$skip tests were not run)"; \
+ test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \
+ dashes="$$skipped"; \
+ fi; \
+ report=""; \
+ if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \
+ report="Please report to $(PACKAGE_BUGREPORT)"; \
+ test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \
+ dashes="$$report"; \
+ fi; \
+ dashes=`echo "$$dashes" | sed s/./=/g`; \
+ echo "$$dashes"; \
+ echo "$$banner"; \
+ test -z "$$skipped" || echo "$$skipped"; \
+ test -z "$$report" || echo "$$report"; \
+ echo "$$dashes"; \
+ test "$$failed" -eq 0; \
+ else :; fi
+
+distdir: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
+ list='$(DISTFILES)'; for file in $$list; do \
+ case $$file in \
+ $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
+ $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
+ esac; \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test "$$dir" != "$$file" && test "$$dir" != "."; then \
+ dir="/$$dir"; \
+ $(mkdir_p) "$(distdir)$$dir"; \
+ else \
+ dir=''; \
+ fi; \
+ if test -d $$d/$$file; then \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
+ fi; \
+ cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
+ else \
+ test -f $(distdir)/$$file \
+ || cp -p $$d/$$file $(distdir)/$$file \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+ $(MAKE) $(AM_MAKEFLAGS) check-TESTS
+check: check-am
+all-am: Makefile
+installdirs:
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ `test -z '$(STRIP)' || \
+ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-libtool mostlyclean-am
+
+distclean: distclean-am
+ -rm -f Makefile
+distclean-am: clean-am distclean-generic distclean-libtool
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-exec-am:
+
+install-info: install-info-am
+
+install-man:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-generic mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-info-am
+
+.PHONY: all all-am check check-TESTS check-am clean clean-generic \
+ clean-libtool distclean distclean-generic distclean-libtool \
+ distdir dvi dvi-am html html-am info info-am install \
+ install-am install-data install-data-am install-exec \
+ install-exec-am install-info install-info-am install-man \
+ install-strip installcheck installcheck-am installdirs \
+ maintainer-clean maintainer-clean-generic mostlyclean \
+ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+ uninstall uninstall-am uninstall-info-am
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/tests/crawl-test.sh b/tests/crawl-test.sh
new file mode 100755
index 0000000..7638d84
--- /dev/null
+++ b/tests/crawl-test.sh
@@ -0,0 +1,176 @@
+#!/bin/bash
+#
+
+function warning {
+ echo "** $*" >&2
+ return 0
+}
+
+function die {
+ warning "$*"
+ exit 1
+}
+
+function debug {
+ if test -n "$verbose"; then
+ echo "$*" >&2
+ fi
+}
+
+function info {
+ printf "[$*] ..\t" >&2
+}
+
+function result {
+ echo "$*" >&2
+}
+
+function cleanup {
+ debug "cleaning function called"
+ if test -n "$tmpdir"; then
+ if test -d "$tmpdir"; then
+ if test -z "$nopurge"; then
+ debug "cleaning up $tmpdir"
+ rm -rf "$tmpdir"
+ fi
+ fi
+ fi
+ if test -n "$crawlpid"; then
+ debug "killing $crawlpid"
+ kill -9 "$crawlpid"
+ crawlpid=
+ fi
+}
+
+function usage {
+ cat << EOF
+usage: $0
+EOF
+}
+
+function assert_equals {
+ info "$1"
+ if test ! "$2" == "$3"; then
+ result "expected '$2', got '$3'"
+ exit 1
+ else
+ result "OK ($2)"
+ fi
+}
+
+function start-crawl {
+ # parse args
+ pos=1
+ while test "$#" -ge "$pos" ; do
+ case "${!pos}" in
+ --debug)
+ verbose=1
+ ;;
+ --no-purge|--summary)
+ ;;
+ --errors|--files)
+ pos=$[${pos}+1]
+ test "$#" -ge "$pos" || warning "missing argument" || return 1
+ ;;
+ httrack)
+ pos=$[${pos}+1]
+ break;
+ ;;
+ *)
+ warning "unrecognized option ${!pos}"
+ return 1
+ ;;
+ esac
+ pos=$[${pos}+1]
+ done
+ debug "remaining args: ${@:${pos}}"
+
+ # ut/ won't exceed 2 minutes
+ moreargs="--quiet --max-time=120"
+
+ # proxy environment ?
+ if test -n "$http_proxy"; then
+ moreargs="$moreargs --proxy $http_proxy"
+ fi
+
+ test -n "$tmpdir" || ! warning "no tmpdir" || return 1
+ tmp="${tmpdir}/crawl"
+ rm -rf "$tmp"
+ mkdir "$tmp" || ! warning "could not create $tmp" || return 1
+
+ which httrack >/dev/null || ! warning "could not find httrack" || return 1
+ ver=$(httrack -O /dev/null --version)
+ test -n "$ver" || ! warning "could not run httrack" || return 1
+
+ # start crawl
+ log="${tmp}/log"
+ debug starting httrack -O "${tmp}" ${moreargs} ${@:${pos}}
+ info "running httrack ${@:${pos}}"
+ httrack -O "${tmp}" --user-agent="HTTrack $ver Unit Tests ($(uname -omrs))" ${moreargs} ${@:${pos}} >"${log}" 2>&1 &
+ crawlpid="$!"
+ debug "started cralwer on pid $crawlpid"
+ wait "$crawlpid"
+ result="$?"
+ crawlpid=
+ test "$result" -eq 0 || ! result "error code $result" || return 1
+ result "OK"
+ grep -iE "^[0-9\:]*[[:space:]]Error:" "${tmp}/hts-log.txt" >&2
+
+ # now audit
+ while test "$#" -gt 0; do
+ case "$1" in
+ --no-purge)
+ nopurge=1
+ ;;
+ --summary)
+ grep -E "^HTTrack Website Copier/[^ ]* mirror complete in " "${tmp}/hts-log.txt"
+ ;;
+ --errors)
+ shift
+ test "$#" -gt 0 || warning "missing argument" || return 1
+ assert_equals "checking errors" "$1" "$(grep -iEc "^[0-9\:]*[[:space:]]Error:" "${tmp}/hts-log.txt")"
+ ;;
+ --files)
+ shift
+ test "$#" -gt 0 || warning "missing argument" || return 1
+ nFiles=$(grep -E "^HTTrack Website Copier/[^ ]* mirror complete in " "${tmp}/hts-log.txt" \
+ | sed -e 's/.*[[:space:]]\([^ ]*\)[[:space:]]files written.*/\1/g')
+ assert_equals "checking files" "$1" "$nFiles"
+ ;;
+ httrack)
+ break;
+ ;;
+ esac
+ shift
+ done
+
+ # cleanup
+ if test -z "$nopurge"; then
+ rm -rf "$tmp"
+ else
+ tmpdir=
+ fi
+}
+
+# check args
+test "$#" -le 0 && usage && exit 0
+
+# <http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap08.html>
+tmptopdir=${TMPDIR:-/tmp}
+test -d "$tmptopdir" || mkdir -p "${tmptopdir}" || die "can not find a temporary directory ; please set TMPDIR"
+
+# final cleanup
+tmpdir=
+crawlpid=
+nopurge=
+verbose=
+trap "cleanup" 0 1 2 3 4 5 6 7 8 9 11 13 14 15 16 19 24 25
+
+# working directory
+tmpdir="${tmptopdir}/httrack_ut.$$"
+mkdir "${tmpdir}"
+
+# rock'in
+start-crawl $*
+
+# that's all, folks!