diff --git a/t/01-smoke-hasindex.test b/t/01-smoke-hasindex.test
new file mode 100644
index 0000000..acfc2d1
--- /dev/null
+++ b/t/01-smoke-hasindex.test
@@ -0,0 +1,3 @@
+#! /bin/bash
+nginx_start
+grep 'Index of' <( fetch )
diff --git a/t/02-smoke-indexisfancy.test b/t/02-smoke-indexisfancy.test
new file mode 100644
index 0000000..fe65544
--- /dev/null
+++ b/t/02-smoke-indexisfancy.test
@@ -0,0 +1,6 @@
+#! /bin/bash
+nginx_start
+content=$(fetch --with-headers)
+grep 'Index of /' <<< "${content}" # It is an index
+grep '\
' <<< "${content}" # It contains a table
+grep '^ Content-Type:[[:space:]]*text/html' <<< "${content}"
diff --git a/t/nginx.conf b/t/nginx.conf
new file mode 100644
index 0000000..2b99a3d
--- /dev/null
+++ b/t/nginx.conf
@@ -0,0 +1,25 @@
+worker_processes 1;
+
+
+events {
+ worker_connections 1024;
+}
+
+http {
+ include mime.types;
+ default_type application/octet-stream;
+ sendfile on;
+ keepalive_timeout 65;
+ server {
+ listen 80;
+ server_name localhost;
+ location / {
+ root html;
+ index index.html index.htm;
+ }
+ error_page 500 502 503 504 /50x.html;
+ location = /50x.html {
+ root html;
+ }
+ }
+}
diff --git a/t/preamble b/t/preamble
index 47defe7..487fd75 100644
--- a/t/preamble
+++ b/t/preamble
@@ -6,6 +6,72 @@
# Distributed under terms of the MIT license.
#
+function nginx_conf_generate () {
+ if ${DYNAMIC} ; then
+ echo 'load_module modules/ngx_http_fancyindex_module.so;'
+ fi
+ cat <<-EOF
+ worker_processes 1;
+ events { worker_connections 1024; }
+ http {
+ include mime.types;
+ default_type application/octet-stream;
+ sendfile on;
+ keepalive_timeout 65;
+ server {
+ server_name localhost;
+ listen 127.0.0.1:8888;
+ root ${TESTDIR};
+ error_page 500 502 503 504 /50x.html;
+ location = /50x.html { root html; }
+ location / {
+ index index.html;
+ fancyindex on;
+ $*
+ }
+ }
+ }
+ EOF
+}
+
+readonly NGINX_CONF="${PREFIX}/conf/nginx.conf"
+readonly NGINX_PID="${PREFIX}/logs/nginx.pid"
+rm -f "${NGINX_CONF}" "${NGINX_PID}"
+mkdir -p "${PREFIX}/logs"
+
+function nginx () {
+ "${PREFIX}/sbin/nginx" "$@"
+}
+
+function nginx_conf () {
+ nginx_conf_generate "$@" > "${NGINX_CONF}"
+}
+
+function nginx_is_running () {
+ [[ -r ${NGINX_PID} ]] && kill -0 $(< "${NGINX_PID}")
+}
+
+function nginx_stop () {
+ if nginx_is_running ; then nginx -s stop ; fi
+ rm -f "${NGINX_PID}"
+}
+trap nginx_stop EXIT
+
+function nginx_start () {
+ if [[ $# -gt 0 || ! -r ${NGINX_CONF} ]] ; then nginx_conf "$@" ; fi
+ nginx_stop # Ensure that it is not running.
+ nginx
+}
+
+function fetch () {
+ local -a opts=( -q )
+ if [[ $1 = --with-headers ]] ; then
+ opts+=( -S )
+ shift
+ fi
+ wget "${opts[@]}" -O- "http://localhost:8888${1:-/}" 2>&1
+}
+
function fail () {
printf "(FF) "
printf "$@"
diff --git a/t/run b/t/run
index db1592e..8f0d328 100755
--- a/t/run
+++ b/t/run
@@ -6,10 +6,16 @@ if [[ $# -lt 1 || $# -gt 2 ]] ; then
exit 1
fi
-readonly T=$(dirname "$0")
+# Obtain the absolute path to the tests directory
+pushd "$(dirname "$0")" &> /dev/null
+readonly T=$(pwd)
+popd &> /dev/null
export T
-readonly prefix=$1
+# Same for the nginx prefix directory
+pushd "$1" &> /dev/null
+readonly prefix=$(pwd)
+popd &> /dev/null
dynamic=false
if [[ $# -gt 1 && $2 -eq 1 ]] ; then
@@ -28,8 +34,9 @@ for t in "$T"/*.test ; do
outfile="${name}.out"
shfile="${name}.sh"
cat > "${shfile}" <<-EOF
- readonly PREFIX='${prefix}'
readonly DYNAMIC=${dynamic}
+ readonly TESTDIR='$T'
+ readonly PREFIX='${prefix}'
$(< "$T/preamble")
$(< "$t")
EOF