aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/urltest.lua28
1 files changed, 15 insertions, 13 deletions
diff --git a/test/urltest.lua b/test/urltest.lua
index 8c50f50..3df4b01 100644
--- a/test/urltest.lua
+++ b/test/urltest.lua
@@ -2,13 +2,15 @@ local socket = require("socket")
2socket.url = require("socket.url") 2socket.url = require("socket.url")
3dofile("testsupport.lua") 3dofile("testsupport.lua")
4 4
5local function fail() os.exit(1) end
6
5local check_build_url = function(parsed) 7local check_build_url = function(parsed)
6 local built = socket.url.build(parsed) 8 local built = socket.url.build(parsed)
7 if built ~= parsed.url then 9 if built ~= parsed.url then
8 print("built is different from expected") 10 print("built is different from expected")
9 print(built) 11 print(built)
10 print(expected) 12 print(parsed.url)
11 os.exit() 13 fail()
12 end 14 end
13end 15end
14 16
@@ -17,7 +19,7 @@ local check_protect = function(parsed, path, unsafe)
17 if built ~= path then 19 if built ~= path then
18 print(built, path) 20 print(built, path)
19 print("path composition failed.") 21 print("path composition failed.")
20 os.exit() 22 fail()
21 end 23 end
22end 24end
23 25
@@ -28,7 +30,7 @@ local check_invert = function(url)
28 if rebuilt ~= url then 30 if rebuilt ~= url then
29 print(url, rebuilt) 31 print(url, rebuilt)
30 print("original and rebuilt are different") 32 print("original and rebuilt are different")
31 os.exit() 33 fail()
32 end 34 end
33end 35end
34 36
@@ -37,24 +39,24 @@ local check_parse_path = function(path, expect)
37 for i = 1, math.max(#parsed, #expect) do 39 for i = 1, math.max(#parsed, #expect) do
38 if parsed[i] ~= expect[i] then 40 if parsed[i] ~= expect[i] then
39 print(path) 41 print(path)
40 os.exit() 42 fail()
41 end 43 end
42 end 44 end
43 if expect.is_directory ~= parsed.is_directory then 45 if expect.is_directory ~= parsed.is_directory then
44 print(path) 46 print(path)
45 print("is_directory mismatch") 47 print("is_directory mismatch")
46 os.exit() 48 fail()
47 end 49 end
48 if expect.is_absolute ~= parsed.is_absolute then 50 if expect.is_absolute ~= parsed.is_absolute then
49 print(path) 51 print(path)
50 print("is_absolute mismatch") 52 print("is_absolute mismatch")
51 os.exit() 53 fail()
52 end 54 end
53 local built = socket.url.build_path(expect) 55 local built = socket.url.build_path(expect)
54 if built ~= path then 56 if built ~= path then
55 print(built, path) 57 print(built, path)
56 print("path composition failed.") 58 print("path composition failed.")
57 os.exit() 59 fail()
58 end 60 end
59end 61end
60 62
@@ -63,7 +65,7 @@ local check_absolute_url = function(base, relative, absolute)
63 if res ~= absolute then 65 if res ~= absolute then
64 io.write("absolute: In test for base='", base, "', rel='", relative, "' expected '", 66 io.write("absolute: In test for base='", base, "', rel='", relative, "' expected '",
65 absolute, "' but got '", res, "'\n") 67 absolute, "' but got '", res, "'\n")
66 os.exit() 68 fail()
67 end 69 end
68end 70end
69 71
@@ -76,7 +78,7 @@ local check_parse_url = function(gaba)
76 io.write("parse: In test for '", url, "' expected ", i, " = '", 78 io.write("parse: In test for '", url, "' expected ", i, " = '",
77 v, "' but got '", tostring(parsed[i]), "'\n") 79 v, "' but got '", tostring(parsed[i]), "'\n")
78 for i,v in pairs(parsed) do print(i,v) end 80 for i,v in pairs(parsed) do print(i,v) end
79 os.exit() 81 fail()
80 end 82 end
81 end 83 end
82 for i, v in pairs(parsed) do 84 for i, v in pairs(parsed) do
@@ -84,7 +86,7 @@ local check_parse_url = function(gaba)
84 io.write("parse: In test for '", url, "' expected ", i, " = '", 86 io.write("parse: In test for '", url, "' expected ", i, " = '",
85 tostring(gaba[i]), "' but got '", v, "'\n") 87 tostring(gaba[i]), "' but got '", v, "'\n")
86 for i,v in pairs(parsed) do print(i,v) end 88 for i,v in pairs(parsed) do print(i,v) end
87 os.exit() 89 fail()
88 end 90 end
89 end 91 end
90end 92end
@@ -626,7 +628,7 @@ local check_classify_host = function(raw, expect_hosttype, expect_host)
626 io.write("classify_host: for '", raw, "' expected ", expect_hosttype, 628 io.write("classify_host: for '", raw, "' expected ", expect_hosttype,
627 " '", expect_host, "' but got ", tostring(hosttype), " '", 629 " '", expect_host, "' but got ", tostring(hosttype), " '",
628 tostring(host), "'\n") 630 tostring(host), "'\n")
629 os.exit() 631 fail()
630 end 632 end
631end 633end
632 634
@@ -651,7 +653,7 @@ do
651 {scheme = "http", ipv4 = "1.2.3.4", hostname = "example.com", path = "/path"}) 653 {scheme = "http", ipv4 = "1.2.3.4", hostname = "example.com", path = "/path"})
652 if ok then 654 if ok then
653 print("build: expected error for ambiguous host, got none") 655 print("build: expected error for ambiguous host, got none")
654 os.exit() 656 fail()
655 end 657 end
656end 658end
657 659