forked from NetHack/NetHack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cnf.lua
More file actions
72 lines (61 loc) · 2.18 KB
/
Copy pathtest_cnf.lua
File metadata and controls
72 lines (61 loc) · 2.18 KB
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
local configtests = {
{ test = "OPTIONS=color", -- config string to parse
result = { }, -- errors, result of parsing the config string
extra = function() return nh.get_config("color") == "true" end -- optional, function that returns boolean, and false means the test failed.
},
{ test = "OPTIONS=!color",
result = { },
extra = function() return nh.get_config("color") == "false" end
},
{ test = "OPTIONS=!color\nOPTIONS=color",
result = { { line = 2, error = "boolean option specified multiple times: color" } }
},
{ test = "OPTIONS=!color,color",
result = { { line = 1, error = "boolean option specified multiple times: color" } }
},
{ test = "OPTIONS=runmode:crawl",
result = { },
extra = function() return nh.get_config("runmode") == "crawl" end
},
{ test = "OPTIONS=runmode:foo",
result = { { line = 1, error = "Unknown runmode parameter 'foo'" } },
},
{ test = "OPTIONS=runmode",
result = { { line = 1, error = "Value is mandatory for runmode" } },
},
{ test = "OPTIONS=!runmode",
result = { },
extra = function() return nh.get_config("runmode") == "teleport" end
},
{ test = "OPTIONS=runmode:crawl\nOPTIONS=runmode:teleport",
result = { { line = 2, error = "compound option specified multiple times: runmode" } }
},
{ test = "OPTIONS=runmode:run,runmode:walk",
result = { { line = 1, error = "compound option specified multiple times: runmode" } }
},
};
function testtable(t1, t2)
if type(t1) ~= type(t2) then return false end
for k1, v1 in pairs(t1) do
if type(v1) == "table" and type(t2[k1]) == "table" then
if not testtable(v1, t2[k1]) then return false end
else
if v1 ~= t2[k1] then return false end
end
end
return true
end
for k, v in pairs(configtests) do
local cnf = configtests[k].test;
local err = configtests[k].result;
nh.parse_config(cnf);
local res = nh.get_config_errors();
if not testtable(err, res) then
error("Config: Results don't match for test \"" .. cnf .. "\"");
end
if (type(configtests[k].extra) == "function") then
if configtests[k].extra() == "false" then
error("Config: Failed extra test.");
end
end
end