Skip to content

Commit

Permalink
Abort on warnings again
Browse files Browse the repository at this point in the history
  • Loading branch information
fxn committed Apr 10, 2023
1 parent 7cac78e commit e326390
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 27 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ gem "minitest"
gem "minitest-focus"
gem "minitest-proveit"
gem "minitest-reporters"
gem "warning"
12 changes: 6 additions & 6 deletions lib/zeitwerk/loader/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,9 @@ def log!
# Common use case.
return false if ignored_paths.empty?

walk_up(abspath) do |abspath|
return true if ignored_path?(abspath)
return false if roots.key?(abspath)
walk_up(abspath) do |path|
return true if ignored_path?(path)
return false if roots.key?(path)
end

false
Expand Down Expand Up @@ -328,9 +328,9 @@ def log!
# Optimize this common use case.
return false if eager_load_exclusions.empty?

walk_up(abspath) do |abspath|
return true if eager_load_exclusions.member?(abspath)
return false if roots.key?(abspath)
walk_up(abspath) do |path|
return true if eager_load_exclusions.member?(path)
return false if roots.key?(path)
end

false
Expand Down
5 changes: 4 additions & 1 deletion test/lib/zeitwerk/test_autovivification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,17 @@ module Namespace; end
end

test "autovivification is synchronized" do
$test_admin_const_set_calls = 0
$test_admin_const_set_queue = Queue.new

files = [["admin/v2/user.rb", "class Admin::V2::User; end"]]
with_setup(files) do
assert Admin

def Admin.const_set(cname, mod)
$test_admin_const_set_calls += 1
$test_admin_const_set_queue << true
sleep 0.5
sleep 0.1
super
end

Expand All @@ -92,6 +94,7 @@ def Admin.const_set(cname, mod)

concurrent_autovivifications.each(&:join)

assert_equal 1, $test_admin_const_set_calls
assert $test_admin_const_set_queue.empty?
end
end
Expand Down
19 changes: 0 additions & 19 deletions test/support/no_warnings_policy.rb

This file was deleted.

21 changes: 20 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,26 @@
require "minitest/reporters"
Minitest::Reporters.use!(Minitest::Reporters::DefaultReporter.new)

# require_relative "support/no_warnings_policy"
require "warning"
Warning.process do |msg|
# This warning is issued by Zeitwerk itself, ignore it.
if msg.include?("Zeitwerk defines the constant")
:default
# These ones are issued by the test "autovivification is synchronized" from
# test_autovivification.rb, but only on Ruby 2.5. They can be ignored, the
# test verifies the constant is set only once. I suspect this is related to
# the internal representation of constants in CRuby and
#
# https://github.com/ruby/ruby/commit/b74131132f8872d23e405c61ecfe18dece17292f
#
# fixed it, but have not verified it.
elsif msg.include?("already initialized constant Admin::V2") || msg.include?("previous definition of V2 was here")
:default
else
:raise
end
end

require_relative "support/test_macro"
require_relative "support/delete_loaded_feature"
require_relative "support/loader_test"
Expand Down

0 comments on commit e326390

Please sign in to comment.