about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorLukas Fleischer2014-01-14 22:25:45 +0100
committerJason A. Donenfeld2014-01-15 14:45:21 +0100
commitcaf557a2ba666ad87a1ebd5b40750feaf1bd631f (patch)
tree8de9226af92266c06712bf4b480f19eb679c79a7
parentemail-gravatar: fix html syntax issues (diff)
downloadcgit-caf557a2ba666ad87a1ebd5b40750feaf1bd631f.tar.gz
cgit-caf557a2ba666ad87a1ebd5b40750feaf1bd631f.zip
t0111: Add basic tests for Lua filters
* Validate the email filter by manipulating stdin. Additional checks for
  all the arguments can be added in a later patch.

* Add the exec prefix to all informational messages.

* Rename the filter repository to filter-exec. The Git repository itself
  is not renamed since it can be shared amongst all filter types.

* In the filter checks, check whether all arguments are passed properly
  instead of validating the buffer/stdin only.

Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
-rwxr-xr-xtests/filters/capitalize-argv1.sh3
-rw-r--r--tests/filters/capitalize-buffer.lua17
-rwxr-xr-xtests/filters/capitalize-stdin.sh1
-rwxr-xr-xtests/setup.sh13
-rwxr-xr-xtests/t0111-filter.sh65
5 files changed, 63 insertions, 36 deletions
diff --git a/tests/filters/capitalize-argv1.sh b/tests/filters/capitalize-argv1.sh deleted file mode 100755 index 2ea0098..0000000 --- a/tests/filters/capitalize-argv1.sh +++ /dev/null
@@ -1,3 +0,0 @@
1#!/bin/sh
2
3echo "$1" | tr '[:lower:]' '[:upper:]'
diff --git a/tests/filters/capitalize-buffer.lua b/tests/filters/capitalize-buffer.lua new file mode 100644 index 0000000..1f15c93 --- /dev/null +++ b/tests/filters/capitalize-buffer.lua
@@ -0,0 +1,17 @@
1function filter_open(...)
2 buffer = ""
3 for i = 1, select("#", ...) do
4 buffer = buffer .. select(i, ...) .. " "
5 end
6end
7
8function filter_close()
9 html(buffer)
10 return 0
11end
12
13function filter_write(str)
14 buffer = buffer .. string.upper(str)
15end
16
17
diff --git a/tests/filters/capitalize-stdin.sh b/tests/filters/capitalize-stdin.sh index c9f4719..da6f7a1 100755 --- a/tests/filters/capitalize-stdin.sh +++ b/tests/filters/capitalize-stdin.sh
@@ -1,3 +1,4 @@
1#!/bin/sh 1#!/bin/sh
2 2
3[ "$#" -gt 0 ] && printf "%s " "$*"
3tr '[:lower:]' '[:upper:]' 4tr '[:lower:]' '[:upper:]'
diff --git a/tests/setup.sh b/tests/setup.sh index 861f48a..12c97f5 100755 --- a/tests/setup.sh +++ b/tests/setup.sh
@@ -125,14 +125,23 @@ repo.url=with space
125repo.path=$PWD/repos/with space/.git 125repo.path=$PWD/repos/with space/.git
126repo.desc=spaced repo 126repo.desc=spaced repo
127 127
128repo.url=filter 128repo.url=filter-exec
129repo.path=$PWD/repos/filter/.git 129repo.path=$PWD/repos/filter/.git
130repo.desc=filtered repo 130repo.desc=filtered repo
131repo.about-filter=exec:$FILTER_DIRECTORY/capitalize-stdin.sh 131repo.about-filter=exec:$FILTER_DIRECTORY/capitalize-stdin.sh
132repo.commit-filter=exec:$FILTER_DIRECTORY/capitalize-stdin.sh 132repo.commit-filter=exec:$FILTER_DIRECTORY/capitalize-stdin.sh
133repo.email-filter=exec:$FILTER_DIRECTORY/capitalize-argv1.sh 133repo.email-filter=exec:$FILTER_DIRECTORY/capitalize-stdin.sh
134repo.source-filter=exec:$FILTER_DIRECTORY/capitalize-stdin.sh 134repo.source-filter=exec:$FILTER_DIRECTORY/capitalize-stdin.sh
135repo.readme=master:a+b 135repo.readme=master:a+b
136
137repo.url=filter-lua
138repo.path=$PWD/repos/filter/.git
139repo.desc=filtered repo
140repo.about-filter=lua:$FILTER_DIRECTORY/capitalize-buffer.lua
141repo.commit-filter=lua:$FILTER_DIRECTORY/capitalize-buffer.lua
142repo.email-filter=lua:$FILTER_DIRECTORY/capitalize-buffer.lua
143repo.source-filter=lua:$FILTER_DIRECTORY/capitalize-buffer.lua
144repo.readme=master:a+b
136EOF 145EOF
137} 146}
138 147
diff --git a/tests/t0111-filter.sh b/tests/t0111-filter.sh index 2f99880..c89020a 100755 --- a/tests/t0111-filter.sh +++ b/tests/t0111-filter.sh
@@ -3,36 +3,39 @@
3test_description='Check filtered content' 3test_description='Check filtered content'
4. ./setup.sh 4. ./setup.sh
5 5
6test_expect_success 'generate filter/tree/a%2bb' ' 6for prefix in exec lua
7 cgit_url "filter/tree/a%2bb" >tmp 7do
8' 8 test_expect_success "generate filter-$prefix/tree/a%2bb" "
9 9 cgit_url 'filter-$prefix/tree/a%2bb' >tmp
10test_expect_success 'check whether the source filter works' ' 10 "
11 grep "<code>HELLO$" tmp 11
12' 12 test_expect_success "check whether the $prefix source filter works" '
13 13 grep "<code>a+b HELLO$" tmp
14test_expect_success 'generate filter/about/' ' 14 '
15 cgit_url "filter/about/" >tmp 15
16' 16 test_expect_success "generate filter-$prefix/about/" "
17 17 cgit_url 'filter-$prefix/about/' >tmp
18test_expect_success 'check whether the about filter works' ' 18 "
19 grep "<div id='"'"'summary'"'"'>HELLO$" tmp 19
20' 20 test_expect_success "check whether the $prefix about filter works" '
21 21 grep "<div id='"'"'summary'"'"'>a+b HELLO$" tmp
22test_expect_success 'generate filter/commit/' ' 22 '
23 cgit_url "filter/commit/" >tmp 23
24' 24 test_expect_success "generate filter-$prefix/commit/" "
25 25 cgit_url 'filter-$prefix/commit/' >tmp
26test_expect_success 'check whether the commit filter works' ' 26 "
27 grep "<div class='"'"'commit-subject'"'"'>ADD A+B" tmp 27
28' 28 test_expect_success "check whether the $prefix commit filter works" '
29 29 grep "<div class='"'"'commit-subject'"'"'>ADD A+B" tmp
30test_expect_success 'check whether the email filter works for authors' ' 30 '
31 grep "<AUTHOR@EXAMPLE.COM>" tmp 31
32' 32 test_expect_success "check whether the $prefix email filter works for authors" '
33 33 grep "A U THOR &LT;AUTHOR@EXAMPLE.COM&GT;" tmp
34test_expect_success 'check whether the email filter works for committers' ' 34 '
35 grep "<COMMITTER@EXAMPLE.COM>" tmp 35
36' 36 test_expect_success "check whether the $prefix email filter works for committers" '
37 grep "C O MITTER &LT;COMMITTER@EXAMPLE.COM&GT;" tmp
38 '
39done
37 40
38test_done 41test_done