Skip to content

Commit ee7f36e

Browse files
authored
Merge pull request #179 from nobu/test-touch
Add tests for `FileUtils.touch`
2 parents bff17dd + 86278df commit ee7f36e

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

‎test/fileutils/test_fileutils.rb‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,6 +2059,37 @@ def test_touch
20592059
check_singleton :touch
20602060
end
20612061

2062+
def test_touch_verbose
2063+
assert_output_lines(["touch file"]) do
2064+
touch('file', verbose: true, noop: true)
2065+
end
2066+
assert_output_lines(["touch -c file"]) do
2067+
touch('file', verbose: true, noop: true, nocreate: true)
2068+
end
2069+
t = Time.new(2026, 5, 4, 3, 2, 1)
2070+
assert_output_lines(["touch -t 202605040302.01 file"]) do
2071+
touch('file', verbose: true, noop: true, mtime: t)
2072+
end
2073+
end
2074+
2075+
def test_touch_create
2076+
t0 = Time.now - 10 # discrepancies caused by remote file systems?
2077+
assert_file.not_exist?('file')
2078+
assert_raise(Errno::ENOENT) {touch('file', nocreate: true)}
2079+
assert_file.not_exist?('file')
2080+
touch('file')
2081+
assert_file.exist?('file')
2082+
t = File.mtime('file')
2083+
assert_operator(t, :>=, t0)
2084+
assert_operator(t, :<=, Time.now + 10)
2085+
end
2086+
2087+
def test_touch_mtime
2088+
t = Time.new(2026, 5, 4, 3, 2, 1)
2089+
touch('file', mtime: t)
2090+
assert_equal(t, File.mtime('file'))
2091+
end
2092+
20622093
def test_collect_methods
20632094
end
20642095

0 commit comments

Comments
 (0)