Skip to content

Commit 3ee5d06

Browse files
committed
[GR-20446] Check that $VERBOSE and $DEBUG are not changed by specs
PullRequest: truffleruby/2037
2 parents 3c337b7 + ec4d450 commit 3ee5d06

File tree

4 files changed

+41
-9
lines changed

4 files changed

+41
-9
lines changed

spec/mspec/lib/mspec/runner/actions/leakchecker.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def initialize
3636
@thread_info = find_threads
3737
@env_info = find_env
3838
@argv_info = find_argv
39+
@globals_info = find_globals
3940
@encoding_info = find_encodings
4041
end
4142

@@ -48,9 +49,10 @@ def check(state)
4849
check_process_leak
4950
check_env
5051
check_argv
52+
check_globals
5153
check_encodings
5254
check_tracepoints
53-
GC.start if !@leaks.empty?
55+
GC.start unless @leaks.empty?
5456
@leaks.empty?
5557
end
5658

@@ -244,6 +246,19 @@ def check_argv
244246
end
245247
end
246248

249+
def find_globals
250+
{ verbose: $VERBOSE, debug: $DEBUG }
251+
end
252+
253+
def check_globals
254+
old_globals = @globals_info
255+
new_globals = find_globals
256+
if new_globals != old_globals
257+
leak "Globals changed: #{old_globals.inspect} to #{new_globals.inspect}"
258+
@globals_info = new_globals
259+
end
260+
end
261+
247262
def find_encodings
248263
[Encoding.default_internal, Encoding.default_external]
249264
end

spec/ruby/core/module/autoload_spec.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require_relative '../../spec_helper'
2+
require_relative '../../fixtures/code_loading'
23
require_relative 'fixtures/classes'
34
require 'thread'
45

@@ -33,14 +34,7 @@
3334
describe "Module#autoload" do
3435
before :all do
3536
@non_existent = fixture __FILE__, "no_autoload.rb"
36-
37-
# Require RubyGems eagerly, to ensure #require is already the RubyGems
38-
# version, before starting #autoload specs which snapshot #require, and
39-
# could end up redefining #require as the original core Kernel#require.
40-
begin
41-
require "rubygems"
42-
rescue LoadError
43-
end
37+
CodeLoadingSpecs.preload_rubygems
4438
end
4539

4640
before :each do

spec/ruby/fixtures/code_loading.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,22 @@ def load(name, wrap=false)
1212
end
1313
end
1414

15+
def self.preload_rubygems
16+
# Require RubyGems eagerly, to ensure #require is already the RubyGems
17+
# version and RubyGems is only loaded once, before starting #require/#autoload specs
18+
# which snapshot $LOADED_FEATURES and could cause RubyGems to load twice.
19+
# #require specs also snapshot #require, and could end up redefining #require as the original core Kernel#require.
20+
@rubygems ||= begin
21+
require "rubygems"
22+
true
23+
rescue LoadError
24+
true
25+
end
26+
end
27+
1528
def self.spec_setup
29+
preload_rubygems
30+
1631
@saved_loaded_features = $LOADED_FEATURES.clone
1732
@saved_load_path = $LOAD_PATH.clone
1833
ScratchPad.record []

spec/ruby/language/predefined_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,14 @@ def obj.foo2; yield; end
933933
end
934934

935935
describe "Global variable $VERBOSE" do
936+
before :each do
937+
@verbose = $VERBOSE
938+
end
939+
940+
after :each do
941+
$VERBOSE = @verbose
942+
end
943+
936944
it "converts truthy values to true" do
937945
[true, 1, 0, [], ""].each do |true_value|
938946
$VERBOSE = true_value

0 commit comments

Comments
 (0)