#! /bin/sh
set -e
pkg="offpunk"

if [ "${AUTOPKGTEST_TMP}" = "" ]
then
	AUTOPKGTEST_TMP=$(mktemp -d /tmp/${pkg}-test.XXXXXX)
	trap "rm -rf ${AUTOPKGTEST_TMP}" 0 INT QUIT ABRT PIPE TERM
fi

# This test is expected to be run from debian source code.
cp ./doc/index.gmi "${AUTOPKGTEST_TMP}"
cd "${AUTOPKGTEST_TMP}"
HOME="${AUTOPKGTEST_TMP}"
export HOME

set -v

# 0. Basic arguments
offpunk --version
offpunk --help
offpunk --features
echo quit | offpunk --bookmarks

# 1. Basic commands
cat << END | offpunk
version
help
help abbrevs
help add
help back
help blackbox
help bookmarks
help cat
help cert
help copy
help find
help forward
help go
help gus
help handler
help help
help history
help info
help list
help ls
help mark
help move
help offline
help online
help open
help redirect
help reload
help root
help save
help set
help shell echo test
help subscribe
help sync
help tour
help url
help version
help wikipedia
help exit
help quit
quit
END

# cert calls a submenu which expects then a blank line to get outside.
# find will call the pager
# gus and search will launch the client to the search engine.
# reload will call the pager
# wikipedia will require test to have Internet access
cat << END | offpunk
abbrevs
add
archive
back
blackbox
bookmarks
cat
cert

copy
forward
go
handler
history
info
list
ls
mark
move
offline
online
open
redirect
root
save
set
shell echo test
subscribe

sync
tour
url
exit
END

# 2. Checks against gemini file
cat << END | offpunk
go file://$PWD/index.gmi
quit
END

# 3. Also verify somewhat the migration script
migrate-offpunk-cache --help
migrate-offpunk-cache
