From 5ca73c54ec24ab16199869466e47e5b54c6de1d4 Mon Sep 17 00:00:00 2001 From: "William T. Nelson" <35801+wtn@users.noreply.github.com> Date: Sun, 15 Nov 2026 21:35:29 -0600 Subject: [PATCH] Fix Shell#unlink for regular files CommandProcessor#unlink called IO.unlink for non-directory paths, but IO has no unlink method, so removing a file raised NoMethodError. Call File.unlink instead, and correct the doc comment that pointed to IO.unlink. Add tests for unlinking a file and a directory. Co-authored-by: Claude Opus 5.5 --- lib/shell/command-processor.rb | 4 ++-- test/shell/test_command_processor.rb | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/shell/command-processor.rb b/lib/shell/command-processor.rb index 20fea43..6e47dfe 100644 --- a/lib/shell/command-processor.rb +++ b/lib/shell/command-processor.rb @@ -129,7 +129,7 @@ def open(path, mode = nil, perm = 0666, &b) # call-seq: # unlink(path) # - # See IO.unlink when +path+ is a file. + # See File.unlink when +path+ is a file. # # See Dir.unlink when +path+ is a directory. # @@ -140,7 +140,7 @@ def unlink(path) if File.directory?(path) Dir.unlink(path) else - IO.unlink(path) + File.unlink(path) end Void.new(@shell) end diff --git a/test/shell/test_command_processor.rb b/test/shell/test_command_processor.rb index 928d40e..b480e3d 100644 --- a/test/shell/test_command_processor.rb +++ b/test/shell/test_command_processor.rb @@ -86,6 +86,30 @@ def test_test File.unlink(path) end + def test_unlink_file + name = "foo" + path = File.join(@tmpdir, name) + open(path, "w") {} + + @shell.cd(@tmpdir) + assert_kind_of(Shell::Void, @shell.unlink(name)) + assert_not_send([File, :exist?, path]) + ensure + File.unlink(path) if File.exist?(path) + end + + def test_unlink_directory + name = "foo" + path = File.join(@tmpdir, name) + Dir.mkdir(path) + + @shell.cd(@tmpdir) + assert_kind_of(Shell::Void, @shell.unlink(name)) + assert_not_send([File, :exist?, path]) + ensure + Dir.rmdir(path) if File.exist?(path) + end + def test_option_type name = 'foo.cmd' path = File.join(@tmpdir, name)