Skip to content

Commit

Permalink
Fix log message when eager loading a directory ends
Browse files Browse the repository at this point in the history
  • Loading branch information
fxn committed Jul 18, 2024
1 parent 4f285de commit 9e3e043
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/zeitwerk/loader/eager_load.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ def load_file(path)
log("eager load directory #{dir} start") if logger

queue = [[dir, namespace]]
while (dir, namespace = queue.shift)
ls(dir) do |basename, abspath, ftype|
while (current_dir, namespace = queue.shift)
ls(current_dir) do |basename, abspath, ftype|
next if honour_exclusions && eager_load_exclusions.member?(abspath)

if ftype == :file
Expand Down
20 changes: 20 additions & 0 deletions test/lib/zeitwerk/test_logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,26 @@ def logger.debug(message)
end
end

test "logs when eager loading a directory starts" do
with_files([]) do
assert_logged(%r(eager load directory #{Dir.pwd} start)) do
loader.push_dir(".")
loader.setup
loader.eager_load_dir(".")
end
end
end

test "logs when eager loading a directory ends" do
with_files([]) do
assert_logged(%r(eager load directory #{Dir.pwd} end)) do
loader.push_dir(".")
loader.setup
loader.eager_load_dir(".")
end
end
end

test "logs when eager loading starts" do
with_setup do
assert_logged(/eager load start/) do
Expand Down

0 comments on commit 9e3e043

Please sign in to comment.