Blame specs/posix_sys_socket_spec.yaml

Packit 437b5e
specify posix.sys.socket:
Packit 437b5e
- before:
Packit 437b5e
    sock = require "posix.sys.socket"
Packit 437b5e
Packit 437b5e
    bind, setsockopt, socket = sock.bind, sock.setsockopt, sock.socket
Packit 437b5e
    recvfrom, sendto = sock.recvfrom, sock.sendto
Packit 437b5e
    AF_INET, AF_INET6, AF_UNIX, AF_NETLINK =
Packit 437b5e
      sock.AF_INET, sock.AF_INET6, sock.AF_UNIX, sock.AF_NETLINK
Packit 437b5e
    IPPROTO_TCP, SOCK_DGRAM = sock.IPPROTO_TCP, sock.SOCK_DGRAM
Packit 437b5e
    SOL_SOCKET, SO_RCVTIMEO = sock.SOL_SOCKET, sock.SO_RCVTIMEO
Packit 437b5e
Packit 437b5e
Packit 437b5e
- describe socket:
Packit 437b5e
  - context with bad arguments:
Packit 437b5e
      badargs.diagnose (sock.socket, "(int, int, int)")
Packit 437b5e
Packit 437b5e
Packit 437b5e
- describe socketpair:
Packit 437b5e
  - context with bad arguments:
Packit 437b5e
      badargs.diagnose (sock.socketpair, "(int, int, int)")
Packit 437b5e
Packit 437b5e
Packit 437b5e
- describe getaddrinfo:
Packit 437b5e
  - before:
Packit 437b5e
      getaddrinfo, typeerrors = init (sock, "getaddrinfo")
Packit 437b5e
Packit 437b5e
  - context with bad arguments: |
Packit 437b5e
      badargs.diagnose (getaddrinfo, "(?string, ?string|int, ?table)")
Packit 437b5e
Packit 437b5e
      examples {
Packit 437b5e
        ["it diagnoses unspecified host and service"] = function ()
Packit 437b5e
          expect (getaddrinfo ()).to_raise.
Packit 437b5e
            any_of (typeerrors (2, "string or int"))
Packit 437b5e
        end
Packit 437b5e
      }
Packit 437b5e
      examples {
Packit 437b5e
        ["it diagnoses invalid hints fields"] = function ()
Packit 437b5e
          expect (getaddrinfo ("localhost", nil, {
Packit 437b5e
            protacol=IPPROTO_TCP
Packit 437b5e
          })).to_raise.any_of (typeerrors (3, nil, "protacol"))
Packit 437b5e
          expect (getaddrinfo ("localhost", nil, {
Packit 437b5e
            family=AF_INET, sacktype=SOCK_DGRAM, protocol=IPPROTO_TCP,
Packit 437b5e
          })).to_raise.any_of (typeerrors (3, nil, "sacktype"))
Packit 437b5e
        end
Packit 437b5e
      }
Packit 437b5e
      examples {
Packit 437b5e
        ["it diagnoses wrong hints field types"] = function ()
Packit 437b5e
          expect (getaddrinfo ("localhost", nil, {
Packit 437b5e
            family=false,
Packit 437b5e
          })).to_raise.any_of (typeerrors (3, "int", "family", "boolean"))
Packit 437b5e
          expect (getaddrinfo ("localhost", nil, {
Packit 437b5e
            family=AF_INET, socktype=false,
Packit 437b5e
          })).to_raise.any_of (typeerrors (3, "int", "socktype", "boolean"))
Packit 437b5e
          expect (getaddrinfo ("localhost", nil, {
Packit 437b5e
            family=AF_INET, socktype=SOCK_DGRAM, protocol=false,
Packit 437b5e
          })).to_raise.any_of (typeerrors (3, "int", "protocol", "boolean"))
Packit 437b5e
          expect (getaddrinfo ("localhost", nil, {
Packit 437b5e
            family=AF_INET, socktype=SOCK_DGRAM, protocol=IPPROTO_TCP, flags=false,
Packit 437b5e
          })).to_raise.any_of (typeerrors (3, "int", "flags", "boolean"))
Packit 437b5e
        end
Packit 437b5e
      }
Packit 437b5e
Packit 437b5e
Packit 437b5e
- describe connect:
Packit 437b5e
  - before:
Packit 437b5e
      connect, typeerrors = init (sock, "connect")
Packit 437b5e
Packit 437b5e
  - context with bad arguments: |
Packit 437b5e
      badargs.diagnose (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 'connect' (unsupported family type -1)",
Packit 437b5e
            "bad argument #2 to '?' (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
Packit 437b5e
- describe bind:
Packit 437b5e
  - before:
Packit 437b5e
      bind, typeerrors = init (sock, "bind")
Packit 437b5e
Packit 437b5e
  - context with bad arguments: |
Packit 437b5e
      badargs.diagnose (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
Packit 437b5e
- describe listen:
Packit 437b5e
  - context with bad arguments:
Packit 437b5e
      badargs.diagnose (sock.listen, "(int, int)")
Packit 437b5e
Packit 437b5e
Packit 437b5e
- describe accept:
Packit 437b5e
  - context with bad arguments:
Packit 437b5e
      badargs.diagnose (sock.accept, "(int)")
Packit 437b5e
Packit 437b5e
Packit 437b5e
- describe recv:
Packit 437b5e
  - context with bad arguments:
Packit 437b5e
      badargs.diagnose (sock.recv, "(int, int)")
Packit 437b5e
Packit 437b5e
Packit 437b5e
- describe recvfrom:
Packit 437b5e
  - context with bad arguments:
Packit 437b5e
      badargs.diagnose (sock.recvfrom, "(int, int)")
Packit 437b5e
Packit 437b5e
Packit 437b5e
- describe send:
Packit 437b5e
  - context with bad arguments:
Packit 437b5e
      badargs.diagnose (sock.send, "(int, string)")
Packit 437b5e
Packit 437b5e
Packit 437b5e
- describe sendto:
Packit 437b5e
  - before:
Packit 437b5e
      sendto, typeerrors = init (sock, "sendto")
Packit 437b5e
Packit 437b5e
  - context with bad arguments: |
Packit 437b5e
      badargs.diagnose (sendto, "(int, string, table)")
Packit 437b5e
Packit 437b5e
      examples {
Packit 437b5e
        ["it diagnoses wrong family types"] = function ()
Packit 437b5e
          expect (sendto (42, "msg", {family=false})).
Packit 437b5e
            to_raise.any_of (typeerrors (3, "int", "family", "boolean"))
Packit 437b5e
          expect (sendto (42, "msg", {family=-1})).to_raise.any_of {
Packit 437b5e
            "bad argument #3 to '?' (unsupported family type -1)",
Packit 437b5e
            "bad argument #3 to 'sendto' (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 (sendto (42, "msg", {family=AF_INET, port=false})).
Packit 437b5e
            to_raise.any_of (typeerrors (3, "int", "port", "boolean"))
Packit 437b5e
          expect (sendto (42, "msg", {family=AF_INET, port=9999, addr=false})).
Packit 437b5e
            to_raise.any_of (typeerrors (3, "string", "addr", "boolean"))
Packit 437b5e
        end
Packit 437b5e
      }
Packit 437b5e
      examples {
Packit 437b5e
        ["it diagnoses invalid AF_INET fields"] = function ()
Packit 437b5e
          expect (sendto (42, "msg", {
Packit 437b5e
            family=AF_INET, port=9999, addr="127.0.0.1", flags=false
Packit 437b5e
          })).to_raise.any_of (typeerrors (3, nil, "flags"))
Packit 437b5e
        end
Packit 437b5e
      }
Packit 437b5e
      examples {
Packit 437b5e
        ["it diagnoses wrong AF_INET6 field types"] = function ()
Packit 437b5e
          expect (sendto (42, "msg", {family = AF_INET6, port = false})).
Packit 437b5e
            to_raise.any_of (typeerrors (3, "int", "port", "boolean"))
Packit 437b5e
          expect (sendto (42, "msg", {family = AF_INET6, port = 9999, addr = false})).
Packit 437b5e
            to_raise.any_of (typeerrors (3, "string", "addr", "boolean"))
Packit 437b5e
        end
Packit 437b5e
      }
Packit 437b5e
      examples {
Packit 437b5e
        ["it diagnoses invalid AF_INET6 fields"] = function ()
Packit 437b5e
          expect (sendto (42, "msg", {
Packit 437b5e
            family=AF_INET6, port=9999, addr="::", flags=false
Packit 437b5e
          })).to_raise.any_of (typeerrors (3, nil, "flags"))
Packit 437b5e
        end
Packit 437b5e
      }
Packit 437b5e
      examples {
Packit 437b5e
        ["it diagnoses wrong AF_UNIX field types"] = function ()
Packit 437b5e
          expect (sendto (42, "msg", {family = AF_UNIX, path = false})).
Packit 437b5e
            to_raise.any_of (typeerrors (3, "string", "path", "boolean"))
Packit 437b5e
        end
Packit 437b5e
      }
Packit 437b5e
      examples {
Packit 437b5e
        ["it diagnoses invalid AF_UNIX fields"] = function ()
Packit 437b5e
          expect (sendto (42, "msg", {family=AF_UNIX, path="/tmp/afunix", port=9999})).
Packit 437b5e
            to_raise.any_of (typeerrors (3, 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 (sendto (42, "msg", {family = AF_NETLINK, pid = false})).
Packit 437b5e
                to_raise.any_of (typeerrors (3, "int", "pid", "boolean"))
Packit 437b5e
              expect (sendto (42, "msg", {family = AF_NETLINK, pid = 9999, groups = false})).
Packit 437b5e
                to_raise.any_of (typeerrors (3, "int", "groups", "boolean"))
Packit 437b5e
          end
Packit 437b5e
        }
Packit 437b5e
        examples {
Packit 437b5e
          ["it diagnoses invalid AF_NETLINK fields"] = function ()
Packit 437b5e
            expect (sendto (42, "msg", {family=AF_NETLINK, pid=9999, groups=9999, port=9999})).
Packit 437b5e
              to_raise.any_of (typeerrors (3, nil, "port"))
Packit 437b5e
          end
Packit 437b5e
        }
Packit 437b5e
      end
Packit 437b5e
Packit 437b5e
Packit 437b5e
- describe shutdown:
Packit 437b5e
  - context with bad arguments:
Packit 437b5e
      badargs.diagnose (sock.shutdown, "(int, int)")
Packit 437b5e
Packit 437b5e
Packit 437b5e
- describe getsockname:
Packit 437b5e
  - context with bad arguments:
Packit 437b5e
      badargs.diagnose (sock.getsockname, "(int)")
Packit 437b5e
Packit 437b5e
Packit 437b5e
- describe setsockopt:
Packit 437b5e
  - before:
Packit 437b5e
      SOL_SOCKET, SO_LINGER, IPPROTO_TCP =
Packit 437b5e
        sock.SOL_SOCKET, sock.SO_LINGER, sock.IPPROTO_TCP
Packit 437b5e
Packit 437b5e
      setsockopt, typeerrors = init (sock, "setsockopt")
Packit 437b5e
Packit 437b5e
  - context with bad arguments:
Packit 437b5e
    - 'it diagnoses missing argument #1':
Packit 437b5e
        expect (setsockopt ()).to_raise.any_of (typeerrors (1, "int"))
Packit 437b5e
    - 'it diagnoses argument #1 type not int':
Packit 437b5e
        expect (setsockopt (false)).to_raise.any_of (typeerrors (1, "int", "boolean"))
Packit 437b5e
    - 'it diagnoses missing argument #2':
Packit 437b5e
        expect (setsockopt (1)).to_raise.any_of (typeerrors (2, "int"))
Packit 437b5e
    - 'it diagnoses argument #2 type not int':
Packit 437b5e
        expect (setsockopt (1, false)).to_raise.any_of (typeerrors (2, "int", "boolean"))
Packit 437b5e
    - 'it diagnoses missing argument #3':
Packit 437b5e
        expect (setsockopt (1, 2)).to_raise.any_of (typeerrors (3, "int"))
Packit 437b5e
    - 'it diagnoses argument #3 type not int':
Packit 437b5e
        expect (setsockopt (1, 2, false)).to_raise.any_of (typeerrors (3, "int", "boolean"))
Packit 437b5e
    - 'it diagnoses missing argument #4':
Packit 437b5e
        expect (setsockopt (1, SOL_SOCKET, SO_LINGER)).
Packit 437b5e
          to_raise.any_of (typeerrors (4, "int"))
Packit 437b5e
    - 'it diagnoses argument #4 type not int':
Packit 437b5e
        expect (setsockopt (1, SOL_SOCKET, SO_LINGER, false)).
Packit 437b5e
          to_raise.any_of (typeerrors (4, "int", "boolean"))
Packit 437b5e
    - 'it diagnoses missing argument #5':
Packit 437b5e
        expect (setsockopt (1, SOL_SOCKET, SO_LINGER, 4)).
Packit 437b5e
          to_raise.any_of (typeerrors (5, "int"))
Packit 437b5e
    - 'it diagnoses argument #5 type not int':
Packit 437b5e
        expect (setsockopt (1, SOL_SOCKET, SO_LINGER, 4, false)).
Packit 437b5e
          to_raise.any_of (typeerrors (5, "int", "boolean"))
Packit 437b5e
    - it diagnoses too many arguments:
Packit 437b5e
        expect (setsockopt (1, SOL_SOCKET, IPPROTO_TCP, 4, false)).
Packit 437b5e
          to_raise.any_of (typeerrors (5))
Packit 437b5e
        expect (setsockopt (1, SOL_SOCKET, SO_LINGER, 4, 5, false)).
Packit 437b5e
          to_raise.any_of (typeerrors (6))
Packit 437b5e
Packit 437b5e
  - it communicates with IPV4 and IPV6 over loopback: |
Packit 437b5e
      fd = socket (AF_INET6, SOCK_DGRAM, 0)
Packit 437b5e
      expect (type (fd)).to_be "number"
Packit 437b5e
      expect (fd >= 0).to_be (true)
Packit 437b5e
Packit 437b5e
      expect (setsockopt (fd, SOL_SOCKET, SO_RCVTIMEO, 1, 0)).to_be (0)
Packit 437b5e
Packit 437b5e
      expect (bind (fd, { family = AF_INET6, addr = "::", port = 9999 })).
Packit 437b5e
        to_be (0)
Packit 437b5e
Packit 437b5e
      pending "issue #92"
Packit 437b5e
      sockt = { family = AF_INET, addr = "127.0.0.1", port = 59999 }
Packit 437b5e
      expect (sendto (fd, "Test ipv4", sockt)).to_be (9)
Packit 437b5e
Packit 437b5e
      data, so = recvfrom (fd, 1024)
Packit 437b5e
      expect (data).to_be "Test ipv4"