[16971] | 1 | #!/bin/bash |
---|
| 2 | |
---|
| 3 | set -e |
---|
| 4 | |
---|
| 5 | SOURCE="${BASH_SOURCE[0]}" |
---|
| 6 | while [ -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 |
---|
| 10 | done |
---|
| 11 | DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )" |
---|
| 12 | |
---|
| 13 | TARGET_DIR="$DIR/public" |
---|
| 14 | |
---|
| 15 | "${DIR}"/setup-theme.sh |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | ERROR_COUNT=0 |
---|
| 19 | incErrorCount () { |
---|
| 20 | ERROR_COUNT=$((ERROR_COUNT + 1)) |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | cleanBuildHugo () { |
---|
| 24 | rm -rf $TARGET_DIR |
---|
| 25 | cd "$DIR" && hugo |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | fail () { |
---|
| 29 | incErrorCount |
---|
| 30 | echo "$1" |
---|
| 31 | echo "Exiting now..." |
---|
| 32 | exit 1 |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | failButContinue () { |
---|
| 36 | incErrorCount |
---|
| 37 | echo "! $1" |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | testFolderAndContinue () { |
---|
| 41 | if [ ! -d "$1" ]; then |
---|
| 42 | failButContinue "Expected '$(realpath --relative-to="$TARGET_DIR" "$1")' but does not exist" |
---|
| 43 | fi |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | testContentAndContinue () { |
---|
| 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 | |
---|
| 64 | cleanBuildHugo |
---|
| 65 | |
---|
| 66 | if [ ! -d "$TARGET_DIR" ]; then |
---|
| 67 | fail "Compile failed - '$TARGET_DIR' does not exist" |
---|
| 68 | fi |
---|
| 69 | |
---|
| 70 | if [ ! -d "$TARGET_DIR" ]; then |
---|
| 71 | failButContinue "Expected '$TARGET_DIR' but does not exist" |
---|
| 72 | fi |
---|
| 73 | |
---|
| 74 | echo "# Umlauts tests" |
---|
| 75 | testFolderAndContinue "$TARGET_DIR/author/ä-ß+" |
---|
| 76 | |
---|
| 77 | testFolderAndContinue "$TARGET_DIR/article/täst" |
---|
| 78 | testFolderAndContinue "$TARGET_DIR/de/article/täst" |
---|
| 79 | |
---|
| 80 | testFolderAndContinue "$TARGET_DIR/categories/täst++" |
---|
| 81 | testFolderAndContinue "$TARGET_DIR/de/categories/täst++" |
---|
| 82 | |
---|
| 83 | testFolderAndContinue "$TARGET_DIR/tags/c++" |
---|
| 84 | testFolderAndContinue "$TARGET_DIR/de/tags/c++" |
---|
| 85 | |
---|
| 86 | testFolderAndContinue "$TARGET_DIR/tags/tästing++" |
---|
| 87 | testFolderAndContinue "$TARGET_DIR/de/tags/tästing++" |
---|
| 88 | |
---|
| 89 | # article/täst [en] |
---|
| 90 | echo "## Testing article/täst [en]" |
---|
| 91 | testContentAndContinue '<a href="https://example.com/categories/t%C3%A4st++/">Täst++</a>' "$TARGET_DIR/article/täst/index.html" |
---|
| 92 | testContentAndContinue '<a href="https://example.com/author/%C3%A4-%C3%9F+/">ä ß+</a>' "$TARGET_DIR/article/täst/index.html" |
---|
| 93 | testContentAndContinue '<a href="https://example.com/tags/c++/">C++</a>' "$TARGET_DIR/article/täst/index.html" |
---|
| 94 | testContentAndContinue '<a href="https://example.com/tags/t%C3%A4sting++/">tästing++</a>' "$TARGET_DIR/article/täst/index.html" |
---|
| 95 | testContentAndContinue '<a href="https://example.com/de/article/t%C3%A4st/">de</a>' "$TARGET_DIR/article/täst/index.html" |
---|
| 96 | testContentAndContinue '<a href="https://example.com/article/t%C3%A4st/">Umlauts Täst++</a>' "$TARGET_DIR/article/täst/index.html" |
---|
| 97 | testContentAndContinue '<p>This is a umlauts-test in Quotes äüöß++</p>' "$TARGET_DIR/quote/index.html" |
---|
| 98 | testContentAndContinue '<a href="/categories/t%C3%A4st++">Täst++ |
---|
| 99 | (2)</a>' "$TARGET_DIR/article/täst/index.html" |
---|
| 100 | |
---|
| 101 | # article/täst [de] |
---|
| 102 | echo "## Testing article/täst [de]" |
---|
| 103 | testContentAndContinue '<a href="https://example.com/de/categories/t%C3%A4st++/">Täst++</a>' "$TARGET_DIR/de/article/täst/index.html" |
---|
| 104 | testContentAndContinue '<a href="https://example.com/de/author/%C3%A4-%C3%9F+/">ä ß+</a>' "$TARGET_DIR/de/article/täst/index.html" |
---|
| 105 | testContentAndContinue '<a href="https://example.com/de/tags/c++/">C++</a>' "$TARGET_DIR/de/article/täst/index.html" |
---|
| 106 | testContentAndContinue '<a href="https://example.com/de/tags/t%C3%A4sting++/">tästing++</a>' "$TARGET_DIR/de/article/täst/index.html" |
---|
| 107 | testContentAndContinue '<a href="https://example.com/article/t%C3%A4st/">en</a>' "$TARGET_DIR/de/article/täst/index.html" |
---|
| 108 | testContentAndContinue '<a href="https://example.com/de/article/t%C3%A4st/">de Umlauts Täst++</a>' "$TARGET_DIR/de/article/täst/index.html" |
---|
| 109 | testContentAndContinue '<p>de This is a umlauts-test in quotes äüöß++</p>' "$TARGET_DIR/de/quote/index.html" |
---|
| 110 | testContentAndContinue '<a href="/de/categories/t%C3%A4st++">Täst++ |
---|
| 111 | (2)</a>' "$TARGET_DIR/de/article/täst/index.html" |
---|
| 112 | |
---|
| 113 | # quote/täst-quote [en] |
---|
| 114 | echo "## Testing quote/täst-quote [en]" |
---|
| 115 | testContentAndContinue '<a href="/author/%c3%a4-%c3%9f+"> |
---|
| 116 | ä ß+ |
---|
| 117 | </a>' "$TARGET_DIR/quote/täst-quote/index.html" |
---|
| 118 | |
---|
| 119 | # quote/täst-quote [de] |
---|
| 120 | echo "## Testing quote/täst-quote [de]" |
---|
| 121 | testContentAndContinue '<a href="/de/author/%c3%a4-%c3%9f+"> |
---|
| 122 | ä ß+ |
---|
| 123 | </a>' "$TARGET_DIR/de/quote/täst-quote/index.html" |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | echo "# Build stability test" |
---|
| 127 | |
---|
| 128 | BUILD_COUNT=100 |
---|
| 129 | for ((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" |
---|
| 134 | done |
---|
| 135 | |
---|
| 136 | DIFF_OUT="" |
---|
| 137 | set +e |
---|
| 138 | for ((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))")" |
---|
| 141 | done |
---|
| 142 | set -e |
---|
| 143 | |
---|
| 144 | if [[ $DIFF_OUT != "" ]]; then |
---|
| 145 | failButContinue "Build is instable! expected to receive no differences but was: $DIFF_OUT" |
---|
| 146 | fi |
---|
| 147 | |
---|
| 148 | |
---|
| 149 | |
---|
| 150 | echo "Tests finished with $ERROR_COUNT errors" |
---|
| 151 | exit $ERROR_COUNT |
---|