summaryrefslogtreecommitdiff
path: root/spec/ruby/fixtures
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/fixtures')
-rw-r--r--spec/ruby/fixtures/class.rb6
-rw-r--r--spec/ruby/fixtures/code/a/load_fixture.dylib1
-rw-r--r--spec/ruby/fixtures/code/c/load_fixture.rb1
-rw-r--r--spec/ruby/fixtures/code/concurrent.rb2
-rw-r--r--spec/ruby/fixtures/code/concurrent_require_fixture.rb4
-rw-r--r--spec/ruby/fixtures/code/d/load_fixture.rb.rb1
-rw-r--r--spec/ruby/fixtures/code/load_fixture.dylib1
-rw-r--r--spec/ruby/fixtures/code/load_fixture.ext.dylib1
-rw-r--r--spec/ruby/fixtures/code/load_wrap_fixture.rb12
-rw-r--r--spec/ruby/fixtures/code/wrap_fixture.rb3
-rw-r--r--spec/ruby/fixtures/code_loading.rb15
-rw-r--r--spec/ruby/fixtures/constants.rb42
-rw-r--r--spec/ruby/fixtures/enumerator/classes.rb15
-rw-r--r--spec/ruby/fixtures/io.rb12
-rw-r--r--spec/ruby/fixtures/math/common.rb3
-rw-r--r--spec/ruby/fixtures/rational.rb14
16 files changed, 93 insertions, 40 deletions
diff --git a/spec/ruby/fixtures/class.rb b/spec/ruby/fixtures/class.rb
index d2ae14ecb7..98cb6c82a2 100644
--- a/spec/ruby/fixtures/class.rb
+++ b/spec/ruby/fixtures/class.rb
@@ -112,7 +112,7 @@ module ClassSpecs
class M < L; end
# Can't use a method here because of class definition in method body error
- ANON_CLASS_FOR_NEW = lambda do
+ ANON_CLASS_FOR_NEW = -> do
Class.new do
class NamedInModule
end
@@ -122,6 +122,10 @@ module ClassSpecs
end
end
end
+
+ DEFINE_CLASS = -> do
+ class ::A; end
+ end
end
class Class
diff --git a/spec/ruby/fixtures/code/a/load_fixture.dylib b/spec/ruby/fixtures/code/a/load_fixture.dylib
new file mode 100644
index 0000000000..31f4b1a7bb
--- /dev/null
+++ b/spec/ruby/fixtures/code/a/load_fixture.dylib
@@ -0,0 +1 @@
+ScratchPad << :ext_dylib
diff --git a/spec/ruby/fixtures/code/c/load_fixture.rb b/spec/ruby/fixtures/code/c/load_fixture.rb
new file mode 100644
index 0000000000..4a6e9c9601
--- /dev/null
+++ b/spec/ruby/fixtures/code/c/load_fixture.rb
@@ -0,0 +1 @@
+ScratchPad << :loaded
diff --git a/spec/ruby/fixtures/code/concurrent.rb b/spec/ruby/fixtures/code/concurrent.rb
index 054b8fc055..b3602a3db4 100644
--- a/spec/ruby/fixtures/code/concurrent.rb
+++ b/spec/ruby/fixtures/code/concurrent.rb
@@ -2,7 +2,7 @@ ScratchPad.recorded << :con_pre
Thread.current[:in_concurrent_rb] = true
if t = Thread.current[:wait_for]
- Thread.pass until t.backtrace && t.backtrace.any? { |call| call.include? 'require' }
+ Thread.pass until t.backtrace && t.backtrace.any? { |call| call.include? 'require' } && t.stop?
end
if Thread.current[:con_raise]
diff --git a/spec/ruby/fixtures/code/concurrent_require_fixture.rb b/spec/ruby/fixtures/code/concurrent_require_fixture.rb
new file mode 100644
index 0000000000..d4ce734183
--- /dev/null
+++ b/spec/ruby/fixtures/code/concurrent_require_fixture.rb
@@ -0,0 +1,4 @@
+object = ScratchPad.recorded
+thread = Thread.new { object.require(__FILE__) }
+Thread.pass until thread.stop?
+ScratchPad.record(thread)
diff --git a/spec/ruby/fixtures/code/d/load_fixture.rb.rb b/spec/ruby/fixtures/code/d/load_fixture.rb.rb
new file mode 100644
index 0000000000..7e9217729a
--- /dev/null
+++ b/spec/ruby/fixtures/code/d/load_fixture.rb.rb
@@ -0,0 +1 @@
+ScratchPad << :rbrb
diff --git a/spec/ruby/fixtures/code/load_fixture.dylib b/spec/ruby/fixtures/code/load_fixture.dylib
new file mode 100644
index 0000000000..31f4b1a7bb
--- /dev/null
+++ b/spec/ruby/fixtures/code/load_fixture.dylib
@@ -0,0 +1 @@
+ScratchPad << :ext_dylib
diff --git a/spec/ruby/fixtures/code/load_fixture.ext.dylib b/spec/ruby/fixtures/code/load_fixture.ext.dylib
new file mode 100644
index 0000000000..31f4b1a7bb
--- /dev/null
+++ b/spec/ruby/fixtures/code/load_fixture.ext.dylib
@@ -0,0 +1 @@
+ScratchPad << :ext_dylib
diff --git a/spec/ruby/fixtures/code/load_wrap_fixture.rb b/spec/ruby/fixtures/code/load_wrap_fixture.rb
new file mode 100644
index 0000000000..526bbf8c82
--- /dev/null
+++ b/spec/ruby/fixtures/code/load_wrap_fixture.rb
@@ -0,0 +1,12 @@
+class LoadSpecWrap
+ ScratchPad << String
+end
+
+LOAD_WRAP_SPECS_TOP_LEVEL_CONSTANT = 1
+
+def load_wrap_specs_top_level_method
+ :load_wrap_specs_top_level_method
+end
+ScratchPad << method(:load_wrap_specs_top_level_method).owner
+
+ScratchPad << self
diff --git a/spec/ruby/fixtures/code/wrap_fixture.rb b/spec/ruby/fixtures/code/wrap_fixture.rb
deleted file mode 100644
index b83a8970d7..0000000000
--- a/spec/ruby/fixtures/code/wrap_fixture.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-class LoadSpecWrap
- ScratchPad << self
-end
diff --git a/spec/ruby/fixtures/code_loading.rb b/spec/ruby/fixtures/code_loading.rb
index d6cf0edb47..decd56a358 100644
--- a/spec/ruby/fixtures/code_loading.rb
+++ b/spec/ruby/fixtures/code_loading.rb
@@ -12,7 +12,22 @@ module CodeLoadingSpecs
end
end
+ def self.preload_rubygems
+ # Require RubyGems eagerly, to ensure #require is already the RubyGems
+ # version and RubyGems is only loaded once, before starting #require/#autoload specs
+ # which snapshot $LOADED_FEATURES and could cause RubyGems to load twice.
+ # #require specs also snapshot #require, and could end up redefining #require as the original core Kernel#require.
+ @rubygems ||= begin
+ require "rubygems"
+ true
+ rescue LoadError
+ true
+ end
+ end
+
def self.spec_setup
+ preload_rubygems
+
@saved_loaded_features = $LOADED_FEATURES.clone
@saved_load_path = $LOAD_PATH.clone
ScratchPad.record []
diff --git a/spec/ruby/fixtures/constants.rb b/spec/ruby/fixtures/constants.rb
index e5b20596ef..7f0b88daab 100644
--- a/spec/ruby/fixtures/constants.rb
+++ b/spec/ruby/fixtures/constants.rb
@@ -1,7 +1,7 @@
# Contains all static code examples of all constants behavior in language and
# library specs. The specs include language/constants_spec.rb and the specs
-# for Module#const_defined?, Module#const_get, Module#const_set,
-# Module#remove_const, Module#const_missing and Module#constants.
+# for Module#const_defined?, Module#const_get, Module#const_set, Module#remove_const,
+# Module#const_source_location, Module#const_missing and Module#constants.
#
# Rather than defining a class structure for each example, a canonical set of
# classes is used along with numerous constants, in most cases, a unique
@@ -10,7 +10,7 @@
# variety in class and module configurations, including hierarchy,
# containment, inclusion, singletons and toplevel.
#
-# Constants are numbered for for uniqueness. The CS_ prefix is uniformly used
+# Constants are numbered for uniqueness. The CS_ prefix is uniformly used
# and is to minimize clashes with other toplevel constants (see e.g. ModuleA
# which is included in Object). Constant values are symbols. A numbered suffix
# is used to distinguish constants with the same name defined in different
@@ -28,28 +28,34 @@
# for completeness. No other constant of this name should be defined in the
# specs.
CS_CONST1 = :const1 # only defined here
+CS_CONST1_LINE = __LINE__ - 1
module ConstantSpecs
# Included at toplevel
module ModuleA
CS_CONST10 = :const10_1
+ CS_CONST10_LINE = __LINE__ - 1
CS_CONST12 = :const12_2
CS_CONST13 = :const13
+ CS_CONST13_LINE = __LINE__ - 1
CS_CONST21 = :const21_2
end
# Included in ParentA
module ModuleB
+ LINE = __LINE__ - 1
CS_CONST10 = :const10_9
CS_CONST11 = :const11_2
CS_CONST12 = :const12_1
+ CS_CONST12_LINE = __LINE__ - 1
end
# Included in ChildA
module ModuleC
CS_CONST10 = :const10_4
CS_CONST15 = :const15_1
+ CS_CONST15_LINE = __LINE__ - 1
end
# Included in ChildA metaclass
@@ -70,12 +76,21 @@ module ConstantSpecs
CS_CONST10 = :const10_8
end
+ # Included in ContainerA
+ module ModuleIncludePrepended
+ prepend ModuleD
+
+ CS_CONST11 = :const11_8
+ end
+
# The following classes/modules have all the constants set "statically".
# Contrast with the classes below where the constants are set as the specs
# are run.
class ClassA
+ LINE = __LINE__ - 1
CS_CONST10 = :const10_10
+ CS_CONST10_LINE = __LINE__ - 1
CS_CONST16 = :const16
CS_CONST17 = :const17_2
CS_CONST22 = :const22_1
@@ -97,10 +112,14 @@ module ConstantSpecs
include ModuleB
CS_CONST4 = :const4
+ CS_CONST4_LINE = __LINE__ - 1
CS_CONST10 = :const10_5
+ CS_CONST10_LINE = __LINE__ - 1
CS_CONST11 = :const11_1
+ CS_CONST11_LINE = __LINE__ - 1
CS_CONST15 = :const15_2
CS_CONST20 = :const20_2
+ CS_CONST20_LINE = __LINE__ - 1
CS_CONST21 = :const21_1
CS_CONST22 = :const22_2
@@ -118,6 +137,7 @@ module ConstantSpecs
CS_CONST5 = :const5
CS_CONST10 = :const10_2
+ CS_CONST10_LINE = __LINE__ - 1
CS_CONST23 = :const23
class ChildA < ParentA
@@ -135,6 +155,7 @@ module ConstantSpecs
CS_CONST6 = :const6
CS_CONST10 = :const10_3
+ CS_CONST10_LINE = __LINE__ - 1
CS_CONST19 = :const19_2
def self.const10; CS_CONST10; end
@@ -156,6 +177,10 @@ module ConstantSpecs
def const10; CS_CONST10; end
end
+ class ContainerPrepend
+ include ModuleIncludePrepended
+ end
+
class ContainerA::ChildA
def self.const23; CS_CONST23; end
end
@@ -282,7 +307,18 @@ module ConstantSpecs
end
CS_PRIVATE = :cs_private
+ CS_PRIVATE_LINE = __LINE__ - 1
private_constant :CS_PRIVATE
end
+module ConstantSpecsThree
+ module ConstantSpecsTwo
+ Foo = :cs_three_foo
+ end
+end
+
+module ConstantSpecsTwo
+ Foo = :cs_two_foo
+end
+
include ConstantSpecs::ModuleA
diff --git a/spec/ruby/fixtures/enumerator/classes.rb b/spec/ruby/fixtures/enumerator/classes.rb
deleted file mode 100644
index 6f285b8efa..0000000000
--- a/spec/ruby/fixtures/enumerator/classes.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-module EnumSpecs
- class Numerous
-
- include Enumerable
-
- def initialize(*list)
- @list = list.empty? ? [2, 5, 3, 6, 1, 4] : list
- end
-
- def each
- @list.each { |i| yield i }
- end
- end
-
-end
diff --git a/spec/ruby/fixtures/io.rb b/spec/ruby/fixtures/io.rb
new file mode 100644
index 0000000000..87ebbbb2bd
--- /dev/null
+++ b/spec/ruby/fixtures/io.rb
@@ -0,0 +1,12 @@
+module IOSpec
+ def self.exhaust_write_buffer(io)
+ written = 0
+ buf = " " * 4096
+
+ while true
+ written += io.write_nonblock(buf)
+ end
+ rescue Errno::EAGAIN, Errno::EWOULDBLOCK
+ written
+ end
+end
diff --git a/spec/ruby/fixtures/math/common.rb b/spec/ruby/fixtures/math/common.rb
deleted file mode 100644
index 024732fa7a..0000000000
--- a/spec/ruby/fixtures/math/common.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-class IncludesMath
- include Math
-end
diff --git a/spec/ruby/fixtures/rational.rb b/spec/ruby/fixtures/rational.rb
deleted file mode 100644
index 844d7f9820..0000000000
--- a/spec/ruby/fixtures/rational.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-module RationalSpecs
- class SubNumeric < Numeric
- def initialize(value)
- @value = Rational(value)
- end
-
- def to_r
- @value
- end
- end
-
- class CoerceError < StandardError
- end
-end