Blame specs/posix_dirent_spec.yaml

Packit 437b5e
specify posix.dirent:
Packit 437b5e
- before:
Packit 437b5e
    dirent = require "posix.dirent"
Packit 437b5e
Packit 437b5e
Packit 437b5e
- describe dir:
Packit 437b5e
  - before:
Packit 437b5e
      dir = dirent.dir
Packit 437b5e
Packit 437b5e
  - context with bad arguments: |
Packit 437b5e
      badargs.diagnose (dir, "(?string)")
Packit 437b5e
Packit 437b5e
      examples {
Packit 437b5e
        ["it diagnoses argument #1 not a valid file"] = function ()
Packit 437b5e
          expect (dir "/not/exists").to_raise.any_of {
Packit 437b5e
            -- Can't be any more accurate, because error message is system specific
Packit 437b5e
            "bad argument #1 to 'dir' (/not/exists: ",
Packit 437b5e
            "bad argument #1 to '?' (/not/exists: ",
Packit 437b5e
          }
Packit 437b5e
        end
Packit 437b5e
      }
Packit 437b5e
Packit 437b5e
- describe files:
Packit 437b5e
  - before:
Packit 437b5e
      # Make and change into a temporary subdirectory where we can
Packit 437b5e
      # control all the contents for self-contained examples.
Packit 437b5e
      link, mkdir, mkdtemp = posix.link, posix.mkdir, posix.mkdtemp
Packit 437b5e
      origwd = posix.getcwd ()
Packit 437b5e
      dir, errmsg = mkdtemp (template)
Packit 437b5e
      mkdir (dir .. "/subdir")
Packit 437b5e
      link ("subdir", dir .. "/soft", true)
Packit 437b5e
      touch (dir .. "/file")
Packit 437b5e
      link (dir .. "/file", dir .. "/hard")
Packit 437b5e
      link ("no such destination", dir .. "/dangling", true)
Packit 437b5e
Packit 437b5e
      files = dirent.files
Packit 437b5e
Packit 437b5e
  - after:
Packit 437b5e
      posix.chdir (origwd)
Packit 437b5e
      rmtmp (dir)
Packit 437b5e
Packit 437b5e
  - context with bad arguments: |
Packit 437b5e
      badargs.diagnose (files, "(?string)")
Packit 437b5e
Packit 437b5e
      examples {
Packit 437b5e
        ["it diagnoses argument #1 not a valid file"] = function ()
Packit 437b5e
          expect (files "/not/exists").to_raise.any_of {
Packit 437b5e
            -- Can't be any more accurate, because error message is system specific
Packit 437b5e
            "bad argument #1 to 'files' (/not/exists: ",
Packit 437b5e
            "bad argument #1 to '?' (/not/exists: ",
Packit 437b5e
          }
Packit 437b5e
        end
Packit 437b5e
      }
Packit 437b5e
Packit 437b5e
  - it returns a table of files in the given directory:
Packit 437b5e
      t = {}
Packit 437b5e
      for f in files (dir) do
Packit 437b5e
        table.insert (t, f)
Packit 437b5e
      end
Packit 437b5e
      table.sort (t)
Packit 437b5e
      expect (t).to_equal {".", "..", "dangling", "file", "hard", "soft", "subdir"}