Skip to content

Commit

Permalink
[Truffle] Add Kernel#test to kernel.rb.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjfish committed Apr 24, 2015
1 parent 6550480 commit 9f60295
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
12 changes: 0 additions & 12 deletions spec/truffle/tags/core/kernel/test_tags.txt
@@ -1,15 +1,3 @@
fails:Kernel#test is a private method
fails:Kernel#test returns true when passed ?f if the argument is a regular file
fails:Kernel#test returns true when passed ?e if the argument is a file
fails:Kernel#test returns true when passed ?d if the argument is a directory
fails:Kernel#test returns true when passed ?l if the argument is a symlink
fails:Kernel#test returns true when passed ?r if the argument is readable by the effective uid
fails:Kernel#test returns true when passed ?R if the argument is readable by the real uid
fails:Kernel#test returns true when passed ?w if the argument is readable by the effective uid
fails:Kernel#test returns true when passed ?W if the argument is readable by the real uid
fails:Kernel#test calls #to_path on second argument when passed ?f and a filename
fails:Kernel#test calls #to_path on second argument when passed ?e and a filename
fails:Kernel#test calls #to_path on second argument when passed ?d and a directory
fails:Kernel#test time commands returns the last access time for the provided file when passed ?A
fails:Kernel#test time commands returns the time at which the file was created when passed ?C
fails:Kernel#test time commands returns the time at which the file was modified when passed ?M
30 changes: 30 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/kernel.rb
Expand Up @@ -228,6 +228,36 @@ def tap
self
end

def test(cmd, file1, file2=nil)
case cmd
when ?d
File.directory? file1
when ?e
File.exist? file1
when ?f
File.file? file1
when ?l
File.symlink? file1
when ?r
File.readable? file1
when ?R
File.readable_real? file1
when ?w
File.writable? file1
when ?W
File.writable_real? file1
when ?A
File.atime file1
when ?C
File.ctime file1
when ?M
File.mtime file1
else
raise NotImplementedError, "command ?#{cmd.chr} not implemented"
end
end
module_function :test

def open(obj, *rest, &block)
if obj.respond_to?(:to_open)
obj = obj.to_open(*rest)
Expand Down

0 comments on commit 9f60295

Please sign in to comment.