Skip to content

Commit 19ff60c

Browse files
authored
Skip directories ending with .rb when collecting analysis targets (#454)
`Dir.glob("**/*.{rb,rbs}")` matches not only files but also directories whose names end with `.rb` or `.rbs`. Such directories exist in real projects (e.g. the `http_parser.rb` gem directory inside rubygems' VCR cassettes), and `Service#batch` then crashes with `Errno::EISDIR` while trying to `File.read` them. Filter the glob result to regular files only.
1 parent 184ff7d commit 19ff60c

4 files changed

Lines changed: 21 additions & 1 deletion

File tree

lib/typeprof/cli/cli.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def find_files
156156
files = []
157157
@cli_options[:argv].each do |path|
158158
if File.directory?(path)
159-
files.concat(Dir.glob("#{ path }/**/*.{rb,rbs}"))
159+
files.concat(Dir.glob("#{ path }/**/*.{rb,rbs}").select {|f| File.file?(f) })
160160
elsif File.file?(path)
161161
files << path
162162
else

test/cli_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,21 @@ def foo: (String) -> String
156156
END
157157
end
158158

159+
def test_e2e_dir_with_rb_suffix
160+
# A directory whose name ends with `.rb` (e.g. the `http_parser.rb`
161+
# gem name appearing in rubygems' VCR cassettes) must be skipped,
162+
# not opened as a Ruby file.
163+
# https://github.com/rubygems/rubygems/tree/v4.0.11/bundler/spec/support/artifice/vcr_cassettes/realworld/index.rubygems.org/info/http_parser.rb
164+
assert_equal(<<~END, test_run("dir_with_rb_suffix", ["."]))
165+
# TypeProf #{ TypeProf::VERSION }
166+
167+
# ./main.rb
168+
class Object
169+
def foo: (String) -> String
170+
end
171+
END
172+
end
173+
159174
def test_e2e_show_stats
160175
result = test_run("show_stats", ["--no-show-typeprof-version", "--show-stats", "."])
161176
stats = result[/# TypeProf Evaluation Statistics.*/m]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def foo(n)
2+
n
3+
end
4+
5+
foo("str")

test/fixtures/dir_with_rb_suffix/sub.rb/.keep

Whitespace-only changes.

0 commit comments

Comments
 (0)