aboutsummaryrefslogtreecommitdiffstats
path: root/tests/tests.sh
blob: 7ead650cde6b69f1816d5aeb518135f4809357b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env bash
#
# Copyright (C) 2024 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
#
# 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 <https://www.gnu.org/licenses/>.

nr_errors=0

# Test the CommonMark files
for file in posts/*.md ; do
    # Test licenses compliance.
    if grep '^licenses: ' "${file}" > /dev/null ; then
	echo "[ OK ] ${file}: has a license."
    else
	echo "[ !! ] ${file}: license is missing."
	nr_errors=$((nr_errors + 1))
    fi
    # Test for authorship information.
    if grep '^authors: ' "${file}" > /dev/null ; then
	echo "[ OK ] ${file}: has a authorship information."
    else
	echo "[ !! ] ${file}: authorship information missing."
	nr_errors=$((nr_errors + 1))
    fi
done

# Test generated HTML files.
for file in site/*.html ; do
    # Test for unknown characters.
    if grep '??' "${file}" > /dev/null ; then
	echo "[ !! ] ${file}"
	nr_errors=$((nr_errors + 1))
    else
	echo "[ OK ] ${file}"
    fi
done

# Test shell scripts.
if shellcheck -x tests/tests.sh ; then
    echo "[ OK ] tests/tests.sh"
else
    nr_errors=$((nr_errors + 1))
    echo "[ !! ] tests/tests.sh"
fi

# Fail if some errors were found.
echo "${nr_errors} errors found."
if [ ${nr_errors} -gt 0 ] ; then
    exit 1
fi