Blame specs/posix_unistd_spec.yaml

Packit 437b5e
specify posix.unistd:
Packit 437b5e
- before: |
Packit 437b5e
    pwd    = require "posix.pwd"
Packit 437b5e
    unistd = require "posix.unistd"
Packit 437b5e
Packit 437b5e
    -- Assume $USER is the process owner, egid is gid and euid is uid
Packit 437b5e
    ids = pwd.getpwnam (os.getenv "USER")
Packit 437b5e
Packit 437b5e
Packit 437b5e
- describe exec:
Packit 437b5e
  - before:
Packit 437b5e
      exec = unistd.exec
Packit 437b5e
Packit 437b5e
  - context with bad arguments:
Packit 437b5e
      badargs.diagnose (exec, "(string, table)")
Packit 437b5e
Packit 437b5e
Packit 437b5e
- describe execp:
Packit 437b5e
  - before: |
Packit 437b5e
      bit = require "bit32"
Packit 437b5e
      fcntl = require "posix.fcntl"
Packit 437b5e
      syswait = require "posix.sys.wait"
Packit 437b5e
Packit 437b5e
      execp = unistd.execp
Packit 437b5e
Packit 437b5e
      dup2, fork, wait = unistd.dup2, unistd.fork, syswait.wait
Packit 437b5e
      open, O_WRONLY, O_APPEND = fcntl.open, fcntl.O_WRONLY, fcntl.O_APPEND
Packit 437b5e
      P_CHILD = 0
Packit 437b5e
Packit 437b5e
      -- redirect output to /dev/null
Packit 437b5e
      function child (...)
Packit 437b5e
        quietly = open ("/dev/null", bit.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
  - context with bad arguments:
Packit 437b5e
      badargs.diagnose (execp, "(string, table)")
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 sets argv[0]":
Packit 437b5e
Packit 437b5e
Packit 437b5e
- describe getegid:
Packit 437b5e
  - before:
Packit 437b5e
      getegid = unistd.getegid
Packit 437b5e
Packit 437b5e
  - context with bad arguments:
Packit 437b5e
      badargs.diagnose (getegid, "()")
Packit 437b5e
Packit 437b5e
  - it returns the effective group id:
Packit 437b5e
      expect (getegid ()).to_be (ids.pw_gid)
Packit 437b5e
Packit 437b5e
Packit 437b5e
- describe geteuid:
Packit 437b5e
  - before:
Packit 437b5e
      geteuid = unistd.geteuid
Packit 437b5e
Packit 437b5e
  - context with bad arguments:
Packit 437b5e
      badargs.diagnose (geteuid, "()")
Packit 437b5e
Packit 437b5e
  - it returns the effective user id:
Packit 437b5e
      expect (geteuid ()).to_be (ids.pw_uid)
Packit 437b5e
Packit 437b5e
Packit 437b5e
- describe getgid:
Packit 437b5e
  - before:
Packit 437b5e
      getgid = unistd.getgid
Packit 437b5e
Packit 437b5e
  - context with bad arguments:
Packit 437b5e
      badargs.diagnose (getgid, "()")
Packit 437b5e
Packit 437b5e
  - it returns the group id:
Packit 437b5e
      expect (getgid ()).to_be (ids.pw_gid)
Packit 437b5e
Packit 437b5e
Packit 437b5e
- describe gethostid:
Packit 437b5e
  - before:
Packit 437b5e
      gethostid = unistd.gethostid
Packit 437b5e
Packit 437b5e
  - context with bad arguments:
Packit 437b5e
      badargs.diagnose (gethostid, "()")
Packit 437b5e
Packit 437b5e
  - it returns an integer:
Packit 437b5e
      expect (math.floor (gethostid ())).to_be (gethostid ())
Packit 437b5e
Packit 437b5e
Packit 437b5e
- describe getuid:
Packit 437b5e
  - before:
Packit 437b5e
      getuid = unistd.getuid
Packit 437b5e
Packit 437b5e
  - context with bad arguments:
Packit 437b5e
      badargs.diagnose (getuid, "()")
Packit 437b5e
Packit 437b5e
  - it returns the user id:
Packit 437b5e
      expect (getuid ()).to_be (ids.pw_uid)
Packit 437b5e
Packit 437b5e
Packit 437b5e
- describe getpgrp:
Packit 437b5e
  - before:
Packit 437b5e
      getpgrp = unistd.getpgrp
Packit 437b5e
Packit 437b5e
  - context with bad arguments:
Packit 437b5e
      badargs.diagnose (getpgrp, "()")
Packit 437b5e
Packit 437b5e
  - it returns a positive integer:
Packit 437b5e
      expect (math.floor (getpgrp ())).to_be (getpgrp ())
Packit 437b5e
      expect (getpgrp () > 0).to_be (true)
Packit 437b5e
Packit 437b5e
Packit 437b5e
- describe getpid:
Packit 437b5e
  - before:
Packit 437b5e
      getpid = unistd.getpid
Packit 437b5e
Packit 437b5e
  - context with bad arguments:
Packit 437b5e
      badargs.diagnose (getpid, "()")
Packit 437b5e
Packit 437b5e
  - it returns the a positive integer:
Packit 437b5e
      expect (math.floor (getpid ())).to_be (getpid ())
Packit 437b5e
      expect (getpid () > 0).to_be (true)
Packit 437b5e
Packit 437b5e
Packit 437b5e
- describe getppid:
Packit 437b5e
  - before:
Packit 437b5e
      getppid = unistd.getppid
Packit 437b5e
Packit 437b5e
  - context with bad arguments:
Packit 437b5e
      badargs.diagnose (getppid, "()")
Packit 437b5e
Packit 437b5e
  - it returns a positive integer:
Packit 437b5e
      expect (math.floor (getppid ())).to_be (getppid ())
Packit 437b5e
      expect (getppid () > 0).to_be (true)
Packit 437b5e
  - it does not return the process id:
Packit 437b5e
      expect (getppid ()).not_to_be (unistd.getpid ())
Packit 437b5e
Packit 437b5e
Packit 437b5e
- describe pathconf:
Packit 437b5e
  - before:
Packit 437b5e
      pathconf = unistd.pathconf
Packit 437b5e
Packit 437b5e
  - context with bad arguments:
Packit 437b5e
      badargs.diagnose (pathconf, "(string, int)")
Packit 437b5e
Packit 437b5e
  - it returns whether chown can be used on the given file:
Packit 437b5e
      expect (type (pathconf (".", unistd._PC_CHOWN_RESTRICTED))).to_be "number"
Packit 437b5e
  - it fetches the maximum number of links to the given file:
Packit 437b5e
      expect (type (pathconf (".", unistd._PC_LINK_MAX))).to_be "number"
Packit 437b5e
  - it fetches the maximum formatted line input length for a tty:
Packit 437b5e
      expect (type (pathconf (".", unistd._PC_MAX_CANON))).to_be "number"
Packit 437b5e
  - it fetches the maximum raw line input length for a tty:
Packit 437b5e
      expect (type (pathconf (".", unistd._PC_MAX_INPUT))).to_be "number"
Packit 437b5e
  - it fetches the maximum filename length in this directory:
Packit 437b5e
      expect (type (pathconf (".", unistd._PC_NAME_MAX))).to_be "number"
Packit 437b5e
  - it fetches whether accessing overlong filenames is an error:
Packit 437b5e
      expect (type (pathconf (".", unistd._PC_NO_TRUNC))).to_be "number"
Packit 437b5e
  - it fetches the maximum relative path length from this directory:
Packit 437b5e
      expect (type (pathconf (".", unistd._PC_PATH_MAX))).to_be "number"
Packit 437b5e
  - it fetches the size of the pipe buffer:
Packit 437b5e
      expect (type (pathconf (".", unistd._PC_PIPE_BUF))).to_be "number"
Packit 437b5e
  - it fetches whether special character processing can be disabled:
Packit 437b5e
      expect (type (pathconf (".", unistd._PC_VDISABLE))).to_be "number"
Packit 437b5e
Packit 437b5e
Packit 437b5e
- describe sysconf:
Packit 437b5e
  - before:
Packit 437b5e
      sysconf = unistd.sysconf
Packit 437b5e
Packit 437b5e
  - context with bad arguments:
Packit 437b5e
      badargs.diagnose (sysconf, "(int)")
Packit 437b5e
Packit 437b5e
  - it fetches the maximum number of exec arguments:
Packit 437b5e
      expect (type (sysconf (unistd._SC_ARG_MAX))).to_be "number"
Packit 437b5e
  - it fetches the number processes per user:
Packit 437b5e
      expect (type (sysconf (unistd._SC_CHILD_MAX))).to_be "number"
Packit 437b5e
  - it fetches the number of clock ticks per second:
Packit 437b5e
      expect (type (sysconf (unistd._SC_CLK_TCK))).to_be "number"
Packit 437b5e
  - it fetches the job control version:
Packit 437b5e
      expect (type (sysconf (unistd._SC_JOB_CONTROL))).to_be "number"
Packit 437b5e
  - it fetches the maximum number of groups:
Packit 437b5e
      expect (type (sysconf (unistd._SC_NGROUPS_MAX))).to_be "number"
Packit 437b5e
  - it fetches the maximum number of open descriptors:
Packit 437b5e
      expect (type (sysconf (unistd._SC_OPEN_MAX))).to_be "number"
Packit 437b5e
  - it fetches the number of saved ids:
Packit 437b5e
      expect (type (sysconf (unistd._SC_SAVED_IDS))).to_be "number"
Packit 437b5e
  - it fetches the maximum number of open streams:
Packit 437b5e
      expect (type (sysconf (unistd._SC_STREAM_MAX))).to_be "number"
Packit 437b5e
  - it fetches the maximum length of a timezone name:
Packit 437b5e
      expect (type (sysconf (unistd._SC_TZNAME_MAX))).to_be "number"
Packit 437b5e
  - it fetches the POSIX.1 version:
Packit 437b5e
      expect (type (sysconf (unistd._SC_VERSION))).to_be "number"