parent
51737a3001
commit
7c150c5bc8
@ -1,3 +1,4 @@
|
||||
/contracts-0.14.0.gem
|
||||
/contracts-0.15.0.gem
|
||||
/contracts-0.16.0.gem
|
||||
/contracts-0.16.1.gem
|
||||
|
@ -1,102 +0,0 @@
|
||||
From 726e28c473b8d4453b4485922a2c52e9511bfc42 Mon Sep 17 00:00:00 2001
|
||||
From: Chris Seaton <chris@chrisseaton.com>
|
||||
Date: Fri, 10 Nov 2017 17:20:38 +0000
|
||||
Subject: [PATCH 1/5] Don't use exceptions for control flow
|
||||
|
||||
---
|
||||
lib/contracts/call_with.rb | 22 +++++++++++++--------
|
||||
lib/contracts/method_handler.rb | 34 +++++++++++++--------------------
|
||||
2 files changed, 27 insertions(+), 29 deletions(-)
|
||||
|
||||
diff --git a/lib/contracts/call_with.rb b/lib/contracts/call_with.rb
|
||||
index c8a8b62..2735d1e 100644
|
||||
--- a/lib/contracts/call_with.rb
|
||||
+++ b/lib/contracts/call_with.rb
|
||||
@@ -1,6 +1,10 @@
|
||||
module Contracts
|
||||
module CallWith
|
||||
def call_with(this, *args, &blk)
|
||||
+ call_with_inner(false, this, *args, &blk)
|
||||
+ end
|
||||
+
|
||||
+ def call_with_inner(returns, this, *args, &blk)
|
||||
args << blk if blk
|
||||
|
||||
# Explicitly append blk=nil if nil != Proc contract violation anticipated
|
||||
@@ -16,14 +20,16 @@ module Contracts
|
||||
validator = @args_validators[i]
|
||||
|
||||
unless validator && validator[arg]
|
||||
- return unless Contract.failure_callback(:arg => arg,
|
||||
- :contract => contract,
|
||||
- :class => klass,
|
||||
- :method => method,
|
||||
- :contracts => self,
|
||||
- :arg_pos => i+1,
|
||||
- :total_args => args.size,
|
||||
- :return_value => false)
|
||||
+ data = {:arg => arg,
|
||||
+ :contract => contract,
|
||||
+ :class => klass,
|
||||
+ :method => method,
|
||||
+ :contracts => self,
|
||||
+ :arg_pos => i+1,
|
||||
+ :total_args => args.size,
|
||||
+ :return_value => false}
|
||||
+ return ParamContractError.new("as return value", data) if returns
|
||||
+ return unless Contract.failure_callback(data)
|
||||
end
|
||||
|
||||
if contract.is_a?(Contracts::Func) && blk && !nil_block_appended
|
||||
diff --git a/lib/contracts/method_handler.rb b/lib/contracts/method_handler.rb
|
||||
index ee16b6b..fe301cd 100644
|
||||
--- a/lib/contracts/method_handler.rb
|
||||
+++ b/lib/contracts/method_handler.rb
|
||||
@@ -125,31 +125,23 @@ module Contracts
|
||||
# function. Otherwise we return the result.
|
||||
# If we run out of functions, we raise the last error, but
|
||||
# convert it to_contract_error.
|
||||
- success = false
|
||||
- i = 0
|
||||
- result = nil
|
||||
+
|
||||
expected_error = decorated_methods[0].failure_exception
|
||||
+ last_error = nil
|
||||
|
||||
- until success
|
||||
- decorated_method = decorated_methods[i]
|
||||
- i += 1
|
||||
- begin
|
||||
- success = true
|
||||
- result = decorated_method.call_with(self, *args, &blk)
|
||||
- rescue expected_error => error
|
||||
- success = false
|
||||
- unless decorated_methods[i]
|
||||
- begin
|
||||
- ::Contract.failure_callback(error.data, false)
|
||||
- rescue expected_error => final_error
|
||||
- raise final_error.to_contract_error
|
||||
- end
|
||||
- end
|
||||
- end
|
||||
+ decorated_methods.each do |decorated_method|
|
||||
+ result = decorated_method.call_with_inner(true, self, *args, &blk)
|
||||
+ return result unless result.is_a?(ParamContractError)
|
||||
+ last_error = result
|
||||
end
|
||||
|
||||
- # Return the result of successfully called method
|
||||
- result
|
||||
+ begin
|
||||
+ if ::Contract.failure_callback(last_error.data, false)
|
||||
+ decorated_methods.last.call_with_inner(false, self, *args, &blk)
|
||||
+ end
|
||||
+ rescue expected_error => final_error
|
||||
+ raise final_error.to_contract_error
|
||||
+ end
|
||||
end
|
||||
end
|
||||
|
||||
--
|
||||
2.29.2
|
||||
|
@ -1,73 +0,0 @@
|
||||
From 85c6a4e471f2013079dc5a63c1a6bb84bee9351b Mon Sep 17 00:00:00 2001
|
||||
From: PikachuEXE <pikachuexe@gmail.com>
|
||||
Date: Mon, 25 Jan 2021 17:26:45 +0800
|
||||
Subject: [PATCH 2/5] * Update spec to specify error class to suppress RSpec
|
||||
warning
|
||||
|
||||
---
|
||||
spec/contracts_spec.rb | 6 +++---
|
||||
spec/methods_spec.rb | 8 ++++----
|
||||
2 files changed, 7 insertions(+), 7 deletions(-)
|
||||
|
||||
diff --git a/spec/contracts_spec.rb b/spec/contracts_spec.rb
|
||||
index d37c40e..72c8603 100644
|
||||
--- a/spec/contracts_spec.rb
|
||||
+++ b/spec/contracts_spec.rb
|
||||
@@ -7,7 +7,7 @@ RSpec.describe "Contracts:" do
|
||||
it "should fail for insufficient arguments" do
|
||||
expect do
|
||||
@o.hello
|
||||
- end.to raise_error
|
||||
+ end.to raise_error ArgumentError
|
||||
end
|
||||
|
||||
it "should fail for insufficient contracts" do
|
||||
@@ -32,7 +32,7 @@ RSpec.describe "Contracts:" do
|
||||
1
|
||||
end
|
||||
end
|
||||
- end.to raise_error
|
||||
+ end.to raise_error NameError
|
||||
end
|
||||
end
|
||||
|
||||
@@ -696,7 +696,7 @@ RSpec.describe "Contracts:" do
|
||||
it "should apply the contract to an inherited method" do
|
||||
c = Child.new
|
||||
expect { c.double(2) }.to_not raise_error
|
||||
- expect { c.double("asd") }.to raise_error
|
||||
+ expect { c.double("asd") }.to raise_error ParamContractError
|
||||
end
|
||||
end
|
||||
|
||||
diff --git a/spec/methods_spec.rb b/spec/methods_spec.rb
|
||||
index 334fb4e..d1b5d47 100644
|
||||
--- a/spec/methods_spec.rb
|
||||
+++ b/spec/methods_spec.rb
|
||||
@@ -36,19 +36,19 @@ RSpec.describe "Contracts:" do
|
||||
end
|
||||
|
||||
it "should enforce return value inside block with no other parameter" do
|
||||
- expect { obj.foo(&:to_s) }.to raise_error
|
||||
+ expect { obj.foo(&:to_s) }.to raise_error ReturnContractError
|
||||
end
|
||||
|
||||
it "should enforce return value inside block with other parameter" do
|
||||
- expect { obj.foo2(2) { |x| x.to_s } }.to raise_error
|
||||
+ expect { obj.foo2(2) { |x| x.to_s } }.to raise_error ReturnContractError
|
||||
end
|
||||
|
||||
it "should enforce return value inside lambda with no other parameter" do
|
||||
- expect { obj.bar lambda { |x| x.to_s } }.to raise_error
|
||||
+ expect { obj.bar lambda { |x| x.to_s } }.to raise_error ReturnContractError
|
||||
end
|
||||
|
||||
it "should enforce return value inside lambda with other parameter" do
|
||||
- expect { obj.bar2(2, lambda { |x| x.to_s }) }.to raise_error
|
||||
+ expect { obj.bar2(2, lambda { |x| x.to_s }) }.to raise_error ReturnContractError
|
||||
end
|
||||
end
|
||||
end
|
||||
--
|
||||
2.29.2
|
||||
|
@ -1,40 +0,0 @@
|
||||
From 989ee11906bb2061b2618bd1d8f128162e143a79 Mon Sep 17 00:00:00 2001
|
||||
From: Olle Jonsson <olle.jonsson@gmail.com>
|
||||
Date: Sun, 24 Sep 2017 19:08:58 +0200
|
||||
Subject: [PATCH 3/5] Fix misspellings in comments
|
||||
|
||||
- found using find . | misspellings -f -
|
||||
---
|
||||
lib/contracts/call_with.rb | 2 +-
|
||||
spec/ruby_version_specific/contracts_spec_2.1.rb | 2 +-
|
||||
2 files changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/lib/contracts/call_with.rb b/lib/contracts/call_with.rb
|
||||
index 2735d1e..c9336a1 100644
|
||||
--- a/lib/contracts/call_with.rb
|
||||
+++ b/lib/contracts/call_with.rb
|
||||
@@ -80,7 +80,7 @@ module Contracts
|
||||
# proc, block, lambda, etc
|
||||
method.call(*args, &blk)
|
||||
else
|
||||
- # original method name referrence
|
||||
+ # original method name reference
|
||||
added_block = blk ? lambda { |*params| blk.call(*params) } : nil
|
||||
method.send_to(this, *args, &added_block)
|
||||
end
|
||||
diff --git a/spec/ruby_version_specific/contracts_spec_2.1.rb b/spec/ruby_version_specific/contracts_spec_2.1.rb
|
||||
index 168cfd0..36b6ede 100644
|
||||
--- a/spec/ruby_version_specific/contracts_spec_2.1.rb
|
||||
+++ b/spec/ruby_version_specific/contracts_spec_2.1.rb
|
||||
@@ -51,7 +51,7 @@ RSpec.describe "Contracts:" do
|
||||
end.to raise_error(ContractError)
|
||||
end
|
||||
|
||||
- it "should fail when passed nil to an optional argument which contract shouldnt accept nil" do
|
||||
+ it "should fail when passed nil to an optional argument which contract shouldn't accept nil" do
|
||||
expect do
|
||||
@o.complicated("a", true, :b, :c, 2.0, e: (1..5), f: nil, g: :d) do |x|
|
||||
x
|
||||
--
|
||||
2.29.2
|
||||
|
@ -1,30 +0,0 @@
|
||||
From ab30dab081c4e004812eab00a36c70e5b8e4e29b Mon Sep 17 00:00:00 2001
|
||||
From: md-work <>
|
||||
Date: Thu, 14 Dec 2017 11:37:18 +0100
|
||||
Subject: [PATCH 4/5] Wrapping &blocks only when there is a Func check. (bug
|
||||
278)
|
||||
|
||||
---
|
||||
lib/contracts/call_with.rb | 6 ++++--
|
||||
1 file changed, 4 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/lib/contracts/call_with.rb b/lib/contracts/call_with.rb
|
||||
index c9336a1..9252c79 100644
|
||||
--- a/lib/contracts/call_with.rb
|
||||
+++ b/lib/contracts/call_with.rb
|
||||
@@ -81,8 +81,10 @@ module Contracts
|
||||
method.call(*args, &blk)
|
||||
else
|
||||
# original method name reference
|
||||
- added_block = blk ? lambda { |*params| blk.call(*params) } : nil
|
||||
- method.send_to(this, *args, &added_block)
|
||||
+ # Don't reassign blk, else Travis CI shows "stack level too deep".
|
||||
+ target_blk = blk
|
||||
+ target_blk = lambda { |*params| blk.call(*params) } if blk && blk.is_a?(Contract)
|
||||
+ method.send_to(this, *args, &target_blk)
|
||||
end
|
||||
|
||||
unless @ret_validator[result]
|
||||
--
|
||||
2.29.2
|
||||
|
@ -1 +1 @@
|
||||
SHA512 (contracts-0.16.0.gem) = 27d757c3a6d25920ada1b24842a5ed8521bc8902b1840b6060c94dc17e5eecb91501439eb764fa2fec97dedc6591d2c2978630f56d4b38e7b607e9fccfb60ad7
|
||||
SHA512 (contracts-0.16.1.gem) = bc182431de9efbc6d23603c68a64eddcd3f27ea1ac8c2c9ff00840cf38d2f58ba595304127e6b43e504d3aa387559a5c1429b671dadac175d3a4ad2c02edbf6a
|
||||
|
Loading…
Reference in new issue