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

[rbs diff] Fix error when empty manifest.yaml #1762

Merged
merged 1 commit into from
Mar 11, 2024
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
2 changes: 1 addition & 1 deletion lib/rbs/diff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def build_env(path)
manifest_pathname = dir_pathname / 'manifest.yaml'
if manifest_pathname.exist?
manifest = YAML.safe_load(manifest_pathname.read)
if manifest['dependencies']
if manifest && manifest['dependencies']
manifest['dependencies'].each do |dependency|
loader.add(library: dependency['name'], version: nil)
end
Expand Down
69 changes: 69 additions & 0 deletions test/rbs/diff_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,73 @@ class Foo
], results
end
end

def test_with_manifest_yaml
mktmpdir do |path|
dir1 = (path / "dir1")
dir1.mkdir
(dir1 / 'before.rbs').write(<<~RBS)
class Pathname
end
RBS
(dir1 / 'manifest.yaml').write(<<~RBS)
dependencies:
- name: pathname
RBS

dir2 = (path / "dir2")
dir2.mkdir
(dir2 / 'after.rbs').write(<<~RBS)
class Pathname
def foooooooo: () -> void
end
RBS
(dir2 / 'manifest.yaml').write(<<~RBS)
dependencies:
- name: pathname
RBS

diff = Diff.new(
type_name: TypeName("::Pathname"),
library_options: RBS::CLI::LibraryOptions.new,
before_path: [dir1],
after_path: [dir2],
detail: true,
)
assert_equal [["-", "[::Pathname public] def foooooooo: () -> void"]], diff.each_diff.to_a
end
end

def test_with_empty_manifest_yaml
mktmpdir do |path|
dir1 = (path / "dir1")
dir1.mkdir
(dir1 / 'before.rbs').write(<<~RBS)
class Foo
end
RBS
(dir1 / 'manifest.yaml').write(<<~RBS)
# empty
RBS

dir2 = (path / "dir2")
dir2.mkdir
(dir2 / 'after.rbs').write(<<~RBS)
class Foo
end
RBS
(dir2 / 'manifest.yaml').write(<<~RBS)
# empty
RBS

diff = Diff.new(
type_name: TypeName("::Foo"),
library_options: RBS::CLI::LibraryOptions.new,
before_path: [dir1],
after_path: [dir2],
detail: true,
)
assert_equal [], diff.each_diff.to_a
end
end
end