Skip to content

Commit 95cf2ba

Browse files
andrykonchineregon
authored andcommitted
Remove version guards for 3.1
1 parent ec960f2 commit 95cf2ba

File tree

12 files changed

+73
-177
lines changed

12 files changed

+73
-177
lines changed

core/dir/fixtures/common.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,7 @@ def self.expected_paths
192192
]
193193
end
194194

195-
if RUBY_VERSION > '3.1'
196-
def self.expected_glob_paths
197-
expected_paths - ['..']
198-
end
199-
else
200-
def self.expected_glob_paths
201-
expected_paths
202-
end
195+
def self.expected_glob_paths
196+
expected_paths - ['..']
203197
end
204198
end

core/marshal/shared/load.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
end
140140
end
141141

142-
ruby_bug "#19427", "3.1"..."3.3" do
142+
ruby_bug "#19427", ""..."3.3" do
143143
it "returns frozen object having #_dump method" do
144144
object = Marshal.send(@method, Marshal.dump(UserDefined.new), freeze: true)
145145
object.should.frozen?

core/time/now_spec.rb

Lines changed: 70 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -84,99 +84,97 @@
8484
end
8585
end
8686

87-
ruby_version_is '3.1' do # https://bugs.ruby-lang.org/issues/17485
88-
describe "Timezone object" do
89-
it "raises TypeError if timezone does not implement #utc_to_local method" do
87+
describe "Timezone object" do # https://bugs.ruby-lang.org/issues/17485
88+
it "raises TypeError if timezone does not implement #utc_to_local method" do
89+
zone = Object.new
90+
def zone.local_to_utc(time)
91+
time
92+
end
93+
94+
-> {
95+
Time.now(in: zone)
96+
}.should raise_error(TypeError, /can't convert Object into an exact number/)
97+
end
98+
99+
it "does not raise exception if timezone does not implement #local_to_utc method" do
100+
zone = Object.new
101+
def zone.utc_to_local(time)
102+
time
103+
end
104+
105+
Time.now(in: zone).should be_kind_of(Time)
106+
end
107+
108+
# The result also should be a Time or Time-like object (not necessary to be the same class)
109+
# or Integer. The zone of the result is just ignored.
110+
describe "returned value by #utc_to_local and #local_to_utc methods" do
111+
it "could be Time instance" do
90112
zone = Object.new
91-
def zone.local_to_utc(time)
92-
time
113+
def zone.utc_to_local(t)
114+
time = Time.new(t.year, t.mon, t.day, t.hour, t.min, t.sec, t.utc_offset)
115+
time + 60 * 60 # + 1 hour
93116
end
94117

95-
-> {
96-
Time.now(in: zone)
97-
}.should raise_error(TypeError, /can't convert Object into an exact number/)
118+
Time.now(in: zone).should be_kind_of(Time)
119+
Time.now(in: zone).utc_offset.should == 3600
98120
end
99121

100-
it "does not raise exception if timezone does not implement #local_to_utc method" do
122+
it "could be Time subclass instance" do
101123
zone = Object.new
102-
def zone.utc_to_local(time)
103-
time
124+
def zone.utc_to_local(t)
125+
time = Time.new(t.year, t.mon, t.day, t.hour, t.min, t.sec, t.utc_offset)
126+
time += 60 * 60 # + 1 hour
127+
128+
Class.new(Time).new(time.year, time.mon, time.day, time.hour, time.min, time.sec, time.utc_offset)
104129
end
105130

106131
Time.now(in: zone).should be_kind_of(Time)
132+
Time.now(in: zone).utc_offset.should == 3600
107133
end
108134

109-
# The result also should be a Time or Time-like object (not necessary to be the same class)
110-
# or Integer. The zone of the result is just ignored.
111-
describe "returned value by #utc_to_local and #local_to_utc methods" do
112-
it "could be Time instance" do
113-
zone = Object.new
114-
def zone.utc_to_local(t)
115-
time = Time.new(t.year, t.mon, t.day, t.hour, t.min, t.sec, t.utc_offset)
116-
time + 60 * 60 # + 1 hour
117-
end
118-
119-
Time.now(in: zone).should be_kind_of(Time)
120-
Time.now(in: zone).utc_offset.should == 3600
135+
it "could be Integer" do
136+
zone = Object.new
137+
def zone.utc_to_local(time)
138+
time.to_i + 60*60
121139
end
122140

123-
it "could be Time subclass instance" do
124-
zone = Object.new
125-
def zone.utc_to_local(t)
126-
time = Time.new(t.year, t.mon, t.day, t.hour, t.min, t.sec, t.utc_offset)
127-
time += 60 * 60 # + 1 hour
128-
129-
Class.new(Time).new(time.year, time.mon, time.day, time.hour, time.min, time.sec, time.utc_offset)
130-
end
141+
Time.now(in: zone).should be_kind_of(Time)
142+
Time.now(in: zone).utc_offset.should == 60*60
143+
end
131144

132-
Time.now(in: zone).should be_kind_of(Time)
133-
Time.now(in: zone).utc_offset.should == 3600
145+
it "could have any #zone and #utc_offset because they are ignored" do
146+
zone = Object.new
147+
def zone.utc_to_local(t)
148+
Struct.new(:year, :mon, :mday, :hour, :min, :sec, :isdst, :to_i, :zone, :utc_offset) # rubocop:disable Lint/StructNewOverride
149+
.new(t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.isdst, t.to_i, 'America/New_York', -5*60*60)
134150
end
151+
Time.now(in: zone).utc_offset.should == 0
135152

136-
it "could be Integer" do
137-
zone = Object.new
138-
def zone.utc_to_local(time)
139-
time.to_i + 60*60
140-
end
141-
142-
Time.now(in: zone).should be_kind_of(Time)
143-
Time.now(in: zone).utc_offset.should == 60*60
153+
zone = Object.new
154+
def zone.utc_to_local(t)
155+
Struct.new(:year, :mon, :mday, :hour, :min, :sec, :isdst, :to_i, :zone, :utc_offset) # rubocop:disable Lint/StructNewOverride
156+
.new(t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.isdst, t.to_i, 'Asia/Tokyo', 9*60*60)
144157
end
158+
Time.now(in: zone).utc_offset.should == 0
145159

146-
it "could have any #zone and #utc_offset because they are ignored" do
147-
zone = Object.new
148-
def zone.utc_to_local(t)
149-
Struct.new(:year, :mon, :mday, :hour, :min, :sec, :isdst, :to_i, :zone, :utc_offset) # rubocop:disable Lint/StructNewOverride
150-
.new(t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.isdst, t.to_i, 'America/New_York', -5*60*60)
151-
end
152-
Time.now(in: zone).utc_offset.should == 0
153-
154-
zone = Object.new
155-
def zone.utc_to_local(t)
156-
Struct.new(:year, :mon, :mday, :hour, :min, :sec, :isdst, :to_i, :zone, :utc_offset) # rubocop:disable Lint/StructNewOverride
157-
.new(t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.isdst, t.to_i, 'Asia/Tokyo', 9*60*60)
158-
end
159-
Time.now(in: zone).utc_offset.should == 0
160-
161-
zone = Object.new
162-
def zone.utc_to_local(t)
163-
Time.new(t.year, t.mon, t.mday, t.hour, t.min, t.sec, 9*60*60)
164-
end
165-
Time.now(in: zone).utc_offset.should == 0
160+
zone = Object.new
161+
def zone.utc_to_local(t)
162+
Time.new(t.year, t.mon, t.mday, t.hour, t.min, t.sec, 9*60*60)
166163
end
164+
Time.now(in: zone).utc_offset.should == 0
165+
end
167166

168-
it "raises ArgumentError if difference between argument and result is too large" do
169-
zone = Object.new
170-
def zone.utc_to_local(t)
171-
time = Time.utc(t.year, t.mon, t.day, t.hour, t.min, t.sec, t.utc_offset)
172-
time -= 24 * 60 * 60 # - 1 day
173-
Time.utc(time.year, time.mon, time.day, time.hour, time.min, time.sec, time.utc_offset)
174-
end
175-
176-
-> {
177-
Time.now(in: zone)
178-
}.should raise_error(ArgumentError, "utc_offset out of range")
167+
it "raises ArgumentError if difference between argument and result is too large" do
168+
zone = Object.new
169+
def zone.utc_to_local(t)
170+
time = Time.utc(t.year, t.mon, t.day, t.hour, t.min, t.sec, t.utc_offset)
171+
time -= 24 * 60 * 60 # - 1 day
172+
Time.utc(time.year, time.mon, time.day, time.hour, time.min, time.sec, time.utc_offset)
179173
end
174+
175+
-> {
176+
Time.now(in: zone)
177+
}.should raise_error(ArgumentError, "utc_offset out of range")
180178
end
181179
end
182180
end

optional/capi/ext/class_spec.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,9 @@ static VALUE class_spec_rb_class_new_instance(VALUE self, VALUE args, VALUE klas
6565
return rb_class_new_instance(RARRAY_LENINT(args), RARRAY_PTR(args), klass);
6666
}
6767

68-
#ifdef RUBY_VERSION_IS_3_0
6968
static VALUE class_spec_rb_class_new_instance_kw(VALUE self, VALUE args, VALUE klass) {
7069
return rb_class_new_instance_kw(RARRAY_LENINT(args), RARRAY_PTR(args), klass, RB_PASS_KEYWORDS);
7170
}
72-
#endif
7371

7472
static VALUE class_spec_rb_class_real(VALUE self, VALUE object) {
7573
if (rb_type_p(object, T_FIXNUM)) {
@@ -160,9 +158,7 @@ void Init_class_spec(void) {
160158
rb_define_method(cls, "rb_class_private_instance_methods", class_spec_rb_class_private_instance_methods, -1);
161159
rb_define_method(cls, "rb_class_new", class_spec_rb_class_new, 1);
162160
rb_define_method(cls, "rb_class_new_instance", class_spec_rb_class_new_instance, 2);
163-
#ifdef RUBY_VERSION_IS_3_0
164161
rb_define_method(cls, "rb_class_new_instance_kw", class_spec_rb_class_new_instance_kw, 2);
165-
#endif
166162
rb_define_method(cls, "rb_class_real", class_spec_rb_class_real, 1);
167163
rb_define_method(cls, "rb_class_get_superclass", class_spec_rb_class_get_superclass, 1);
168164
rb_define_method(cls, "rb_class_superclass", class_spec_rb_class_superclass, 1);

optional/capi/ext/constants_spec.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ defconstfunc(rb_cBinding)
1414
defconstfunc(rb_cClass)
1515
defconstfunc(rb_cComplex)
1616
defconstfunc(rb_mComparable)
17-
#ifndef RUBY_VERSION_IS_3_0
18-
defconstfunc(rb_cData)
19-
#endif
2017
defconstfunc(rb_cDir)
2118
defconstfunc(rb_cEncoding)
2219
defconstfunc(rb_mEnumerable)
@@ -97,9 +94,6 @@ void Init_constants_spec(void) {
9794
rb_define_method(cls, "rb_cClass", constants_spec_rb_cClass, 0);
9895
rb_define_method(cls, "rb_cComplex", constants_spec_rb_cComplex, 0);
9996
rb_define_method(cls, "rb_mComparable", constants_spec_rb_mComparable, 0);
100-
#ifndef RUBY_VERSION_IS_3_0
101-
rb_define_method(cls, "rb_cData", constants_spec_rb_cData, 0);
102-
#endif
10397
rb_define_method(cls, "rb_cDir", constants_spec_rb_cDir, 0);
10498
rb_define_method(cls, "rb_cEncoding", constants_spec_rb_cEncoding, 0);
10599
rb_define_method(cls, "rb_mEnumerable", constants_spec_rb_mEnumerable, 0);

optional/capi/ext/fiber_spec.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,10 @@ VALUE fiber_spec_rb_fiber_new(VALUE self) {
4444
return rb_fiber_new(fiber_spec_rb_fiber_new_function, Qnil);
4545
}
4646

47-
#ifdef RUBY_VERSION_IS_3_1
4847
VALUE fiber_spec_rb_fiber_raise(int argc, VALUE *argv, VALUE self) {
4948
VALUE fiber = argv[0];
5049
return rb_fiber_raise(fiber, argc-1, argv+1);
5150
}
52-
#endif
5351

5452
void Init_fiber_spec(void) {
5553
VALUE cls = rb_define_class("CApiFiberSpecs", rb_cObject);
@@ -58,10 +56,7 @@ void Init_fiber_spec(void) {
5856
rb_define_method(cls, "rb_fiber_resume", fiber_spec_rb_fiber_resume, 2);
5957
rb_define_method(cls, "rb_fiber_yield", fiber_spec_rb_fiber_yield, 1);
6058
rb_define_method(cls, "rb_fiber_new", fiber_spec_rb_fiber_new, 0);
61-
62-
#ifdef RUBY_VERSION_IS_3_1
6359
rb_define_method(cls, "rb_fiber_raise", fiber_spec_rb_fiber_raise, -1);
64-
#endif
6560
}
6661

6762
#ifdef __cplusplus

optional/capi/ext/io_spec.c

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,7 @@ static int set_non_blocking(int fd) {
2828
}
2929

3030
static int io_spec_get_fd(VALUE io) {
31-
#ifdef RUBY_VERSION_IS_3_1
3231
return rb_io_descriptor(io);
33-
#else
34-
rb_io_t* fp;
35-
GetOpenFile(io, fp);
36-
return fp->fd;
37-
#endif
3832
}
3933

4034
VALUE io_spec_GetOpenFile_fd(VALUE self, VALUE io) {
@@ -143,11 +137,7 @@ VALUE io_spec_rb_io_wait_readable(VALUE self, VALUE io, VALUE read_p) {
143137
errno = saved_errno;
144138
}
145139

146-
#ifdef RUBY_VERSION_IS_3_1
147140
ret = rb_io_maybe_wait_readable(errno, io, Qnil);
148-
#else
149-
ret = rb_io_wait_readable(fd);
150-
#endif
151141

152142
if (RTEST(read_p)) {
153143
ssize_t r = read(fd, buf, RB_IO_WAIT_READABLE_BUF);
@@ -166,22 +156,15 @@ VALUE io_spec_rb_io_wait_readable(VALUE self, VALUE io, VALUE read_p) {
166156
}
167157

168158
VALUE io_spec_rb_io_wait_writable(VALUE self, VALUE io) {
169-
#ifdef RUBY_VERSION_IS_3_1
170159
int ret = rb_io_maybe_wait_writable(errno, io, Qnil);
171-
#else
172-
int ret = rb_io_wait_writable(io_spec_get_fd(io));
173-
#endif
174160
return ret ? Qtrue : Qfalse;
175161
}
176162

177-
#ifdef RUBY_VERSION_IS_3_1
178163
VALUE io_spec_rb_io_maybe_wait_writable(VALUE self, VALUE error, VALUE io, VALUE timeout) {
179164
int ret = rb_io_maybe_wait_writable(NUM2INT(error), io, timeout);
180165
return INT2NUM(ret);
181166
}
182-
#endif
183167

184-
#ifdef RUBY_VERSION_IS_3_1
185168
#ifdef SET_NON_BLOCKING_FAILS_ALWAYS
186169
NORETURN(VALUE io_spec_rb_io_maybe_wait_readable(VALUE self, VALUE error, VALUE io, VALUE timeout, VALUE read_p));
187170
#endif
@@ -224,37 +207,24 @@ VALUE io_spec_rb_io_maybe_wait_readable(VALUE self, VALUE error, VALUE io, VALUE
224207
UNREACHABLE_RETURN(Qnil);
225208
#endif
226209
}
227-
#endif
228210

229-
#ifdef RUBY_VERSION_IS_3_1
230211
VALUE io_spec_rb_io_maybe_wait(VALUE self, VALUE error, VALUE io, VALUE events, VALUE timeout) {
231212
return rb_io_maybe_wait(NUM2INT(error), io, events, timeout);
232213
}
233-
#endif
234214

235215
VALUE io_spec_rb_thread_wait_fd(VALUE self, VALUE io) {
236216
rb_thread_wait_fd(io_spec_get_fd(io));
237217
return Qnil;
238218
}
239219

240220
VALUE io_spec_rb_wait_for_single_fd(VALUE self, VALUE io, VALUE events, VALUE secs, VALUE usecs) {
241-
#ifdef RUBY_VERSION_IS_3_0
242221
VALUE timeout = Qnil;
243222
if (!NIL_P(secs)) {
244223
timeout = rb_float_new((double)FIX2INT(secs) + (0.000001 * FIX2INT(usecs)));
245224
}
246225
VALUE result = rb_io_wait(io, events, timeout);
247226
if (result == Qfalse) return INT2FIX(0);
248227
else return result;
249-
#else
250-
struct timeval tv;
251-
if (!NIL_P(secs)) {
252-
tv.tv_sec = FIX2INT(secs);
253-
tv.tv_usec = FIX2INT(usecs);
254-
}
255-
int fd = io_spec_get_fd(io);
256-
return INT2FIX(rb_wait_for_single_fd(fd, FIX2INT(events), NIL_P(secs) ? NULL : &tv));
257-
#endif
258228
}
259229

260230
VALUE io_spec_rb_thread_fd_writable(VALUE self, VALUE io) {
@@ -409,11 +379,9 @@ void Init_io_spec(void) {
409379
rb_define_method(cls, "rb_io_taint_check", io_spec_rb_io_taint_check, 1);
410380
rb_define_method(cls, "rb_io_wait_readable", io_spec_rb_io_wait_readable, 2);
411381
rb_define_method(cls, "rb_io_wait_writable", io_spec_rb_io_wait_writable, 1);
412-
#ifdef RUBY_VERSION_IS_3_1
413382
rb_define_method(cls, "rb_io_maybe_wait_writable", io_spec_rb_io_maybe_wait_writable, 3);
414383
rb_define_method(cls, "rb_io_maybe_wait_readable", io_spec_rb_io_maybe_wait_readable, 4);
415384
rb_define_method(cls, "rb_io_maybe_wait", io_spec_rb_io_maybe_wait, 4);
416-
#endif
417385
rb_define_method(cls, "rb_thread_wait_fd", io_spec_rb_thread_wait_fd, 1);
418386
rb_define_method(cls, "rb_thread_fd_writable", io_spec_rb_thread_fd_writable, 1);
419387
rb_define_method(cls, "rb_thread_fd_select_read", io_spec_rb_thread_fd_select_read, 1);

optional/capi/ext/kernel_spec.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,15 +351,13 @@ static VALUE kernel_spec_rb_funcallv(VALUE self, VALUE obj, VALUE method, VALUE
351351
return rb_funcallv(obj, SYM2ID(method), RARRAY_LENINT(args), RARRAY_PTR(args));
352352
}
353353

354-
#ifdef RUBY_VERSION_IS_3_0
355354
static VALUE kernel_spec_rb_funcallv_kw(VALUE self, VALUE obj, VALUE method, VALUE args) {
356355
return rb_funcallv_kw(obj, SYM2ID(method), RARRAY_LENINT(args), RARRAY_PTR(args), RB_PASS_KEYWORDS);
357356
}
358357

359358
static VALUE kernel_spec_rb_keyword_given_p(int argc, VALUE *args, VALUE self) {
360359
return rb_keyword_given_p() ? Qtrue : Qfalse;
361360
}
362-
#endif
363361

364362
static VALUE kernel_spec_rb_funcallv_public(VALUE self, VALUE obj, VALUE method) {
365363
return rb_funcallv_public(obj, SYM2ID(method), 0, NULL);
@@ -436,10 +434,8 @@ void Init_kernel_spec(void) {
436434
rb_define_method(cls, "rb_str_format", kernel_spec_rb_str_format, 3);
437435
rb_define_method(cls, "rb_make_backtrace", kernel_spec_rb_make_backtrace, 0);
438436
rb_define_method(cls, "rb_funcallv", kernel_spec_rb_funcallv, 3);
439-
#ifdef RUBY_VERSION_IS_3_0
440437
rb_define_method(cls, "rb_funcallv_kw", kernel_spec_rb_funcallv_kw, 3);
441438
rb_define_method(cls, "rb_keyword_given_p", kernel_spec_rb_keyword_given_p, -1);
442-
#endif
443439
rb_define_method(cls, "rb_funcallv_public", kernel_spec_rb_funcallv_public, 2);
444440
rb_define_method(cls, "rb_funcall_many_args", kernel_spec_rb_funcall_many_args, 2);
445441
rb_define_method(cls, "rb_funcall_with_block", kernel_spec_rb_funcall_with_block, 4);

0 commit comments

Comments
 (0)