🐙 Templated web page generator for your git repositories
git clone https://github.com/m-col/gitja
Files | Refs | Readme | License

-rwxr-xr-x test/test.sh


      1 #!/usr/bin/env bash
      2 : '
      3 
      4 Testing gitja
      5 =============
      6 
      7 Running `make test` or `./test/test.sh` from the root project folder will run
      8 this script, which tests gitja.
      9 
     10 Beside this file is the config file that gitja uses. It runs using the
     11 templates in this folder and outputs into this folder. Then the output is
     12 compared with expected results.
     13 
     14 Hopefully this will do until a "proper" test setup is needed.
     15 
     16 '
     17 
     18 set -u
     19 
     20 if [[ $(basename "$PWD") != gitja ]]
     21 then
     22     echo "The test script should be run from the gitja root project folder."
     23     exit 1
     24 fi
     25 
     26 let errors="0"
     27 EXPECTED="test/expected"
     28 RESULT="test/result"
     29 rm -fr "$RESULT"
     30 
     31 declare -a TESTS
     32 TESTS=(
     33     "index.html"  # Index scope
     34     "link.html"  # Symbolic link at top level
     35     "style.css"  # Static file at top level
     36     "static/a_nice_file"  # Static folder at top level
     37     "gitja/index.html"  # Repo scope
     38     "gitja/commit/0292014748caae952bbc8dd6225680d83c0a5135.html"  # A commit
     39     "gitja/blob/test.templates.style.css.html"  # A plain text file
     40     "so_called_binary_file"  # Static file at top level that git considers binary
     41     "gitja/blob/test.templates.so_called_binary_file.html"  # The binary file
     42     "gitja/blob/github.FUNDING.yml.html"  # HREF drops leading period
     43     "gitja/log.html"  # Symbolic link inside repo/
     44     "gitja/static/another_file"  # Static folder inside repo/
     45 )
     46 
     47 stack run -- -c test/config.dhall -q || exit 1
     48 
     49 for test in "${TESTS[@]}"
     50 do
     51     diff --text --strip-trailing-cr \
     52 	"$EXPECTED/$test" "$RESULT/$test" || {
     53 	    let errors+=1
     54 	    echo "^ ERRORED ON: $test"
     55 	}
     56 done
     57 
     58 test -f "$RESULT/title.html.include" && {
     59     let errors+=1
     60     echo "title.html.include found in results"
     61 }
     62 
     63 case "$errors" in
     64     0)
     65 	echo "All good!"
     66 	rm -r "$RESULT"
     67 	;;
     68     *)
     69 	echo "Had this many errors: $errors"
     70 	;;
     71 esac
     72 
     73 exit $errors
     74