diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-03-22 04:15:03 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-03-22 04:15:03 +0000 |
| commit | 1fa65d89ca5dc64756f7933d7cc3f524e4627dce (patch) | |
| tree | df614c8b86b0f7c2f45c2afcacc993ab3c0dcf11 /test | |
| parent | 4919a83d2271a9e43b83c7d488e3f94c850681e3 (diff) | |
| download | luasocket-1fa65d89ca5dc64756f7933d7cc3f524e4627dce.tar.gz luasocket-1fa65d89ca5dc64756f7933d7cc3f524e4627dce.tar.bz2 luasocket-1fa65d89ca5dc64756f7933d7cc3f524e4627dce.zip | |
Adjusted some details, got rid of old files, added some new.
Diffstat (limited to 'test')
| -rw-r--r-- | test/httptest.lua | 36 | ||||
| -rw-r--r-- | test/smtptest.lua | 2 | ||||
| -rw-r--r-- | test/testsupport.lua | 37 | ||||
| -rw-r--r-- | test/urltest.lua | 2 |
4 files changed, 45 insertions, 32 deletions
diff --git a/test/httptest.lua b/test/httptest.lua index ddeea50..4ec0cc1 100644 --- a/test/httptest.lua +++ b/test/httptest.lua | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | -- needs ScriptAlias from /home/c/diego/tec/luasocket/test/cgi | 3 | -- needs ScriptAlias from /home/c/diego/tec/luasocket/test/cgi |
| 4 | -- to "/luasocket-test-cgi" and "/luasocket-test-cgi/" | 4 | -- to "/luasocket-test-cgi" and "/luasocket-test-cgi/" |
| 5 | -- needs "AllowOverride AuthConfig" on /home/c/diego/tec/luasocket/test/auth | 5 | -- needs "AllowOverride AuthConfig" on /home/c/diego/tec/luasocket/test/auth |
| 6 | dofile("noglobals.lua") | 6 | dofile("testsupport.lua") |
| 7 | 7 | ||
| 8 | local host, proxy, request, response, index_file | 8 | local host, proxy, request, response, index_file |
| 9 | local ignore, expect, index, prefix, cgiprefix, index_crlf | 9 | local ignore, expect, index, prefix, cgiprefix, index_crlf |
| @@ -18,33 +18,9 @@ prefix = prefix or "/luasocket-test" | |||
| 18 | cgiprefix = cgiprefix or "/luasocket-test-cgi" | 18 | cgiprefix = cgiprefix or "/luasocket-test-cgi" |
| 19 | index_file = "test/index.html" | 19 | index_file = "test/index.html" |
| 20 | 20 | ||
| 21 | local readfile = function(name) | ||
| 22 | local f = io.open(name, "r") | ||
| 23 | if not f then return nil end | ||
| 24 | local s = f:read("*a") | ||
| 25 | f:close() | ||
| 26 | return s | ||
| 27 | end | ||
| 28 | |||
| 29 | -- read index with CRLF convention | 21 | -- read index with CRLF convention |
| 30 | index = readfile(index_file) | 22 | index = readfile(index_file) |
| 31 | 23 | ||
| 32 | local similar = function(s1, s2) | ||
| 33 | return string.lower(string.gsub(s1 or "", "%s", "")) == | ||
| 34 | string.lower(string.gsub(s2 or "", "%s", "")) | ||
| 35 | end | ||
| 36 | |||
| 37 | local fail = function(s) | ||
| 38 | s = s or "failed!" | ||
| 39 | print(s) | ||
| 40 | os.exit() | ||
| 41 | end | ||
| 42 | |||
| 43 | local check = function (v, e) | ||
| 44 | if v then print("ok") | ||
| 45 | else fail(e) end | ||
| 46 | end | ||
| 47 | |||
| 48 | local check_result = function(response, expect, ignore) | 24 | local check_result = function(response, expect, ignore) |
| 49 | for i,v in response do | 25 | for i,v in response do |
| 50 | if not ignore[i] then | 26 | if not ignore[i] then |
| @@ -171,7 +147,7 @@ check_request(request, expect, ignore) | |||
| 171 | ------------------------------------------------------------------------ | 147 | ------------------------------------------------------------------------ |
| 172 | io.write("testing simple post function: ") | 148 | io.write("testing simple post function: ") |
| 173 | back = socket.http.post("http://" .. host .. cgiprefix .. "/cat", index) | 149 | back = socket.http.post("http://" .. host .. cgiprefix .. "/cat", index) |
| 174 | check(back == index) | 150 | assert(back == index) |
| 175 | 151 | ||
| 176 | ------------------------------------------------------------------------ | 152 | ------------------------------------------------------------------------ |
| 177 | io.write("testing ltn12.(sink|source).file: ") | 153 | io.write("testing ltn12.(sink|source).file: ") |
| @@ -191,7 +167,7 @@ ignore = { | |||
| 191 | } | 167 | } |
| 192 | check_request(request, expect, ignore) | 168 | check_request(request, expect, ignore) |
| 193 | back = readfile(index_file .. "-back") | 169 | back = readfile(index_file .. "-back") |
| 194 | check(back == index) | 170 | assert(back == index) |
| 195 | os.remove(index_file .. "-back") | 171 | os.remove(index_file .. "-back") |
| 196 | 172 | ||
| 197 | ------------------------------------------------------------------------ | 173 | ------------------------------------------------------------------------ |
| @@ -233,7 +209,7 @@ ignore = { | |||
| 233 | } | 209 | } |
| 234 | check_request(request, expect, ignore) | 210 | check_request(request, expect, ignore) |
| 235 | back = readfile(index_file .. "-back") | 211 | back = readfile(index_file .. "-back") |
| 236 | check(back == index) | 212 | assert(back == index) |
| 237 | os.remove(index_file .. "-back") | 213 | os.remove(index_file .. "-back") |
| 238 | 214 | ||
| 239 | ------------------------------------------------------------------------ | 215 | ------------------------------------------------------------------------ |
| @@ -434,7 +410,7 @@ check_request(request, expect, ignore) | |||
| 434 | local body | 410 | local body |
| 435 | io.write("testing simple get function: ") | 411 | io.write("testing simple get function: ") |
| 436 | body = socket.http.get("http://" .. host .. prefix .. "/index.html") | 412 | body = socket.http.get("http://" .. host .. prefix .. "/index.html") |
| 437 | check(body == index) | 413 | assert(body == index) |
| 438 | 414 | ||
| 439 | ------------------------------------------------------------------------ | 415 | ------------------------------------------------------------------------ |
| 440 | io.write("testing HEAD method: ") | 416 | io.write("testing HEAD method: ") |
| @@ -443,7 +419,7 @@ response = socket.http.request { | |||
| 443 | method = "HEAD", | 419 | method = "HEAD", |
| 444 | url = "http://www.cs.princeton.edu/~diego/" | 420 | url = "http://www.cs.princeton.edu/~diego/" |
| 445 | } | 421 | } |
| 446 | check(response and response.headers) | 422 | assert(response and response.headers) |
| 447 | 423 | ||
| 448 | ------------------------------------------------------------------------ | 424 | ------------------------------------------------------------------------ |
| 449 | print("passed all tests") | 425 | print("passed all tests") |
diff --git a/test/smtptest.lua b/test/smtptest.lua index 8468408..e812737 100644 --- a/test/smtptest.lua +++ b/test/smtptest.lua | |||
| @@ -16,7 +16,7 @@ local err | |||
| 16 | 16 | ||
| 17 | dofile("mbox.lua") | 17 | dofile("mbox.lua") |
| 18 | local parse = mbox.parse | 18 | local parse = mbox.parse |
| 19 | dofile("noglobals.lua") | 19 | dofile("testsupport.lua") |
| 20 | 20 | ||
| 21 | local total = function() | 21 | local total = function() |
| 22 | local t = 0 | 22 | local t = 0 |
diff --git a/test/testsupport.lua b/test/testsupport.lua new file mode 100644 index 0000000..ca3cd95 --- /dev/null +++ b/test/testsupport.lua | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | function readfile(name) | ||
| 2 | local f = io.open(name, "r") | ||
| 3 | if not f then return nil end | ||
| 4 | local s = f:read("*a") | ||
| 5 | f:close() | ||
| 6 | return s | ||
| 7 | end | ||
| 8 | |||
| 9 | function similar(s1, s2) | ||
| 10 | return string.lower(string.gsub(s1 or "", "%s", "")) == | ||
| 11 | string.lower(string.gsub(s2 or "", "%s", "")) | ||
| 12 | end | ||
| 13 | |||
| 14 | function fail(msg) | ||
| 15 | msg = msg or "failed" | ||
| 16 | error(msg, 2) | ||
| 17 | end | ||
| 18 | |||
| 19 | function compare(input, output) | ||
| 20 | local original = readfile(input) | ||
| 21 | local recovered = readfile(output) | ||
| 22 | if original ~= recovered then fail("comparison failed") | ||
| 23 | else print("ok") end | ||
| 24 | end | ||
| 25 | |||
| 26 | local G = _G | ||
| 27 | local set = rawset | ||
| 28 | local warn = print | ||
| 29 | |||
| 30 | local setglobal = function(table, key, value) | ||
| 31 | warn("changed " .. key) | ||
| 32 | set(table, key, value) | ||
| 33 | end | ||
| 34 | |||
| 35 | setmetatable(G, { | ||
| 36 | __newindex = setglobal | ||
| 37 | }) | ||
diff --git a/test/urltest.lua b/test/urltest.lua index 990a3e5..7e0e73f 100644 --- a/test/urltest.lua +++ b/test/urltest.lua | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | dofile("noglobals.lua") | 1 | dofile("testsupport.lua") |
| 2 | 2 | ||
| 3 | local check_build_url = function(parsed) | 3 | local check_build_url = function(parsed) |
| 4 | local built = socket.url.build(parsed) | 4 | local built = socket.url.build(parsed) |
