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 73 74 75 76 77 78 79 80 81 82 83 84 85
|
before:
this_module = 'posix.sys.resource'
global_table = '_G'
M = require(this_module)
specify posix.sys.resource:
- context when required:
- it does not touch the global table:
expect(show_apis {added_to=global_table, by=this_module}).
to_equal {}
- describe getrlimit:
- before:
getrlimit = M.getrlimit
- context with bad arguments:
badargs.diagnose(getrlimit, "(int)")
- it returns a PosixRlimit:
expect(prototype(getrlimit(M.RLIMIT_AS))).to_be "PosixRlimit"
- it fetches resource limits for a process:
for _, rc in pairs {"RLIMIT_CORE", "RLIMIT_CPU", "RLIMIT_DATA", "RLIMIT_FSIZE",
"RLIMIT_NOFILE", "RLIMIT_STACK", "RLIMIT_AS"}
do
rlim = getrlimit(M[rc])
expect(type(rlim.rlim_cur)).to_be "number"
expect(type(rlim.rlim_max)).to_be "number"
end
- describe setrlimit:
- before:
setrlimit, typeerrors = init(M, "setrlimit")
getrlimit = M.getrlimit
- context with bad arguments: |
badargs.diagnose(setrlimit, "(int, table)")
examples {
["context diagnosing rlimit table fields"] = {
{
["it diagnoses argument #2 missing rlim_cur field"] = function()
expect(setrlimit(-1, {})).to_raise.
any_of(typeerrors(2, "integer", "rlim_cur", "no value"))
end
},
{
["it diagnoses argument #2 rlim_cur field type not int"] = function()
expect(setrlimit(-1, {rlim_cur = false})).to_raise.
any_of(typeerrors(2, "integer", "rlim_cur", "boolean"))
end
},
{
["it diagnoses argument #2 missing rlim_max field"] = function()
expect(setrlimit(-1, {rlim_cur = -1})).to_raise.
any_of(typeerrors(2, "integer", "rlim_max", "no value"))
end
},
{
["it diagnoses argument #2 rlim_max field type not int"] = function()
expect(setrlimit(-1, {rlim_cur = -1, rlim_max = false})).to_raise.
any_of(typeerrors(2, "integer", "rlim_max", "boolean"))
end
},
{
["it diagnoses argument #2 spurious fields"] = function()
expect(setrlimit(-1, {rlim_cur = -1, rlim_max = -1, bogus = false})).
to_raise.any_of(typeerrors(2, nil, "bogus"))
end
},
}
}
- it accepts PosixRlimit argument: |
for _, rc in pairs {"RLIMIT_CORE", "RLIMIT_CPU", "RLIMIT_DATA", "RLIMIT_FSIZE",
"RLIMIT_NOFILE", "RLIMIT_STACK", "RLIMIT_AS"}
do
rlim = getrlimit(M[rc])
expect({setrlimit(M[rc], rlim)}).to_equal.any_of {
{0},
{nil, "setrlimit: Operation not permitted", 1},
}
end
|