aboutsummaryrefslogtreecommitdiff
path: root/tests/integration.sh
blob: 8fa13e9cd10dc54c75893d55ab527f52676ee138 (plain) (blame)
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
#!/bin/sh
set -u

. tests/lib.sh

assert_file() {
	if ! diff "$2" "$1"; then
		printf '\n%s: File content differs.\n' \
			"$(ERROR)" >&2
		printf '\nexpected: %s\ngot:      %s\n\n' "$1" "$2" >&2
		print_debug_info
		exit 1
	fi
}

test_index_generation() {
	testing 'index generation'

	N="$LINENO"
	OUT="$(mkstemp)"
	ERR="$(mkstemp)"
	DIR="$(mkdtemp)"
	./gistatic -i -o "$DIR" tests/resources/repositories/* 1>"$OUT" 2>"$ERR"
	STATUS=$?
	assert_empty_stdout
	assert_empty_stderr
	assert_status 0
	assert_file tests/resources/assets/style.css  "$DIR/style.css"
	assert_file tests/resources/assets/logo.svg   "$DIR/logo.svg"
	assert_file tests/resources/assets/index.html "$DIR/index.html"

	test_ok
}

test_repo_generation() {
	testing 'repo generation'

	N="$LINENO"
	OUT="$(mkstemp)"
	ERR="$(mkstemp)"
	DIR="$(mkdtemp)"
	./gistatic -o "$DIR" -u https://example.com/ \
		tests/resources/repositories/repo-1 1>"$OUT" 2>"$ERR"
	STATUS=$?
	assert_empty_stdout
	assert_empty_stderr
	assert_status 0

	assert_file tests/resources/assets/repo/style.css "$DIR/style.css"
	assert_file tests/resources/assets/repo/logo.svg  "$DIR/logo.svg"
	assert_file tests/resources/assets/repo/refs.html "$DIR/refs.html"

	test_ok
}

test_index_generation
test_repo_generation