source: tanzpartie-hugo/themes/bilberry-hugo-theme/testing/testing-example-site/test-theme.sh @ 16971

Last change on this file since 16971 was 16971, checked in by Henrik Bettermann, 2 years ago
File size: 5.1 KB
Line 
1#!/bin/bash
2
3set -e
4
5SOURCE="${BASH_SOURCE[0]}"
6while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
7  DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
8  SOURCE="$(readlink "$SOURCE")"
9  [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
10done
11DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
12
13TARGET_DIR="$DIR/public"
14
15"${DIR}"/setup-theme.sh
16
17
18ERROR_COUNT=0
19incErrorCount () {
20  ERROR_COUNT=$((ERROR_COUNT + 1))
21}
22
23cleanBuildHugo () {
24  rm -rf $TARGET_DIR
25  cd "$DIR" && hugo
26}
27
28fail () {
29  incErrorCount
30  echo "$1"
31  echo "Exiting now..."
32  exit 1
33}
34
35failButContinue () {
36  incErrorCount
37  echo "! $1"
38}
39
40testFolderAndContinue () {
41  if [ ! -d "$1" ]; then
42    failButContinue "Expected '$(realpath --relative-to="$TARGET_DIR" "$1")' but does not exist"
43  fi
44}
45
46testContentAndContinue () {
47
48  local FILE
49  FILE=$2
50  local TEST_CONTENT
51  TEST_CONTENT=$1
52  local OUT
53  set +e
54  OUT=$(grep -w "$TEST_CONTENT" "$FILE")
55  set -e
56
57  if [[ -z $OUT ]]; then
58    failButContinue "Expected to find '$TEST_CONTENT' in file '$(realpath --relative-to="$TARGET_DIR" "$FILE")'"
59  fi
60
61}
62
63
64cleanBuildHugo
65
66if [ ! -d "$TARGET_DIR" ]; then
67  fail "Compile failed - '$TARGET_DIR' does not exist"
68fi
69
70if [ ! -d "$TARGET_DIR" ]; then
71  failButContinue "Expected '$TARGET_DIR' but does not exist"
72fi
73
74echo "# Umlauts tests"
75testFolderAndContinue "$TARGET_DIR/author/ä-ß+"
76
77testFolderAndContinue "$TARGET_DIR/article/täst"
78testFolderAndContinue "$TARGET_DIR/de/article/täst"
79
80testFolderAndContinue "$TARGET_DIR/categories/täst++"
81testFolderAndContinue "$TARGET_DIR/de/categories/täst++"
82
83testFolderAndContinue "$TARGET_DIR/tags/c++"
84testFolderAndContinue "$TARGET_DIR/de/tags/c++"
85
86testFolderAndContinue "$TARGET_DIR/tags/tästing++"
87testFolderAndContinue "$TARGET_DIR/de/tags/tästing++"
88
89# article/täst [en]
90echo "## Testing article/täst [en]"
91testContentAndContinue '<a href="https://example.com/categories/t%C3%A4st&#43;&#43;/">Täst&#43;&#43;</a>' "$TARGET_DIR/article/täst/index.html"
92testContentAndContinue '<a href="https://example.com/author/%C3%A4-%C3%9F&#43;/">ä ß&#43;</a>' "$TARGET_DIR/article/täst/index.html"
93testContentAndContinue '<a href="https://example.com/tags/c&#43;&#43;/">C&#43;&#43;</a>' "$TARGET_DIR/article/täst/index.html"
94testContentAndContinue '<a href="https://example.com/tags/t%C3%A4sting&#43;&#43;/">tästing&#43;&#43;</a>' "$TARGET_DIR/article/täst/index.html"
95testContentAndContinue '<a href="https://example.com/de/article/t%C3%A4st/">de</a>' "$TARGET_DIR/article/täst/index.html"
96testContentAndContinue '<a href="https://example.com/article/t%C3%A4st/">Umlauts Täst&#43;&#43;</a>' "$TARGET_DIR/article/täst/index.html"
97testContentAndContinue '<p>This is a umlauts-test in Quotes äüöß++</p>' "$TARGET_DIR/quote/index.html"
98testContentAndContinue '<a href="/categories/t%C3%A4st&#43;&#43;">Täst&#43;&#43;
99                        (2)</a>' "$TARGET_DIR/article/täst/index.html"
100
101# article/täst [de]
102echo "## Testing article/täst [de]"
103testContentAndContinue '<a href="https://example.com/de/categories/t%C3%A4st&#43;&#43;/">Täst&#43;&#43;</a>' "$TARGET_DIR/de/article/täst/index.html"
104testContentAndContinue '<a href="https://example.com/de/author/%C3%A4-%C3%9F&#43;/">ä ß&#43;</a>' "$TARGET_DIR/de/article/täst/index.html"
105testContentAndContinue '<a href="https://example.com/de/tags/c&#43;&#43;/">C&#43;&#43;</a>' "$TARGET_DIR/de/article/täst/index.html"
106testContentAndContinue '<a href="https://example.com/de/tags/t%C3%A4sting&#43;&#43;/">tästing&#43;&#43;</a>' "$TARGET_DIR/de/article/täst/index.html"
107testContentAndContinue '<a href="https://example.com/article/t%C3%A4st/">en</a>' "$TARGET_DIR/de/article/täst/index.html"
108testContentAndContinue '<a href="https://example.com/de/article/t%C3%A4st/">de Umlauts Täst&#43;&#43;</a>' "$TARGET_DIR/de/article/täst/index.html"
109testContentAndContinue '<p>de This is a umlauts-test in quotes äüöß++</p>' "$TARGET_DIR/de/quote/index.html"
110testContentAndContinue '<a href="/de/categories/t%C3%A4st&#43;&#43;">Täst&#43;&#43;
111                        (2)</a>' "$TARGET_DIR/de/article/täst/index.html"
112
113# quote/täst-quote [en]
114echo "## Testing quote/täst-quote [en]"
115testContentAndContinue '<a href="/author/%c3%a4-%c3%9f&#43;">
116  ä ß&#43;
117</a>' "$TARGET_DIR/quote/täst-quote/index.html"
118
119# quote/täst-quote [de]
120echo "## Testing quote/täst-quote [de]"
121testContentAndContinue '<a href="/de/author/%c3%a4-%c3%9f&#43;">
122  ä ß&#43;
123</a>' "$TARGET_DIR/de/quote/täst-quote/index.html"
124
125
126echo "# Build stability test"
127
128BUILD_COUNT=100
129for ((i=0; i<BUILD_COUNT; i++)) ; do
130 echo "Building ($i)"
131 cleanBuildHugo > /dev/null
132 rm -rf "$TARGET_DIR$i"
133 mv "$TARGET_DIR" "$TARGET_DIR$i"
134done
135
136DIFF_OUT=""
137set +e
138for ((i=1; i<BUILD_COUNT; i++)) ; do
139 echo "Calculating differences between $i and $((i-1))"
140 DIFF_OUT="$DIFF_OUT$(diff -rq "$TARGET_DIR$i" "$TARGET_DIR$((i-1))")"
141done
142set -e
143
144if [[ $DIFF_OUT != "" ]]; then
145   failButContinue "Build is instable! expected to receive no differences but was: $DIFF_OUT"
146fi
147
148
149
150echo "Tests finished with $ERROR_COUNT errors"
151exit $ERROR_COUNT
Note: See TracBrowser for help on using the repository browser.