Blame specs/posix_deprecated_spec.yaml

Packit 437b5e
specify posix.deprecated:
Packit 437b5e
- before:
Packit 437b5e
    socket, getaddrinfo, close = posix.socket, posix.getaddrinfo, posix.close
Packit 437b5e
    AF_INET, AF_INET6, AF_UNIX, AF_NETLINK =
Packit 437b5e
      posix.AF_INET, posix.AF_INET6, posix.AF_UNIX, posix.AF_NETLINK
Packit 437b5e
    SOCK_STREAM = posix.SOCK_STREAM
Packit 437b5e
Packit 437b5e
- describe connect:
Packit 437b5e
  - before:
Packit 437b5e
      connect, typeerrors = init (posix, "connect")
Packit 437b5e
Packit 437b5e
  - context with bad arguments: |
Packit 437b5e
      badargs.diagnose (connect, "connect (int, table)")
Packit 437b5e
Packit 437b5e
      examples {
Packit 437b5e
        ["it diagnoses wrong family types"] = function ()
Packit 437b5e
          expect (connect (42, {family=false})).
Packit 437b5e
            to_raise.any_of (typeerrors (2, "int", "family", "boolean"))
Packit 437b5e
          expect (connect (42, {family=-1})).to_raise.any_of {
Packit 437b5e
            "bad argument #2 to '?' (unsupported family type -1)",
Packit 437b5e
            "bad argument #2 to 'connect' (unsupported family type -1)",
Packit 437b5e
          }
Packit 437b5e
        end
Packit 437b5e
      }
Packit 437b5e
      examples {
Packit 437b5e
        ["it diagnoses wrong AF_INET field types"] = function ()
Packit 437b5e
          expect (connect (42, {family=AF_INET, port=false})).
Packit 437b5e
            to_raise.any_of (typeerrors (2, "int", "port", "boolean"))
Packit 437b5e
          expect (connect (42, {family=AF_INET, port=9999, addr=false})).
Packit 437b5e
            to_raise.any_of (typeerrors (2, "string", "addr", "boolean"))
Packit 437b5e
        end
Packit 437b5e
      }
Packit 437b5e
      examples {
Packit 437b5e
        ["it diagnoses invalid AF_INET fields"] = function ()
Packit 437b5e
          expect (connect (42, {
Packit 437b5e
            family=AF_INET, port=9999, addr="127.0.0.1", flags=false
Packit 437b5e
          })).to_raise.any_of (typeerrors (2, nil, "flags"))
Packit 437b5e
        end
Packit 437b5e
      }
Packit 437b5e
      examples {
Packit 437b5e
        ["it diagnoses wrong AF_INET6 field types"] = function ()
Packit 437b5e
          expect (connect (42, {family = AF_INET6, port = false})).
Packit 437b5e
            to_raise.any_of (typeerrors (2, "int", "port", "boolean"))
Packit 437b5e
          expect (connect (42, {family = AF_INET6, port = 9999, addr = false})).
Packit 437b5e
            to_raise.any_of (typeerrors (2, "string", "addr", "boolean"))
Packit 437b5e
        end
Packit 437b5e
      }
Packit 437b5e
      examples {
Packit 437b5e
        ["it diagnoses invalid AF_INET6 fields"] = function ()
Packit 437b5e
          expect (connect (42, {
Packit 437b5e
            family=AF_INET6, port=9999, addr="::", flags=false
Packit 437b5e
          })).to_raise.any_of (typeerrors (2, nil, "flags"))
Packit 437b5e
        end
Packit 437b5e
      }
Packit 437b5e
      examples {
Packit 437b5e
        ["it diagnoses wrong AF_UNIX field types"] = function ()
Packit 437b5e
          expect (connect (42, {family = AF_UNIX, path = false})).
Packit 437b5e
            to_raise.any_of (typeerrors (2, "string", "path", "boolean"))
Packit 437b5e
        end
Packit 437b5e
      }
Packit 437b5e
      examples {
Packit 437b5e
        ["it diagnoses invalid AF_UNIX fields"] = function ()
Packit 437b5e
          expect (connect (42, {family=AF_UNIX, path="/tmp/afunix", port=9999})).
Packit 437b5e
            to_raise.any_of (typeerrors (2, nil, "port"))
Packit 437b5e
        end
Packit 437b5e
      }
Packit 437b5e
      if AF_NETLINK then
Packit 437b5e
        examples {
Packit 437b5e
          ["it diagnoses wrong AF_NETLINK field types"] = function ()
Packit 437b5e
              expect (connect (42, {family = AF_NETLINK, pid = false})).
Packit 437b5e
                to_raise.any_of (typeerrors (2, "int", "pid", "boolean"))
Packit 437b5e
              expect (connect (42, {family = AF_NETLINK, pid = 9999, groups = false})).
Packit 437b5e
                to_raise.any_of (typeerrors (2, "int", "groups", "boolean"))
Packit 437b5e
          end
Packit 437b5e
        }
Packit 437b5e
        examples {
Packit 437b5e
          ["it diagnoses invalid AF_NETLINK fields"] = function ()
Packit 437b5e
            expect (connect (42, {family=AF_NETLINK, pid=9999, groups=9999, port=9999})).
Packit 437b5e
              to_raise.any_of (typeerrors (2, nil, "port"))
Packit 437b5e
          end
Packit 437b5e
        }
Packit 437b5e
      end
Packit 437b5e
Packit 437b5e
  - it returns true on success:
Packit 437b5e
      fd = socket (AF_INET, SOCK_STREAM, 0)
Packit 437b5e
      ait = getaddrinfo ("www.lua.org", "http", {family = AF_INET, socktype = SOCK_STREAM})
Packit 437b5e
      expect (connect (fd, ait[1])).to_be (true)
Packit 437b5e
      close (fd)
Packit 437b5e
Packit 437b5e
Packit 437b5e
Packit 437b5e
- describe bind:
Packit 437b5e
  - before:
Packit 437b5e
      bind, typeerrors = init (posix, "bind")
Packit 437b5e
Packit 437b5e
  - context with bad arguments: |
Packit 437b5e
      badargs.diagnose (bind, "bind (int, table)")
Packit 437b5e
Packit 437b5e
      examples {
Packit 437b5e
        ["it diagnoses wrong family types"] = function ()
Packit 437b5e
          expect (bind (42, {family=false})).
Packit 437b5e
            to_raise.any_of (typeerrors (2, "int", "family", "boolean"))
Packit 437b5e
          expect (bind (42, {family=-1})).to_raise.any_of {
Packit 437b5e
            "bad argument #2 to '?' (unsupported family type -1)",
Packit 437b5e
            "bad argument #2 to 'bind' (unsupported family type -1)",
Packit 437b5e
          }
Packit 437b5e
        end
Packit 437b5e
      }
Packit 437b5e
      examples {
Packit 437b5e
        ["it diagnoses wrong AF_INET field types"] = function ()
Packit 437b5e
          expect (bind (42, {family=AF_INET, port=false})).
Packit 437b5e
            to_raise.any_of (typeerrors (2, "int", "port", "boolean"))
Packit 437b5e
          expect (bind (42, {family=AF_INET, port=9999, addr=false})).
Packit 437b5e
            to_raise.any_of (typeerrors (2, "string", "addr", "boolean"))
Packit 437b5e
        end
Packit 437b5e
      }
Packit 437b5e
      examples {
Packit 437b5e
        ["it diagnoses invalid AF_INET fields"] = function ()
Packit 437b5e
          expect (bind (42, {
Packit 437b5e
            family=AF_INET, port=9999, addr="127.0.0.1", flags=false
Packit 437b5e
          })).to_raise.any_of (typeerrors (2, nil, "flags"))
Packit 437b5e
        end
Packit 437b5e
      }
Packit 437b5e
      examples {
Packit 437b5e
        ["it diagnoses wrong AF_INET6 field types"] = function ()
Packit 437b5e
          expect (bind (42, {family = AF_INET6, port = false})).
Packit 437b5e
            to_raise.any_of (typeerrors (2, "int", "port", "boolean"))
Packit 437b5e
          expect (bind (42, {family = AF_INET6, port = 9999, addr = false})).
Packit 437b5e
            to_raise.any_of (typeerrors (2, "string", "addr", "boolean"))
Packit 437b5e
        end
Packit 437b5e
      }
Packit 437b5e
      examples {
Packit 437b5e
        ["it diagnoses invalid AF_INET6 fields"] = function ()
Packit 437b5e
          expect (bind (42, {
Packit 437b5e
            family=AF_INET6, port=9999, addr="::", flags=false
Packit 437b5e
          })).to_raise.any_of (typeerrors (2, nil, "flags"))
Packit 437b5e
        end
Packit 437b5e
      }
Packit 437b5e
      examples {
Packit 437b5e
        ["it diagnoses wrong AF_UNIX field types"] = function ()
Packit 437b5e
          expect (bind (42, {family = AF_UNIX, path = false})).
Packit 437b5e
            to_raise.any_of (typeerrors (2, "string", "path", "boolean"))
Packit 437b5e
        end
Packit 437b5e
      }
Packit 437b5e
      examples {
Packit 437b5e
        ["it diagnoses invalid AF_UNIX fields"] = function ()
Packit 437b5e
          expect (bind (42, {family=AF_UNIX, path="/tmp/afunix", port=9999})).
Packit 437b5e
            to_raise.any_of (typeerrors (2, nil, "port"))
Packit 437b5e
        end
Packit 437b5e
      }
Packit 437b5e
      if AF_NETLINK then
Packit 437b5e
        examples {
Packit 437b5e
          ["it diagnoses wrong AF_NETLINK field types"] = function ()
Packit 437b5e
              expect (bind (42, {family = AF_NETLINK, pid = false})).
Packit 437b5e
                to_raise.any_of (typeerrors (2, "int", "pid", "boolean"))
Packit 437b5e
              expect (bind (42, {family = AF_NETLINK, pid = 9999, groups = false})).
Packit 437b5e
                to_raise.any_of (typeerrors (2, "int", "groups", "boolean"))
Packit 437b5e
          end
Packit 437b5e
        }
Packit 437b5e
        examples {
Packit 437b5e
          ["it diagnoses invalid AF_NETLINK fields"] = function ()
Packit 437b5e
            expect (bind (42, {family=AF_NETLINK, pid=9999, groups=9999, port=9999})).
Packit 437b5e
              to_raise.any_of (typeerrors (2, nil, "port"))
Packit 437b5e
          end
Packit 437b5e
        }
Packit 437b5e
      end
Packit 437b5e
Packit 437b5e
  - it returns true on success:
Packit 437b5e
      fd = socket (AF_INET, SOCK_STREAM, 0)
Packit 437b5e
      expect (bind (fd, {family = AF_INET, addr = "127.0.0.1", port = 13457 })).to_be (true)
Packit 437b5e
      close (fd)
Packit 437b5e
Packit 437b5e
Packit 437b5e
- describe exec:
Packit 437b5e
  - before:
Packit 437b5e
      exec, typeerrors = init (posix, "exec")
Packit 437b5e
Packit 437b5e
  # posix.exec takes a string or non-empty table as its second
Packit 437b5e
  # argument, followed by zero or more strings only if the second
Packit 437b5e
  # argument was a string; since we can't express that with
Packit 437b5e
  # `badargs.diagnose` do it all manually again...
Packit 437b5e
  - context with bad arguments:
Packit 437b5e
    - 'it diagnoses argument #1 type not string':
Packit 437b5e
        expect (exec (false)).to_raise.any_of (typeerrors (1, "string", "boolean"))
Packit 437b5e
    - 'it diagnoses argument #2 type not table or string':
Packit 437b5e
        expect (exec ("cmd", false)).
Packit 437b5e
          to_raise.any_of (typeerrors (2, "?string|table", "boolean"))
Packit 437b5e
    - 'it diagnoses argument #3 type not string':
Packit 437b5e
        expect (exec ("cmd", "cmd", false)).
Packit 437b5e
          to_raise.any_of (typeerrors (3, "string", "boolean"))
Packit 437b5e
    - it diagnoses too many arguments:
Packit 437b5e
        expect (exec ("cmd", {}, false)).to_raise.any_of (typeerrors (3))
Packit 437b5e
Packit 437b5e
Packit 437b5e
- describe execp:
Packit 437b5e
  - before:
Packit 437b5e
      # redirect output to /dev/null
Packit 437b5e
      dup2, fork, open, wait, O_WRONLY, O_APPEND =
Packit 437b5e
        posix.dup2, posix.fork, posix.open, posix.wait, posix.O_WRONLY, posix.O_APPEND
Packit 437b5e
      P_CHILD = 0
Packit 437b5e
Packit 437b5e
      function child (...)
Packit 437b5e
        quietly = open ("/dev/null", bor (O_WRONLY, O_APPEND))
Packit 437b5e
        dup2 (quietly, 1)
Packit 437b5e
        execp (...)
Packit 437b5e
        expect ("not reached").to_be (true)
Packit 437b5e
      end
Packit 437b5e
Packit 437b5e
      execp, typeerrors = init (posix, "execp")
Packit 437b5e
Packit 437b5e
  # posix.execp takes a string or non-empty table as its second
Packit 437b5e
  # argument, followed by zero or more strings only if the second
Packit 437b5e
  # argument was a string; since we can't express that with
Packit 437b5e
  # `badargs.diagnose` do it all manually again...
Packit 437b5e
  - context with bad arguments:
Packit 437b5e
    - 'it diagnoses argument #1 type not string':
Packit 437b5e
        expect (execp (false)).to_raise.any_of (typeerrors (1, "string", "boolean"))
Packit 437b5e
    - 'it diagnoses argument #2 type not table or string':
Packit 437b5e
        expect (execp ("cmd", false)).
Packit 437b5e
          to_raise.any_of (typeerrors (2, "?string|table", "boolean"))
Packit 437b5e
    - 'it diagnoses argument #3 type not string':
Packit 437b5e
        expect (execp ("cmd", "cmd", false)).
Packit 437b5e
          to_raise.any_of (typeerrors (3, "string", "boolean"))
Packit 437b5e
    - it diagnoses too many arguments:
Packit 437b5e
        expect (execp ("cmd", {}, false)).to_raise.any_of (typeerrors (3))
Packit 437b5e
Packit 437b5e
  - it overwrites the running process with a shell invocation:
Packit 437b5e
      process = fork ()
Packit 437b5e
      if process == P_CHILD then
Packit 437b5e
        child ("date", "+[%c]")
Packit 437b5e
      else
Packit 437b5e
        p, msg, ret = wait (process)
Packit 437b5e
        expect (table.concat {msg, " ", tostring (ret)}).to_be "exited 0"
Packit 437b5e
      end
Packit 437b5e
  - it accepts a table of arguments:
Packit 437b5e
      process = fork ()
Packit 437b5e
      if process == P_CHILD then
Packit 437b5e
        child ("date", {"+[%c]"})
Packit 437b5e
      else
Packit 437b5e
        p, msg, ret = wait (process)
Packit 437b5e
        expect (table.concat {msg, " ", tostring (ret)}).to_be "exited 0"
Packit 437b5e
      end
Packit 437b5e
  - "it sets argv[0]":
Packit 437b5e
Packit 437b5e
Packit 437b5e
- describe openlog:
Packit 437b5e
  - before:
Packit 437b5e
      openlog = posix.openlog
Packit 437b5e
Packit 437b5e
  - context with bad arguments: |
Packit 437b5e
      if openlog then
Packit 437b5e
        badargs.diagnose (openlog, "openlog (string, ?string, ?int)")
Packit 437b5e
Packit 437b5e
        examples {
Packit 437b5e
          ["it diagnoses invalid options"] = function ()
Packit 437b5e
            expect (openlog ("log", "cp*")).to_raise.any_of {
Packit 437b5e
              "bad argument #2 to '?' (invalid openlog option '*')",
Packit 437b5e
              "bad argument #2 to 'openlog' (invalid openlog option '*')",
Packit 437b5e
            }
Packit 437b5e
          end
Packit 437b5e
        }
Packit 437b5e
      end