file_perm_spec.lua 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. -- Test getting and setting file permissions.
  2. require('os')
  3. local helpers = require('test.functional.helpers')(after_each)
  4. local clear, call, eq = helpers.clear, helpers.call, helpers.eq
  5. local neq, exc_exec, eval = helpers.neq, helpers.exc_exec, helpers.eval
  6. describe('Test getting and setting file permissions', function()
  7. local tempfile = helpers.tmpname()
  8. before_each(function()
  9. os.remove(tempfile)
  10. clear()
  11. end)
  12. it('file permissions', function()
  13. -- eval() is used to test VimL method syntax for setfperm() and getfperm()
  14. eq('', call('getfperm', tempfile))
  15. eq(0, eval("'" .. tempfile .. "'->setfperm('r--------')"))
  16. call('writefile', {'one'}, tempfile)
  17. eq(9, eval("len('" .. tempfile .. "'->getfperm())"))
  18. eq(1, call('setfperm', tempfile, 'rwx------'))
  19. if helpers.is_os('win') then
  20. eq('rw-rw-rw-', call('getfperm', tempfile))
  21. else
  22. eq('rwx------', call('getfperm', tempfile))
  23. end
  24. eq(1, call('setfperm', tempfile, 'r--r--r--'))
  25. eq('r--r--r--', call('getfperm', tempfile))
  26. local err = exc_exec(('call setfperm("%s", "---")'):format(tempfile))
  27. neq(err:find('E475:'), nil)
  28. eq(1, call('setfperm', tempfile, 'rwx------'))
  29. end)
  30. after_each(function()
  31. os.remove(tempfile)
  32. end)
  33. end)