|
| 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 |