#!/bin/bash

#   eLyXer -- convert LyX source files to HTML output.
#
#   Copyright (C) 2009 Alex Fernández
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Alex 20090319: run all tests

# first from the current directory
echo "Testing eLyXer -- any text below this line signals an error"
for file in test/*.lyx; do
  name=$(dirname "$file")/$(basename "$file" .lyx)
  ./elyxer.py --quiet --css ../docs/lyx.css "$name.lyx" "$name-test.html"
  diff -u --ignore-matching-lines="create-date" "$name-good.html" "$name-test.html"
done
# now a limited subset of tests from within the directory
cd test
name="with images-1-5"
../elyxer.py --quiet --css ../docs/lyx.css "$name.lyx" "$name-test.html"
diff -u --ignore-matching-lines="create-date" "$name-good.html" "$name-test.html"
../elyxer.py --html --quiet --css ../docs/lyx.css "$name.lyx" "$name-html-test.html"
diff -u --ignore-matching-lines="create-date" "$name-html-good.html" "$name-html-test.html"
../elyxer.py --quiet --css ../docs/lyx.css --forceformat ".jpg" "$name.lyx" "$name-jpg-test.html"
diff -u --ignore-matching-lines="create-date" "$name-jpg-good.html" "$name-jpg-test.html"
# a test for --directory
name="appendix-1-6"
cp "$name.lyx" "subdir/$name.lyx"
cd subdir
../../elyxer.py --directory .. --quiet --css ../../docs/lyx.css "$name.lyx" "$name-test.html"
diff -u --ignore-matching-lines="create-date" "$name-good.html" "$name-test.html"
# test TOC generation
cd ..
name="appendix-1-6"
../elyxer.py --quiet --toc --toctarget "$name-test.html" --css ../docs/toc.css --target contents "$name.lyx" "$name-toc-test.html"
diff -u --ignore-matching-lines="create-date" "$name-toc-good.html" "$name-toc-test.html"
# test lowmem generation
name="index-1-6"
../elyxer.py --quiet --lowmem --css ../docs/lyx.css "$name.lyx" "$name-lowmem-test.html"
diff -u --ignore-matching-lines="create-date" "$name-lowmem-good.html" "$name-lowmem-test.html"
# test stdin + stdout generation
name="footnotes-1-6"
cat "$name.lyx" | ../elyxer.py --css ../docs/lyx.css > "$name-stdio-test.html"
diff -u --ignore-matching-lines="create-date" "$name-good.html" "$name-stdio-test.html"

