mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* test/fileutils/fileasserts.rb
(Test::Unit::FileAssertions#{assert_filemode,assert_equal_timestamp}): New utility assertion methods for testing file modes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41859 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3ac1eeb34d
commit
3488db9455
2 changed files with 66 additions and 49 deletions
|
@ -67,6 +67,27 @@ EOT
|
|||
assert_equal(expected.tv_sec, actual.tv_sec, full_message)
|
||||
end
|
||||
|
||||
def assert_filemode(expected, file, message=nil, mask: 07777)
|
||||
width = ('%o' % mask).size
|
||||
actual = File.stat(file).mode & mask
|
||||
assert expected == actual, <<EOT
|
||||
File mode of "#{file}" unexpected:
|
||||
Expected: <#{'%0*o' % [width, expected]}>
|
||||
Actual: <#{'%0*o' % [width, actual]}>
|
||||
EOT
|
||||
end
|
||||
|
||||
def assert_equal_filemode(file1, file2, message=nil, mask: 07777)
|
||||
mode1, mode2 = [file1, file2].map { |file|
|
||||
File.stat(file).mode & mask
|
||||
}
|
||||
width = ('%o' % mask).size
|
||||
assert mode1 == mode2, <<EOT
|
||||
File modes expected to be equal:
|
||||
<#{'%0*o' % [width, mode1]}>: "#{file1}"
|
||||
<#{'%0*o' % [width, mode2]}>: "#{file2}"
|
||||
EOT
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue