#!/bin/sh
# Check that the standard plugin config fragments shipped in
# /usr/share/edbrowse/plugins are picked up by the generated config, and that
# one of them actually runs. The zip plugin is used because its helper is
# shipped by this package rather than pulled in from elsewhere.
set -e

export HOME="$AUTOPKGTEST_TMP"

# First start only writes the default config and exits.
printf 'q\n' | edbrowse >/dev/null 2>&1 || true

grep -q '^optinclude = /usr/share/edbrowse/plugins$' "$HOME/.ebrc" || {
	echo "ERROR: generated config does not include the plugin directory" >&2
	exit 1
}

mkdir -p "$AUTOPKGTEST_TMP/z/sub"
echo hello > "$AUTOPKGTEST_TMP/z/sub/greet.txt"
(cd "$AUTOPKGTEST_TMP/z" && zip -qr "$AUTOPKGTEST_TMP/t.zip" .)

out=$(printf 'b\n1,$p\nq\n' | edbrowse "$AUTOPKGTEST_TMP/t.zip" 2>&1)
printf '%s\n' "$out"

printf '%s\n' "$out" | grep -q 'Zip Archive' || {
	echo "ERROR: the zip plugin did not run" >&2
	exit 1
}
