Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subtract: Remove RBS file if the subtracted definition is empty #1385

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/rbs/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,11 @@ def run_subtract(args, _)
w.write(subtracted)

if write_to_file
rbs_path.write(io.string)
if io.string.empty?
rbs_path.delete
else
rbs_path.write(io.string)
end
else
stdout.puts(io.string)
end
Expand Down
25 changes: 25 additions & 0 deletions test/rbs/cli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,31 @@ def y: () -> untyped
end
end


def test_subtract_write_removes_definition_if_empty
Dir.mktmpdir do |dir|
dir = Pathname(dir)

minuend = dir.join('minuend.rbs')
minuend.write(<<~RBS)
class C
def x: () -> untyped
end
RBS
subtrahend = dir.join('subtrahend.rbs')
subtrahend.write(<<~RBS)
class C
def x: () -> untyped
end
RBS

stdout, stderr = run_rbs('subtract', '--write', minuend.to_s, subtrahend.to_s)
assert_empty stderr
assert_empty stdout
assert_equal minuend.exist?, false
end
end

def assert_rbs_test_no_errors cli, dir, arg_array
args = ['-I', dir.to_s, 'test', *arg_array]
assert_instance_of Process::Status, cli.run(args)
Expand Down