Skip to content

Commit

Permalink
add windows exceptions to file permissions for files tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mfelsche committed Apr 20, 2018
1 parent 3eb2684 commit e33a438
Showing 1 changed file with 33 additions and 21 deletions.
54 changes: 33 additions & 21 deletions packages/files/_test.pony
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,16 @@ class iso _TestFileCreateDirNotWriteable is _NonRootTest
try
let file_path = dir_path.join("trycreateme")?
let file = File(file_path)
h.assert_false(file.valid())
h.assert_true(file.writeable)

ifdef windows then
// assuming that on windows opening is fine
// but on writing it will fail
h.assert_true(file.valid())
h.assert_false(file.write("oh noes!"))
end

h.assert_false(file.valid())
h.assert_is[FileErrNo](file.errno(), FilePermissionDenied)
then
mode.owner_write = true
Expand Down Expand Up @@ -498,27 +506,31 @@ class _TestFileOpenWrite is UnitTest
class iso _TestFileOpenPermissionDenied is _NonRootTest
fun name(): String => "files/File.open-permission-denied"
fun apply_as_non_root(h: TestHelper) =>
try
let filepath = FilePath(h.env.root as AmbientAuth, "tmp.open-not-readable")?
with file = CreateFile(filepath) as File do
file.print("unreadable")
ifdef not windows then
// on windows all files are always writeable
// with chmod there is no way to make a file not readable
try
let filepath = FilePath(h.env.root as AmbientAuth, "tmp.open-not-readable")?
with file = CreateFile(filepath) as File do
file.print("unreadable")
end
let mode: FileMode ref = FileMode.>private()
mode.owner_read = false
mode.owner_write = false
h.assert_true(filepath.chmod(mode))
let opened = File.open(filepath)
h.assert_true(opened.errno() is FilePermissionDenied)
h.assert_false(opened.valid())
let read = opened.read(10)
h.assert_eq[USize](read.size(), 0)

mode.owner_read = true
mode.owner_write = true
filepath.chmod(mode)
filepath.remove()
else
h.fail("Unhandled error!")
end
let mode: FileMode ref = FileMode.>private()
mode.owner_read = false
mode.owner_write = false
h.assert_true(filepath.chmod(mode))
let opened = File.open(filepath)
h.assert_true(opened.errno() is FilePermissionDenied)
h.assert_false(opened.valid())
let read = opened.read(10)
h.assert_eq[USize](read.size(), 0)

mode.owner_read = true
mode.owner_write = true
filepath.chmod(mode)
filepath.remove()
else
h.fail("Unhandled error!")
end


Expand Down

0 comments on commit e33a438

Please sign in to comment.