| 1 |
#!/usr/bin/env bash |
| 2 |
# ========================================================================== |
| 3 |
# ____ _ _ _____ __ ______ |
| 4 |
# | __ )(_) |_|_ _|__\ \/ / ___|___ _ ____ __ |
| 5 |
# | _ \| | '_ \| |/ _ \ / | / _ \| '_ \ \ / / |
| 6 |
# | |_) | | |_) | | __// \ |__| (_) | | | \ V / |
| 7 |
# |____/|_|_.__/|_|\___/_/\_\____\___/|_| |_|\_/ |
| 8 |
# |
| 9 |
# --- BibTeX Converter --- |
| 10 |
# https://www.nntb.no/~dreibh/bibtexconv/ |
| 11 |
# ========================================================================== |
| 12 |
# |
| 13 |
# BibTeX Converter |
| 14 |
# Copyright (C) 2010-2026 by Thomas Dreibholz |
| 15 |
# |
| 16 |
# This program is free software: you can redistribute it and/or modify |
| 17 |
# it under the terms of the GNU General Public License as published by |
| 18 |
# the Free Software Foundation, either version 3 of the License, or |
| 19 |
# (at your option) any later version. |
| 20 |
# |
| 21 |
# This program is distributed in the hope that it will be useful, |
| 22 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 |
# GNU General Public License for more details. |
| 25 |
# |
| 26 |
# You should have received a copy of the GNU General Public License |
| 27 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 28 |
# |
| 29 |
# Contact: [email protected] |
| 30 |
|
| 31 |
set -eu |
| 32 |
|
| 33 |
RUN="" |
| 34 |
# RUN="valgrind " |
| 35 |
|
| 36 |
make bibtexconv |
| 37 |
bibTeXFile="ExampleReferences.bib" |
| 38 |
downloadsDirectory="${HOME}/tmp/BibTeXConv" |
| 39 |
mkdir -p "${downloadsDirectory}" |
| 40 |
|
| 41 |
failures=0 |
| 42 |
# Tests: test1 test2 test3 bibtex-example1 bibtex-example2 bibtex-example3 xml-example yaml-example md-example text-example web-example1 web-example2 web-rserpool odt-example |
| 43 |
for test in test1 test2 test3 bibtex-example1 bibtex-example2 bibtex-example3 xml-example yaml-example md-example text-example web-example1 web-example2 web-rserpool odt-example ; do |
| 44 |
|
| 45 |
# ====== Prepare test run ======================================= |
| 46 |
print-utf8 -x 86 -s "\x1b[34m###### Testing: ${test} " "#" "#\x1b[0m " >&2 |
| 47 |
echo "" |
| 48 |
|
| 49 |
# ------ Default parameters ------------------------------------- |
| 50 |
exportFile="${test}.export" |
| 51 |
outputDirectory="bibtexconv-tests" |
| 52 |
outputFile="${outputDirectory}/${test}" |
| 53 |
goodFile="${outputDirectory}/${test}.good" |
| 54 |
badFile="${outputDirectory}/${test}.bad" |
| 55 |
rm -f "${badFile}" |
| 56 |
|
| 57 |
# ====== Perform the test run =================================== |
| 58 |
if [ "${test}" == "bibtex-example1" ] ; then |
| 59 |
outputFile="${outputFile}.bib" |
| 60 |
command="${RUN} ./bibtexconv ${bibTeXFile} -q --export-to-bibtex=${outputFile} --check-urls --only-check-new-urls --non-interactive" |
| 61 |
elif [ "${test}" == "bibtex-example2" ] ; then |
| 62 |
outputFile="${outputFile}.bib" |
| 63 |
command="${RUN} ./bibtexconv ${bibTeXFile} -q --export-to-bibtex=${outputFile} --check-urls --store-downloads=${downloadsDirectory} --non-interactive" |
| 64 |
elif [ "${test}" == "bibtex-example3" ] ; then |
| 65 |
outputFile="${outputFile}.out" |
| 66 |
command="${RUN} ./bibtexconv ${bibTeXFile} --non-interactive --export-to-separate-bibtexs=${outputDirectory}/ >${outputFile}" |
| 67 |
touch "${goodFile}" # Empty! |
| 68 |
elif [ "${test}" == "xml-example" ] ; then |
| 69 |
outputFile="${outputFile}.out" |
| 70 |
command="${RUN} ./bibtexconv ${bibTeXFile} --non-interactive --export-to-separate-xmls=${outputDirectory}/reference. >${outputFile}" |
| 71 |
touch "${goodFile}" # Empty! |
| 72 |
elif [ "${test}" == "web-example2" ] || [ "${test}" == "md-example" ] ; then |
| 73 |
if [[ "${test}" =~ ^md- ]] ; then |
| 74 |
outputFile="${outputFile}.md" |
| 75 |
else |
| 76 |
outputFile="${outputFile}.html" |
| 77 |
fi |
| 78 |
command="${RUN} ./bibtexconv ${bibTeXFile} -q --mapping=author-url:authors.list:Name:URL <${exportFile} >${outputFile}" |
| 79 |
elif [ "${test}" == "web-rserpool" ] ; then |
| 80 |
outputFile="${outputFile}.html" |
| 81 |
# FIXME! ${bibTeXFile} |
| 82 |
command="${RUN} ./bibtexconv RSerPool.bib <${exportFile} >${outputFile}" |
| 83 |
else |
| 84 |
if [[ "${test}" =~ ^odt- ]] ; then |
| 85 |
outputFile="${outputFile}.xml" |
| 86 |
elif [[ "${test}" =~ ^te[sx]t ]] ; then |
| 87 |
outputFile="${outputFile}.txt" |
| 88 |
elif [[ "${test}" =~ ^yaml ]] ; then |
| 89 |
outputFile="${outputFile}.yaml" |
| 90 |
else |
| 91 |
outputFile="${outputFile}.html" |
| 92 |
fi |
| 93 |
command="${RUN} ./bibtexconv ${bibTeXFile} <${exportFile} >${outputFile}" |
| 94 |
fi |
| 95 |
bash -c "${command}" |
| 96 |
|
| 97 |
# ====== Check results ========================================== |
| 98 |
if [ -e "${goodFile}" ] ; then |
| 99 |
# NOTE: Comparison for "url.*" and "numpages" is disabled. |
| 100 |
# * A later check will have a newer url.checked date/time, |
| 101 |
# mainly for HTML webpages. |
| 102 |
# * The download PDF length may differ from "pages" values. |
| 103 |
if ! diff -q -I "url.checked = " -I "url.size = " -I "url.md5 = " -I "numpages = " "${goodFile}" "${outputFile}" >/dev/null ; then |
| 104 |
failures=$((failures+1)) |
| 105 |
( |
| 106 |
echo "" |
| 107 |
print-utf8 -n -s "\e[1;31;5m█" "▀" "█\e[0m" ; |
| 108 |
echo "TEST FAILED!" | figlet -w 64 | print-utf8 -n -C "\e[1;31;5m█\e[25m" "\e[5m█\e[0m" ; |
| 109 |
print-utf8 -n -s "\e[1;31;5m█" "▄" "█\e[0m" |
| 110 |
echo "Failure #${failures}:" |
| 111 |
echo "Command:${command}" |
| 112 |
echo "" |
| 113 |
print-utf8 -x 78 -n -s "\x1b[33m------ Good ($(basename "${goodFile}")) " "-" "-\x1b[0m" |
| 114 |
ls -l "${goodFile}" |
| 115 |
# cat "${goodFile}" |
| 116 |
# echo "" |
| 117 |
print-utf8 -x 78 -n -s "\x1b[35m------ Output ($(basename "${outputFile}")) " "-" "-\x1b[0m" |
| 118 |
ls -l "${outputFile}" |
| 119 |
# cat "${outputFile}" |
| 120 |
# echo "" |
| 121 |
print-utf8 -x 78 -n -s "\x1b[31m------ Differences: " "-" "-\x1b[0m" |
| 122 |
diff --color -I "url.checked = " -I "url.size = " -I "url.md5 = " -I "numpages = " -I "numpages = " "${goodFile}" "${outputFile}" || true |
| 123 |
echo "" |
| 124 |
cp "${outputFile}" "${badFile}" |
| 125 |
) >&2 |
| 126 |
exit 1 |
| 127 |
else |
| 128 |
echo -e "\x1b[33mOKAY!\x1b[0m" |
| 129 |
fi |
| 130 |
else |
| 131 |
echo -e "\x1b[35mN/A!\x1b[0m" |
| 132 |
echo "*** No good file for $(basename "${outputFile}")! ***" |
| 133 |
fi |
| 134 |
done |