Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita731110

Browse files
committed
fix: standardize deprecation handling and consolidate tests (fixes#842)
Replace invalid Git.deprecation/Git.deprecated calls with Git::Deprecation.warn.Consolidate all deprecation-related tests into tests/units/test_deprecations.rb.Changes:- Base: use Git::Deprecation.warn in is_* methods and set_index/set_working- Object::Commit#set_commit warns properly- Consolidated log/base/object deprecation tests into one file- Removed redundant test filesAll tests pass locally: 430 tests, 1582 assertions.
1 parent4a03b5c commita731110

File tree

5 files changed

+203
-105
lines changed

5 files changed

+203
-105
lines changed

‎lib/git/base.rb‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,10 @@ def local_branch?(branch)
286286
end
287287

288288
defis_local_branch?(branch)# rubocop:disable Naming/PredicatePrefix
289-
Git.deprecation('Git::Base#is_local_branch? is deprecated. Use Git::Base#local_branch? instead.')
289+
Git::Deprecation.warn(
290+
'Git::Base#is_local_branch? is deprecated and will be removed in a future version. ' \
291+
'Use Git::Base#local_branch? instead.'
292+
)
290293
local_branch?(branch)
291294
end
292295

@@ -297,7 +300,10 @@ def remote_branch?(branch)
297300
end
298301

299302
defis_remote_branch?(branch)# rubocop:disable Naming/PredicatePrefix
300-
Git.deprecated('Git::Base#is_remote_branch? is deprecated. Use Git::Base#remote_branch? instead.')
303+
Git::Deprecation.warn(
304+
'Git::Base#is_remote_branch? is deprecated and will be removed in a future version. ' \
305+
'Use Git::Base#remote_branch? instead.'
306+
)
301307
remote_branch?(branch)
302308
end
303309

@@ -308,7 +314,10 @@ def branch?(branch)
308314
end
309315

310316
defis_branch?(branch)# rubocop:disable Naming/PredicatePrefix
311-
Git.deprecated('Git::Base#is_branch? is deprecated. Use Git::Base#branch? instead.')
317+
Git::Deprecation.warn(
318+
'Git::Base#is_branch? is deprecated and will be removed in a future version. ' \
319+
'Use Git::Base#branch? instead.'
320+
)
312321
branch?(branch)
313322
end
314323

‎lib/git/object.rb‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,10 @@ def diff_parent
213213
end
214214

215215
defset_commit(data)# rubocop:disable Naming/AccessorMethodName
216-
Git.deprecation('Git::Object::Commit#set_commit is deprecated. Use #from_data instead.')
216+
Git::Deprecation.warn(
217+
'Git::Object::Commit#set_commit is deprecated and will be removed in a future version. ' \
218+
'Use #from_data instead.'
219+
)
217220
from_data(data)
218221
end
219222

‎tests/units/test_deprecations.rb‎

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
# frozen_string_literal: true
2+
3+
require_relative'../test_helper'
4+
5+
# Consolidated deprecation tests to ensure all deprecated entry points emit
6+
# Git::Deprecation warnings and still behave as expected.
7+
classTestDeprecations <Test::Unit::TestCase
8+
defsetup
9+
clone_working_repo
10+
@git=Git.open(@wdir)
11+
end
12+
13+
defteardown
14+
# Cleanup handled by TestCase#git_teardown
15+
end
16+
17+
# --- Git::Base deprecations ---
18+
19+
deftest_base_is_local_branch_deprecation
20+
Git::Deprecation.expects(:warn).with(
21+
'Git::Base#is_local_branch? is deprecated and will be removed in a future version. ' \
22+
'Use Git::Base#local_branch? instead.'
23+
)
24+
25+
assert_equal(true,@git.is_local_branch?(@git.current_branch))
26+
end
27+
28+
deftest_base_is_remote_branch_deprecation
29+
Git::Deprecation.expects(:warn).with(
30+
'Git::Base#is_remote_branch? is deprecated and will be removed in a future version. ' \
31+
'Use Git::Base#remote_branch? instead.'
32+
)
33+
34+
# No remotes in fixture; method should return false
35+
assert_equal(false,@git.is_remote_branch?('origin/master'))
36+
end
37+
38+
deftest_base_is_branch_deprecation
39+
Git::Deprecation.expects(:warn).with(
40+
'Git::Base#is_branch? is deprecated and will be removed in a future version. ' \
41+
'Use Git::Base#branch? instead.'
42+
)
43+
44+
assert_equal(true,@git.is_branch?(@git.current_branch))
45+
end
46+
47+
deftest_base_set_index_check_arg_deprecation
48+
require'tempfile'
49+
tmp=Tempfile.new('index')
50+
tmp.close
51+
52+
Git::Deprecation.expects(:warn).with(
53+
'The "check" argument is deprecated and will be removed in a future version. ' \
54+
'Use "must_exist:" instead.'
55+
)
56+
57+
# Ensure must_exist is provided to avoid nil | check
58+
@git.set_index(tmp.path,false,must_exist:true)
59+
assert_instance_of(Git::Index,@git.index)
60+
ensure
61+
tmp&.unlink
62+
end
63+
64+
deftest_base_set_working_check_arg_deprecation
65+
Dir.mktmpdir('git_work')do |dir|
66+
Git::Deprecation.expects(:warn).with(
67+
'The "check" argument is deprecated and will be removed in a future version. ' \
68+
'Use "must_exist:" instead.'
69+
)
70+
71+
@git.set_working(dir,false,must_exist:true)
72+
assert_equal(dir,@git.dir.path)
73+
end
74+
end
75+
76+
# --- Git::Log deprecations ---
77+
78+
deftest_log_each_deprecation
79+
log=@git.log
80+
first_commit=@git.gcommit('HEAD')
81+
82+
Git::Deprecation.expects(:warn).with(
83+
'Calling Git::Log#each is deprecated. Call #execute and then #each on the result object.'
84+
)
85+
86+
commits=log.map{ |c|c}
87+
assert_equal(first_commit.sha,commits.first.sha)
88+
end
89+
90+
deftest_log_size_deprecation
91+
log=@git.log
92+
Git::Deprecation.expects(:warn).with(
93+
'Calling Git::Log#size is deprecated. Call #execute and then #size on the result object.'
94+
)
95+
assert_operator(log.size,:>=,1)
96+
end
97+
98+
deftest_log_to_s_deprecation
99+
log=@git.log
100+
first_commit=@git.gcommit('HEAD')
101+
102+
Git::Deprecation.expects(:warn).with(
103+
'Calling Git::Log#to_s is deprecated. Call #execute and then #to_s on the result object.'
104+
)
105+
assert_match(first_commit.sha,log.to_s)
106+
end
107+
108+
deftest_log_first_deprecation
109+
log=@git.log
110+
first_commit=@git.gcommit('HEAD')
111+
112+
Git::Deprecation.expects(:warn).with(
113+
'Calling Git::Log#first is deprecated. Call #execute and then #first on the result object.'
114+
)
115+
assert_equal(first_commit.sha,log.first.sha)
116+
end
117+
118+
deftest_log_last_deprecation
119+
log=@git.log
120+
# Determine expected last via modern API to avoid assumptions about repo history
121+
expected_last_sha=log.execute.last.sha
122+
123+
Git::Deprecation.expects(:warn).with(
124+
'Calling Git::Log#last is deprecated. Call #execute and then #last on the result object.'
125+
)
126+
assert_equal(expected_last_sha,log.last.sha)
127+
end
128+
129+
deftest_log_indexer_deprecation
130+
log=@git.log
131+
first_commit=@git.gcommit('HEAD')
132+
133+
Git::Deprecation.expects(:warn).with(
134+
'Calling Git::Log#[] is deprecated. Call #execute and then #[] on the result object.'
135+
)
136+
assert_equal(first_commit.sha,log[0].sha)
137+
end
138+
139+
# --- Git::Object deprecations ---
140+
141+
deftest_object_new_is_tag_deprecation
142+
# The `objectish` here is the tag name, as was the old pattern.
143+
tag_name='v2.8'# Present in fixtures
144+
145+
Git::Deprecation.expects(:warn).with(
146+
'Git::Object.new with is_tag argument is deprecated. Use Git::Object::Tag.new instead.'
147+
)
148+
149+
tag_object=Git::Object.new(@git,tag_name,nil,true)
150+
assert_instance_of(Git::Object::Tag,tag_object)
151+
assert(tag_object.tag?)
152+
end
153+
154+
deftest_commit_set_commit_deprecation_warns_and_delegates
155+
commit=Git::Object::Commit.new(@git,'deadbeef')
156+
157+
data={
158+
'sha'=>'deadbeef',
159+
'committer'=>{'name'=>'C','email'=>'c@example.com','date'=>Time.now},
160+
'author'=>{'name'=>'A','email'=>'a@example.com','date'=>Time.now},
161+
'tree'=>'cafebabe',
162+
'parent'=>[],
163+
'message'=>'message'
164+
}
165+
166+
Git::Deprecation.expects(:warn).with(
167+
'Git::Object::Commit#set_commit is deprecated and will be removed in a future version. ' \
168+
'Use #from_data instead.'
169+
)
170+
171+
commit.expects(:from_data).with(data)
172+
commit.set_commit(data)
173+
end
174+
175+
# --- Git::Lib deprecations ---
176+
177+
deftest_lib_warn_if_old_command_deprecation
178+
# Ensure class-level check does not short-circuit the call in this test
179+
Git::Lib.instance_variable_set(:@version_checked,nil)
180+
181+
Git::Deprecation.expects(:warn).with(
182+
'Git::Lib#warn_if_old_command is deprecated. Use meets_required_version?.'
183+
)
184+
185+
assert_equal(true,Git::Lib.warn_if_old_command(@git.lib))
186+
end
187+
end

‎tests/units/test_log_deprecations.rb‎

Lines changed: 0 additions & 82 deletions
This file was deleted.

‎tests/units/test_object_new.rb‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,4 @@ def test_new_creates_blob_object
5050
assert_instance_of(Git::Object::Blob,object,'Should create a Blob object.')
5151
assert(object.blob?,'Object#blob? should be true.')
5252
end
53-
54-
# Test that using the deprecated `is_tag` argument creates a Tag object
55-
# and issues a deprecation warning.
56-
deftest_new_with_is_tag_deprecation
57-
# Set up the mock expectation for the deprecation warning.
58-
Git::Deprecation.expects(:warn).with(
59-
'Git::Object.new with is_tag argument is deprecated. Use Git::Object::Tag.new instead.'
60-
)
61-
62-
# Action: Call the factory method with the deprecated argument.
63-
# The `objectish` here is the tag name, as was the old pattern.
64-
tag_object=Git::Object.new(@repo,'v1.0',nil,true)
65-
66-
# Verification
67-
assert_instance_of(Git::Object::Tag,tag_object,'Should create a Tag object.')
68-
assert(tag_object.tag?,'Object#tag? should be true.')
69-
assert_equal('v1.0',tag_object.name,'Tag object should have the correct name.')
70-
# Mocha automatically verifies the expectation at the end of the test.
71-
end
7253
end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp