Software /
code /
prosody
File
spec/util_argparse_spec.lua @ 11853:ae5ac9830add
mod_http_file_share: return 401 instead of 403 if authentication failed
This is as per the HTTP standards [1]. Thankfully, the REQUIRED
www-authenticate header is already generated by the code.
[1]: https://datatracker.ietf.org/doc/html/rfc7235#section-3.1
author | Jonas Schäfer <jonas@wielicki.name> |
---|---|
date | Tue, 19 Oct 2021 16:37:32 +0200 |
parent | 11845:97c1399720c2 |
child | 12477:cc84682b8429 |
line wrap: on
line source
describe("parse", function() local parse setup(function() parse = require"util.argparse".parse; end); it("works", function() -- basic smoke test local opts = parse({ "--help" }); assert.same({ help = true }, opts); end); it("returns if no args", function() assert.same({}, parse({})); end); it("supports boolean flags", function() local opts, err = parse({ "--foo"; "--no-bar" }); assert.falsy(err); assert.same({ foo = true; bar = false }, opts); end); it("consumes input until the first argument", function() local arg = { "--foo"; "bar"; "--baz" }; local opts, err = parse(arg); assert.falsy(err); assert.same({ foo = true }, opts); assert.same({ "bar"; "--baz" }, arg); end); it("expands short options", function() local opts, err = parse({ "--foo"; "-b" }, { short_params = { b = "bar" } }); assert.falsy(err); assert.same({ foo = true; bar = true }, opts); end); it("supports value arguments", function() local opts, err = parse({ "--foo"; "bar"; "--baz=moo" }, { value_params = { foo = true; bar = true } }); assert.falsy(err); assert.same({ foo = "bar"; baz = "moo" }, opts); end); it("demands values for value params", function() local opts, err, where = parse({ "--foo" }, { value_params = { foo = true } }); assert.falsy(opts); assert.equal("missing-value", err); assert.equal("--foo", where); end); it("reports where the problem is", function() local opts, err, where = parse({ "-h" }); assert.falsy(opts); assert.equal("param-not-found", err); assert.equal("-h", where, "returned where"); end); end);