diff options
author | Lukas Fleischer <cgit@cryptocrack.de> | 2014-01-15 06:25:45 (JST) |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2014-01-15 22:45:21 (JST) |
commit | caf557a2ba666ad87a1ebd5b40750feaf1bd631f (patch) | |
tree | 8de9226af92266c06712bf4b480f19eb679c79a7 /tests | |
parent | 8ae1d8b8fd0b097b10716d0d2d8acaadbd7a46f7 (diff) | |
download | cgit-caf557a2ba666ad87a1ebd5b40750feaf1bd631f.zip cgit-caf557a2ba666ad87a1ebd5b40750feaf1bd631f.tar.gz |
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>
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/filters/capitalize-argv1.sh | 3 | ||||
-rw-r--r-- | tests/filters/capitalize-buffer.lua | 17 | ||||
-rwxr-xr-x | tests/filters/capitalize-stdin.sh | 1 | ||||
-rwxr-xr-x | tests/setup.sh | 13 | ||||
-rwxr-xr-x | tests/t0111-filter.sh | 65 |
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 | |||
3 | echo "$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 @@ | |||
1 | function filter_open(...) | ||
2 | buffer = "" | ||
3 | for i = 1, select("#", ...) do | ||
4 | buffer = buffer .. select(i, ...) .. " " | ||
5 | end | ||
6 | end | ||
7 | |||
8 | function filter_close() | ||
9 | html(buffer) | ||
10 | return 0 | ||
11 | end | ||
12 | |||
13 | function filter_write(str) | ||
14 | buffer = buffer .. string.upper(str) | ||
15 | end | ||
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 " "$*" | ||
3 | tr '[:lower:]' '[:upper:]' | 4 | tr '[: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 | |||
125 | repo.path=$PWD/repos/with space/.git | 125 | repo.path=$PWD/repos/with space/.git |
126 | repo.desc=spaced repo | 126 | repo.desc=spaced repo |
127 | 127 | ||
128 | repo.url=filter | 128 | repo.url=filter-exec |
129 | repo.path=$PWD/repos/filter/.git | 129 | repo.path=$PWD/repos/filter/.git |
130 | repo.desc=filtered repo | 130 | repo.desc=filtered repo |
131 | repo.about-filter=exec:$FILTER_DIRECTORY/capitalize-stdin.sh | 131 | repo.about-filter=exec:$FILTER_DIRECTORY/capitalize-stdin.sh |
132 | repo.commit-filter=exec:$FILTER_DIRECTORY/capitalize-stdin.sh | 132 | repo.commit-filter=exec:$FILTER_DIRECTORY/capitalize-stdin.sh |
133 | repo.email-filter=exec:$FILTER_DIRECTORY/capitalize-argv1.sh | 133 | repo.email-filter=exec:$FILTER_DIRECTORY/capitalize-stdin.sh |
134 | repo.source-filter=exec:$FILTER_DIRECTORY/capitalize-stdin.sh | 134 | repo.source-filter=exec:$FILTER_DIRECTORY/capitalize-stdin.sh |
135 | repo.readme=master:a+b | 135 | repo.readme=master:a+b |
136 | |||
137 | repo.url=filter-lua | ||
138 | repo.path=$PWD/repos/filter/.git | ||
139 | repo.desc=filtered repo | ||
140 | repo.about-filter=lua:$FILTER_DIRECTORY/capitalize-buffer.lua | ||
141 | repo.commit-filter=lua:$FILTER_DIRECTORY/capitalize-buffer.lua | ||
142 | repo.email-filter=lua:$FILTER_DIRECTORY/capitalize-buffer.lua | ||
143 | repo.source-filter=lua:$FILTER_DIRECTORY/capitalize-buffer.lua | ||
144 | repo.readme=master:a+b | ||
136 | EOF | 145 | EOF |
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 @@ | |||
3 | test_description='Check filtered content' | 3 | test_description='Check filtered content' |
4 | . ./setup.sh | 4 | . ./setup.sh |
5 | 5 | ||
6 | test_expect_success 'generate filter/tree/a%2bb' ' | 6 | for prefix in exec lua |
7 | cgit_url "filter/tree/a%2bb" >tmp | 7 | do |
8 | ' | 8 | test_expect_success "generate filter-$prefix/tree/a%2bb" " |
9 | 9 | cgit_url 'filter-$prefix/tree/a%2bb' >tmp | |
10 | test_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 | |
14 | test_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 | |
18 | test_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 | |
22 | test_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 | |
26 | test_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 | |
30 | test_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 <AUTHOR@EXAMPLE.COM>" tmp | |
34 | test_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 <COMMITTER@EXAMPLE.COM>" tmp | ||
38 | ' | ||
39 | done | ||
37 | 40 | ||
38 | test_done | 41 | test_done |