forked from rsdoiel/mkpage
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_cmd.bash
executable file
·137 lines (118 loc) · 3.62 KB
/
test_cmd.bash
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
function assert_exists() {
if [ "$#" != "2" ]; then
echo "wrong number of parameters for $1, $@"
exit 1
fi
if [[ ! -f "$2" && ! -d "$2" ]]; then
echo "$1: $2 does not exists"
exit 1
fi
}
function assert_equal() {
if [ "$#" != "3" ]; then
echo "wrong number of parameters for $1, $@"
exit 1
fi
if [ "$2" != "$3" ]; then
echo "$1: expected |$2| got |$3|"
exit 1
fi
}
function assert_empty() {
if [ "$#" != "2" ]; then
echo "wrong number of parameters for $1, $@"
exit 1
fi
if [ "$2" != "" ]; then
echo "$1: expected empty string got |$2|"
exit 1
fi
}
#
# Tests
#
function test_blogit() {
mkdir -p test/blog
if ! bin/blogit --prefix=test/blog README.md '2015-01-03'; then
echo "Failed: bin/blogit --prefix=test/blog README.md 2015-01-03"
exit 1
fi
if ! bin/blogit --prefix=test/blog INSTALL.md '2015-01-03'; then
echo "bin/blogit --prefix=test/blog INSTALL.md 2015-01-03"
exit 1
fi
if ! bin/blogit --prefix=test/blog LICENSE '2015-01-03'; then
echo "bin/blogit --prefix=test/blog LICENSE '2015-01-03'"
exit 1
fi
if ! bin/blogit --prefix=test/blog Pandoc-Integration.md '2020-05-19'; then
echo "bin/blogit --prefix=test/blog Pandoc-Integration.md '2020-05-19'"
exit 1
fi
if ! bin/blogit --prefix=test/blog DEVELOPERS.md '2018-07-01'; then
echo "bin/blogit --prefix=test/blog DEVELOPERS.md '2018-07-01'"
exit 1
fi
echo "test_blogit OK"
}
function test_byline() {
EXPECTED="By J. Q. Public 2018-12-04"
# Test reading from file
RESULT=$(bin/byline -i examples/byline/index.md)
assert_equal "test_byline" "$EXPECTED" "$RESULT"
# Test with standard input
RESULT=$(cat examples/byline/index.md | bin/byline -i - )
assert_equal "test_byline" "$EXPECTED" "$RESULT"
echo "test_byline OK"
}
function test_mkpage() {
# test basic markdown processing
if [[ -f "temp.html" ]]; then rm temp.html; fi
if [[ -f "temp.md" ]]; then rm temp.md; fi
bin/mkpage -f commonmark \
"title=text:Hello World" \
content=examples/helloworld.md page.tmpl > temp.html
EXPECTED=""
assert_exists "test_mkpage (simple)" "temp.html"
RESULT=$(cmp examples/helloworld.html temp.html)
assert_equal "test_mkpage (simple)" "$EXPECTED" "$RESULT"
bin/mkpage -t markdown testdata/codemeta.tmpl \
"codemeta=codemeta.json" > temp.md
EXPECTED=""
assert_exists "test_mkpage (markdown doc)" "temp.md"
RESULT=$(cmp examples/codemeta.md temp.md)
assert_equal "test_mkpage (markdown doc)" "$EXPECTED" "$RESULT"
bin/mkpage -t markdown "title=text:Author Test" \
'authors=json-generator:python3 examples/fmt-authors.py examples/authors-list.json 2 "et el."' \
examples/authors.tmpl > temp.md
assert_exists "test_mkpage (generator)" "temp.md"
RESULT=$(cmp examples/authors.md temp.md)
assert_equal "test_mkpage (generator doc)" "$EXPECTED" "$RESULT"
echo "test_mkpage() OK"
}
function test_reldocpath() {
echo "test_reldocpath() not implemented."
}
function test_sitemapper() {
echo "test_sitemapper() not implemented."
}
function test_titleline() {
echo "test_titleline() not implemented."
}
function test_urldecode() {
echo "test_urldecode() not implemented."
}
function test_urlencode() {
echo "test_urlencode() not implemented."
}
echo "Testing command line tools"
test_byline
test_mkpage
test_blogit
#test_reldocpath
#test_sitemapper
#test_titleline
#test_urldecode
#test_urlencode
echo 'Success!'