#!/bin/sh

set -ex

cp -a Users_Guide "$AUTOPKGTEST_TMP"

cd "$AUTOPKGTEST_TMP"

# Create a new document and then build it
publican create --name test
cd test
publican build --quiet --formats=html,pdf,html-single,txt --langs=en-US
cd ..

# Same with docbook 5
publican create --name test-db5 --dtdver 5
cd test-db5
publican build --novalid --quiet --formats=html,pdf,html-single,txt --langs=en-US
# Lack of --novalid ends up with a validation failure:
# Relax-NG parser error : xmlRelaxNGParse: could not load http://docbook.org/xml/5/rng/docbook.rng
cd ..

# Build the user's guide
cd Users_Guide

# Simple build
publican build --quiet --formats=html --langs=en-US

# Build in all formats and in publish mode
publican build --quiet --formats=html,html-single,html-desktop,pdf,txt,epub --langs=en-US --embedtoc --publish
for expected in publish/en-US/Publican/*/html/Users_Guide/index.html \
    publish/en-US/Publican/*/html-single/Users_Guide/index.html \
    publish/en-US/Publican/*/pdf/Users_Guide/*.pdf \
    publish/en-US/Publican/*/txt/Users_Guide/*.txt \
    publish/en-US/Publican/*/epub/Users_Guide/*.epub; do
    if [ ! -s "$expected" ]; then
	echo "ERROR: expected file $expected not found after build of the user guide"
	ls -alR publish
	exit 1
    fi
done

# Test translation features
publican update_pot
if [ ! -s pot/Introduction.pot ]; then
    echo "ERROR: Expected POT file has not been generated"
    exit 1
fi

publican update_po --langs=all --firstname=Raphael --surname=Hertzog --email=hertzog@debian.org --previous
