Skip to content

Commit 33ab0e2

Browse files
committed
test: update all tests to not use deprecated features
Several methods, arguments, and behaviors were deprecated but the tests were not updated to use alternates. This caused a lot of deprecation warnings when running the tests.
1 parent 8b9b9e2 commit 33ab0e2

11 files changed

+114
-74
lines changed

tests/test_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
$stdout.sync = true
1313
$stderr.sync = true
1414

15-
# Silence deprecation warnings during tests
16-
Git::Deprecation.behavior = :silence
15+
# # Silence deprecation warnings during tests
16+
# Git::Deprecation.behavior = :silence
1717

1818
module Test
1919
module Unit

tests/units/test_base.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,23 @@ def test_commit
8888
git.add('test_file_1')
8989
git.add('test_file_2')
9090

91-
base_commit_id = git.log[0].objectish
91+
commits = git.log.execute
92+
base_commit_id = commits[0].objectish
9293

9394
git.commit('Test Commit')
9495

95-
original_commit_id = git.log[0].objectish
96+
commits = git.log.execute
97+
original_commit_id = commits[0].objectish
9698

9799
create_file('test_commit/test_file_3', 'content test_file_3')
98100

99101
git.add('test_file_3')
100102

101103
git.commit(nil, amend: true)
102104

103-
assert(git.log[0].objectish != original_commit_id)
104-
assert(git.log[1].objectish == base_commit_id)
105+
commits = git.log.execute
106+
assert(commits[0].objectish != original_commit_id)
107+
assert(commits[1].objectish == base_commit_id)
105108
end
106109
end
107110
end

tests/units/test_commit_with_empty_message.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def test_with_allow_empty_message_option
2020
Dir.mktmpdir do |dir|
2121
git = Git.init(dir)
2222
git.commit('', { allow_empty: true, allow_empty_message: true })
23-
assert_equal(1, git.log.to_a.size)
23+
commits = git.log.execute
24+
assert_equal(1, commits.to_a.size)
2425
end
2526
end
2627
end

tests/units/test_git_dir.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ def test_git_dir_outside_work_tree
6262
# * the commit was added to the log
6363
#
6464
max_log_size = 100
65-
assert_equal(64, git.log(max_log_size).size)
65+
commits = git.log(max_log_size).execute
66+
assert_equal(64, commits.size)
6667
git.add(file)
6768
git.commit('This is a new commit')
6869
assert_equal(false, git.status.changed?(file))
69-
assert_equal(65, git.log(max_log_size).size)
70+
commits = git.log(max_log_size).execute
71+
assert_equal(65, commits.size)
7072
end
7173
end
7274
end

tests/units/test_git_path.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ def setup
99
end
1010

1111
def test_initalize_with_good_path_and_check_path
12-
path = Git::Path.new(@git.index.to_s, true)
12+
path = Git::Path.new(@git.index.to_s, must_exist: true)
1313
assert_equal @git.index.to_s, path.to_s
1414
end
1515

1616
def test_initialize_with_bad_path_and_check_path
1717
assert_raises ArgumentError do
18-
Git::Path.new('/this path does not exist', true)
18+
Git::Path.new('/this path does not exist', must_exist: true)
1919
end
2020
end
2121

2222
def test_initialize_with_bad_path_and_no_check
23-
path = Git::Path.new('/this path does not exist', false)
23+
path = Git::Path.new('/this path does not exist', must_exist: false)
2424
assert path.to_s.end_with?('/this path does not exist')
2525

2626
assert(path.to_s.match(%r{^(?:[A-Z]:)?/this path does not exist$}))

tests/units/test_index_ops.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ def test_revert
9494
g.commit('second-commit')
9595
g.gcommit('HEAD')
9696

97-
commits = g.log(10_000).count
97+
commits = g.log(10_000).execute
9898
g.revert(first_commit.sha)
99-
assert_equal(commits + 1, g.log(10_000).count)
99+
commits_after_revert = g.log(10_000).execute
100+
assert_equal(commits.count + 1, commits_after_revert.count)
100101
assert(!File.exist?('test-file2'))
101102
end
102103
end

tests/units/test_log.rb

Lines changed: 72 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -11,103 +11,124 @@ def setup
1111
end
1212

1313
def test_log_max_count_default
14-
assert_equal(30, @git.log.size)
14+
# Default max_count is 30
15+
commits = @git.log.execute
16+
assert_equal(30, commits.size)
1517
end
1618

1719
# In these tests, note that @git.log(n) is equivalent to @git.log.max_count(n)
1820
def test_log_max_count_twenty
19-
assert_equal(20, @git.log(20).size)
20-
assert_equal(20, @git.log.max_count(20).size)
21+
max_count = 20
22+
commits = @git.log(max_count).execute
23+
assert_equal(20, commits.size)
24+
commits = @git.log.max_count(max_count).execute
25+
assert_equal(20, commits.size)
2126
end
2227

2328
def test_log_max_count_nil
24-
assert_equal(72, @git.log(nil).size)
25-
assert_equal(72, @git.log.max_count(nil).size)
29+
# nil should return all commits
30+
max_count = nil
31+
commits = @git.log(max_count).execute
32+
assert_equal(72, commits.size)
33+
commits = @git.log.max_count(max_count).execute
34+
assert_equal(72, commits.size)
2635
end
2736

2837
def test_log_max_count_all
29-
assert_equal(72, @git.log(:all).size)
30-
assert_equal(72, @git.log.max_count(:all).size)
38+
max_count = :all
39+
commits = @git.log(max_count).execute
40+
assert_equal(72, commits.size)
41+
commits = @git.log.max_count(max_count).execute
42+
assert_equal(72, commits.size)
3143
end
3244

3345
# Note that @git.log.all does not control the number of commits returned. For that,
3446
# use @git.log.max_count(n)
3547
def test_log_all
36-
assert_equal(72, @git.log(100).size)
37-
assert_equal(76, @git.log(100).all.size)
48+
commits = @git.log(100).execute
49+
assert_equal(72, commits.size)
50+
commits = @git.log(100).all.execute
51+
assert_equal(76, commits.size)
3852
end
3953

4054
def test_log_non_integer_count
41-
assert_raises(ArgumentError) { @git.log('foo').size }
55+
assert_raises(ArgumentError) do
56+
commits = @git.log('foo').execute
57+
commits.size
58+
end
4259
end
4360

4461
def test_get_first_and_last_entries
4562
log = @git.log
46-
assert(log.first.is_a?(Git::Object::Commit))
47-
assert_equal('46abbf07e3c564c723c7c039a43ab3a39e5d02dd', log.first.objectish)
63+
commits = log.execute
64+
assert(commits.first.is_a?(Git::Object::Commit))
65+
assert_equal('46abbf07e3c564c723c7c039a43ab3a39e5d02dd', commits.first.objectish)
4866

49-
assert(log.last.is_a?(Git::Object::Commit))
50-
assert_equal('b03003311ad3fa368b475df58390353868e13c91', log.last.objectish)
67+
assert(commits.last.is_a?(Git::Object::Commit))
68+
assert_equal('b03003311ad3fa368b475df58390353868e13c91', commits.last.objectish)
5169
end
5270

5371
def test_get_log_entries
54-
assert_equal(30, @git.log.size)
55-
assert_equal(50, @git.log(50).size)
56-
assert_equal(10, @git.log(10).size)
72+
assert_equal(30, @git.log.execute.size)
73+
assert_equal(50, @git.log(50).execute.size)
74+
assert_equal(10, @git.log(10).execute.size)
5775
end
5876

5977
def test_get_log_to_s
60-
assert_equal(@git.log.to_s.split("\n").first, @git.log.first.sha)
78+
commits = @git.log.execute
79+
first_line = commits.to_s.split("\n").first
80+
first_sha = commits.first.sha
81+
assert_equal(first_line, first_sha)
6182
end
6283

6384
def test_log_skip
64-
three1 = @git.log(3).to_a[-1]
65-
three2 = @git.log(2).skip(1).to_a[-1]
66-
three3 = @git.log(1).skip(2).to_a[-1]
85+
three1 = @git.log(3).execute.to_a[-1]
86+
three2 = @git.log(2).skip(1).execute.to_a[-1]
87+
three3 = @git.log(1).skip(2).execute.to_a[-1]
6788
assert_equal(three2.sha, three3.sha)
6889
assert_equal(three1.sha, three2.sha)
6990
end
7091

7192
def test_get_log_since
72-
l = @git.log.since('2 seconds ago')
73-
assert_equal(0, l.size)
93+
commits = @git.log.since('2 seconds ago').execute
94+
assert_equal(0, commits.size)
7495

75-
l = @git.log.since("#{Date.today.year - 2006} years ago")
76-
assert_equal(30, l.size)
96+
commits = @git.log.since("#{Date.today.year - 2006} years ago").execute
97+
assert_equal(30, commits.size)
7798
end
7899

79100
def test_get_log_grep
80-
l = @git.log.grep('search')
81-
assert_equal(2, l.size)
101+
commits = @git.log.grep('search').execute
102+
assert_equal(2, commits.size)
82103
end
83104

84105
def test_get_log_author
85-
l = @git.log(5).author('chacon')
86-
assert_equal(5, l.size)
87-
l = @git.log(5).author('lazySusan')
88-
assert_equal(0, l.size)
106+
commits = @git.log(5).author('chacon').execute
107+
assert_equal(5, commits.size)
108+
commits = @git.log(5).author('lazySusan').execute
109+
assert_equal(0, commits.size)
89110
end
90111

91112
def test_get_log_since_file
92-
l = @git.log.path('example.txt')
93-
assert_equal(30, l.size)
113+
commits = @git.log.path('example.txt').execute
114+
assert_equal(30, commits.size)
94115

95-
l = @git.log.between('v2.5', 'test').path('example.txt')
96-
assert_equal(1, l.size)
116+
commits = @git.log.between('v2.5', 'test').path('example.txt').execute
117+
assert_equal(1, commits.size)
97118
end
98119

99120
def test_get_log_path
100-
log = @git.log.path('example.txt')
101-
assert_equal(30, log.size)
102-
log = @git.log.path('example*')
103-
assert_equal(30, log.size)
104-
log = @git.log.path(['example.txt', 'scott/text.txt'])
105-
assert_equal(30, log.size)
121+
commits = @git.log.path('example.txt').execute
122+
assert_equal(30, commits.size)
123+
commits = @git.log.path('example*').execute
124+
assert_equal(30, commits.size)
125+
commits = @git.log.path(['example.txt', 'scott/text.txt']).execute
126+
assert_equal(30, commits.size)
106127
end
107128

108129
def test_log_file_noexist
109130
assert_raise Git::FailedError do
110-
@git.log.object('no-exist.txt').size
131+
@git.log.object('no-exist.txt').execute
111132
end
112133
end
113134

@@ -117,20 +138,22 @@ def test_log_with_empty_commit_message
117138
expected_message = 'message'
118139
git.commit(expected_message, { allow_empty: true })
119140
git.commit('', { allow_empty: true, allow_empty_message: true })
120-
log = git.log
121-
assert_equal(2, log.to_a.size)
122-
assert_equal('', log[0].message)
123-
assert_equal(expected_message, log[1].message)
141+
commits = git.log.execute
142+
assert_equal(2, commits.size)
143+
assert_equal('', commits[0].message)
144+
assert_equal(expected_message, commits[1].message)
124145
end
125146
end
126147

127148
def test_log_cherry
128-
l = @git.log.between('master', 'cherry').cherry
129-
assert_equal(1, l.size)
149+
commits = @git.log.between('master', 'cherry').cherry.execute
150+
assert_equal(1, commits.size)
130151
end
131152

132153
def test_log_merges
133154
expected_command_line = ['log', '--no-color', '--max-count=30', '--pretty=raw', '--merges', { chdir: nil }]
134-
assert_command_line_eq(expected_command_line) { |git| git.log.merges.size }
155+
assert_command_line_eq(expected_command_line) do |git|
156+
git.log.merges.execute
157+
end
135158
end
136159
end

tests/units/test_merge.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ def test_no_ff_merge
9494
g.branch('new_branch2').checkout
9595
g.merge('new_branch', 'merge commit message') # ff merge
9696
assert(g.status['new_file_1']) # file has been merged in
97-
assert_equal('first commit message', g.log.first.message) # merge commit message was ignored
97+
commits = g.log.execute
98+
assert_equal('first commit message', commits.first.message) # merge commit message was ignored
9899

99100
g.branch('new_branch').in_branch('second commit message') do
100101
new_file('new_file_2', 'hello')
@@ -105,7 +106,8 @@ def test_no_ff_merge
105106
assert_equal('new_branch2', g.current_branch) # still in new_branch2 branch
106107
g.merge('new_branch', 'merge commit message', no_ff: true) # no-ff merge
107108
assert(g.status['new_file_2']) # file has been merged in
108-
assert_equal('merge commit message', g.log.first.message)
109+
commits = g.log.execute
110+
assert_equal('merge commit message', commits.first.message)
109111
end
110112
end
111113

tests/units/test_pull.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ class TestPull < Test::Unit::TestCase
4444

4545
Dir.chdir('local') do
4646
git = Git.open('.')
47-
assert_equal(1, git.log.size)
47+
commits = git.log.execute
48+
assert_equal(1, commits.size)
4849
assert_nothing_raised { git.pull }
49-
assert_equal(2, git.log.size)
50+
commits = git.log.execute
51+
assert_equal(2, commits.size)
5052
end
5153
end
5254
end
@@ -72,9 +74,11 @@ class TestPull < Test::Unit::TestCase
7274

7375
Dir.chdir('local') do
7476
git = Git.open('.')
75-
assert_equal(1, git.log.size)
77+
commits = git.log.execute
78+
assert_equal(1, commits.size)
7679
assert_nothing_raised { git.pull('origin') }
77-
assert_equal(2, git.log.size)
80+
commits = git.log.execute
81+
assert_equal(2, commits.size)
7882
end
7983
end
8084
end
@@ -104,9 +108,11 @@ class TestPull < Test::Unit::TestCase
104108

105109
Dir.chdir('local') do
106110
git = Git.open('.')
107-
assert_equal(1, git.log.size)
111+
commits = git.log.execute
112+
assert_equal(1, commits.size)
108113
assert_nothing_raised { git.pull('origin', 'feature1') }
109-
assert_equal(3, git.log.size)
114+
commits = git.log.execute
115+
assert_equal(3, commits.size)
110116
end
111117
end
112118
end

tests/units/test_remotes.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,14 @@ def test_fetch_ref_adds_ref_option
177177
new_file('test-file1', 'gonnaCommitYou')
178178
rem.add
179179
rem.commit('master commit 1')
180-
first_commit_sha = rem.log.first.sha
180+
commits = rem.log.execute
181+
first_commit_sha = commits.first.sha
181182

182183
new_file('test-file2', 'gonnaCommitYouToo')
183184
rem.add
184185
rem.commit('master commit 2')
185-
second_commit_sha = rem.log.first.sha
186+
commits = rem.log.execute
187+
second_commit_sha = commits.first.sha
186188
end
187189

188190
loc.chdir do

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy