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

Commit 7228d7efac9be1c4a26a6fbf8ff78ec59194c47c
Parent: 343b0d5aff98ca8f204751ae82b4b64277a8fb24
Author: mcol <mcol@posteo.net>
Date: 2021-11-25 19:46:01 +0000
Committer: mcol <mcol@posteo.net>
Committed: 2021-11-25 19:46:01 +0000

Add hacky tests

test/test.sh Added

@@ -0,0 +1,54 @@
+#!/usr/bin/env bash
+: '
+
+Testing gitserve
+================
+
+Running `make test` or `./test/test.sh` from the root project folder will run
+this script, which tests gitserve.
+
+Beside this file is the config file that gitserve uses. It runs using the
+templates in this folder and outputs into this folder. Then the output is
+compared with expected results.
+
+Hopefully this will do until a "proper" test setup is needed.
+
+'
+
+if [[ $(basename "$PWD") != gitserve ]]
+then
+    echo "The test script should be run from the gitserve root project folder."
+    exit 1
+fi
+
+rm -rf test/output
+stack run -- -c test/config.dhall
+
+let error=0
+
+error() {
+    echo Failed: $1
+    echo Expected: $2
+    echo But got: $3
+
+    let error+=1
+}
+
+commit_file="test/output/gitserve/commit/0292014748caae952bbc8dd6225680d83c0a5135.html"
+commit_result="$(cat $commit_file)"
+commit_expected="0292014748caae952bbc8dd6225680d83c0a5135"
+
+[[ "$commit_result" != "$commit_expected" ]] || {
+    error "$commit_file" "$commit_expected" "$commit_result"
+}
+
+case "$error" in
+    0)
+	echo "All good!"
+	exit 0
+	;;
+    *)
+	echo "Had this many errors: $error"
+	exit $error
+	;;
+esac

test/templates/title.html.include Added

@@ -0,0 +1,4 @@
+{#- This tests using include files. -#}
+{#- This file should not appear in the outputfolder. -#}
+
+{% block title %}{% endblock %}

test/templates/style.css Added

@@ -0,0 +1 @@
+👄

test/templates/repo/index.html Added

@@ -0,0 +1,6 @@
+{% extends "../title.html.include" -%}
+{%- block title -%}{{ repo.name }}{%- endblock -%}
+
+{% block body %}
+repository
+{% endblock %}

test/templates/repo/file.html Added

@@ -0,0 +1,6 @@
+{% extends "../title.html.include" -%}
+{%- block title -%}{{ file.path }}{%- endblock -%}
+
+{% block body %}
+file
+{% endblock %}

test/templates/repo/commit.html Added

@@ -0,0 +1,6 @@
+{% extends "../title.html.include" -%}
+{%- block title -%}{{ commit.id }}{%- endblock -%}
+
+{% block body %}
+commit
+{% endblock %}

test/templates/index.html Added

@@ -0,0 +1,6 @@
+{% extends "title.html.include" %}
+{%- block title -%}{{ host }}{%- endblock -%}
+
+{% block body %}
+index
+{% endblock %}

test/config.dhall Added

@@ -0,0 +1,8 @@
+let config =
+    { repoPaths = ["."]
+    , templateDirectory = "./test/templates"
+    , outputDirectory = "./test/output"
+    , host = "https://github.com/m-col/gitserve"
+    }
+
+in config

Makefile Modified

@@ -33,3 +33,7 @@
 run: ## Run gitserve on this repository into ./output/
 	rm -rf output
 	stack run
+
+.PHONY: test
+test: ## Run the "tests"
+	bash ./test/test.sh

.gitignore Modified

@@ -1,4 +1,5 @@
 .stack-work/
 *~
 output
+test/output
 dist-newstyle