Skip to content

Commit 9f60295

Browse files
committed
[Truffle] Add Kernel#test to kernel.rb.
1 parent 6550480 commit 9f60295

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed
Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
fails:Kernel#test is a private method
2-
fails:Kernel#test returns true when passed ?f if the argument is a regular file
3-
fails:Kernel#test returns true when passed ?e if the argument is a file
4-
fails:Kernel#test returns true when passed ?d if the argument is a directory
5-
fails:Kernel#test returns true when passed ?l if the argument is a symlink
6-
fails:Kernel#test returns true when passed ?r if the argument is readable by the effective uid
7-
fails:Kernel#test returns true when passed ?R if the argument is readable by the real uid
8-
fails:Kernel#test returns true when passed ?w if the argument is readable by the effective uid
9-
fails:Kernel#test returns true when passed ?W if the argument is readable by the real uid
10-
fails:Kernel#test calls #to_path on second argument when passed ?f and a filename
11-
fails:Kernel#test calls #to_path on second argument when passed ?e and a filename
12-
fails:Kernel#test calls #to_path on second argument when passed ?d and a directory
131
fails:Kernel#test time commands returns the last access time for the provided file when passed ?A
142
fails:Kernel#test time commands returns the time at which the file was created when passed ?C
153
fails:Kernel#test time commands returns the time at which the file was modified when passed ?M

truffle/src/main/ruby/core/rubinius/common/kernel.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,36 @@ def tap
228228
self
229229
end
230230

231+
def test(cmd, file1, file2=nil)
232+
case cmd
233+
when ?d
234+
File.directory? file1
235+
when ?e
236+
File.exist? file1
237+
when ?f
238+
File.file? file1
239+
when ?l
240+
File.symlink? file1
241+
when ?r
242+
File.readable? file1
243+
when ?R
244+
File.readable_real? file1
245+
when ?w
246+
File.writable? file1
247+
when ?W
248+
File.writable_real? file1
249+
when ?A
250+
File.atime file1
251+
when ?C
252+
File.ctime file1
253+
when ?M
254+
File.mtime file1
255+
else
256+
raise NotImplementedError, "command ?#{cmd.chr} not implemented"
257+
end
258+
end
259+
module_function :test
260+
231261
def open(obj, *rest, &block)
232262
if obj.respond_to?(:to_open)
233263
obj = obj.to_open(*rest)

0 commit comments

Comments
 (0)