tests: adding contract testing files
authorFlorian Deljarry <deljarry.florian@gmail.com>
Sat, 27 Apr 2019 21:46:35 +0000 (17:46 -0400)
committerFlorian Deljarry <deljarry.florian@gmail.com>
Wed, 25 Sep 2019 20:43:58 +0000 (16:43 -0400)
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

39 files changed:
tests/contracts.nit [new file with mode: 0644]
tests/contracts_abstract.nit [new file with mode: 0644]
tests/contracts_add.nit [new file with mode: 0644]
tests/contracts_attributs.nit [new file with mode: 0644]
tests/contracts_constructor.nit [new file with mode: 0644]
tests/contracts_ensures.nit [new file with mode: 0644]
tests/contracts_ensures_1.nit [new file with mode: 0644]
tests/contracts_ensures_2.nit [new file with mode: 0644]
tests/contracts_ensures_3.nit [new file with mode: 0644]
tests/contracts_ensures_4.nit [new file with mode: 0644]
tests/contracts_ensures_sequence.nit [new file with mode: 0644]
tests/contracts_error.nit [new file with mode: 0644]
tests/contracts_expects.nit [new file with mode: 0644]
tests/contracts_expects_1.nit [new file with mode: 0644]
tests/contracts_expects_2.nit [new file with mode: 0644]
tests/contracts_expects_3.nit [new file with mode: 0644]
tests/contracts_inheritance.nit [new file with mode: 0644]
tests/contracts_same_contract.nit [new file with mode: 0644]
tests/sav/contracts.res [new file with mode: 0644]
tests/sav/contracts_abstract.res [new file with mode: 0644]
tests/sav/contracts_add.res [new file with mode: 0644]
tests/sav/contracts_attributs.res [new file with mode: 0644]
tests/sav/contracts_constructor.res [new file with mode: 0644]
tests/sav/contracts_ensures.res [new file with mode: 0644]
tests/sav/contracts_ensures_1.res [new file with mode: 0644]
tests/sav/contracts_ensures_2.res [new file with mode: 0644]
tests/sav/contracts_ensures_3.res [new file with mode: 0644]
tests/sav/contracts_ensures_4.res [new file with mode: 0644]
tests/sav/contracts_ensures_5.res [new file with mode: 0644]
tests/sav/contracts_ensures_sequence.res [new file with mode: 0644]
tests/sav/contracts_error.res [new file with mode: 0644]
tests/sav/contracts_expects.res [new file with mode: 0644]
tests/sav/contracts_expects_1.res [new file with mode: 0644]
tests/sav/contracts_expects_2.res [new file with mode: 0644]
tests/sav/contracts_expects_3.res [new file with mode: 0644]
tests/sav/contracts_inheritance.res [new file with mode: 0644]
tests/sav/contracts_same_contract.res [new file with mode: 0644]
tests/sav/test_toolcontext_args1.res
tests/sav/test_toolcontext_args2.res

diff --git a/tests/contracts.nit b/tests/contracts.nit
new file mode 100644 (file)
index 0000000..b804288
--- /dev/null
@@ -0,0 +1,41 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Test the creation ans the usage on simply contract, in the same time check the no modification of the parameter.
+# See the `foo` method in `Myclass` the change of x in a body method has no effect on the ensure because x is a primitive type and it's given by copy and not by reference.
+
+class MyClass
+       fun foo(x: Int)
+       is
+               expects(x == 1)
+               ensures(x > 0)
+       do
+               x = 0
+       end
+end
+
+class MyClass2
+       fun foo(bool: Bool)
+       is
+               expects(not bool)
+               ensures(not bool)
+       do
+               if bool then print "Error"
+       end
+end
+
+var first = new MyClass
+first.foo(1)
+var second = new MyClass2
+second.foo(true) #Fail
diff --git a/tests/contracts_abstract.nit b/tests/contracts_abstract.nit
new file mode 100644 (file)
index 0000000..de62490
--- /dev/null
@@ -0,0 +1,55 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Verification if it's possible to define a contract in different context (abstract class, interface and class) and it's possible to inherit it.
+
+class MyClass
+       fun foo(x: Int, y: Float)is abstract, expects(x != 10)
+end
+
+abstract class AbstractClass
+       fun bar(x: Int, y: Float)is abstract, expects(x >= 1), ensures(y == 10.0)
+end
+
+interface Interface
+       fun baz(x: Int, y: Float)is abstract, ensures(y <= 10.0, y == 42.0)
+end
+
+
+class MySubClass
+       super MyClass
+       super Interface
+       super AbstractClass
+
+       redef fun foo(x: Int, y: Float)
+       do
+               if x == 10 then print "Error"
+       end
+
+       redef fun baz(x: Int, y: Float)
+       do
+
+       end
+
+       redef fun bar(x: Int, y: Float)
+       do
+               if x < 1 then print "Error"
+       end
+end
+
+
+var first = new MySubClass
+first.foo(11,2.0) # Ok
+first.bar(1,10.0) # Ok
+first.baz(9,42.0) # Fail y > 10 (y = 42.0)
diff --git a/tests/contracts_add.nit b/tests/contracts_add.nit
new file mode 100644 (file)
index 0000000..5ab7621
--- /dev/null
@@ -0,0 +1,55 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Verification if it's possible to add a other contract type on existing method.
+# Only the expect contract display a warning when none expect contract are not defined at the introduction
+
+class MyClass
+       fun foo(x: Int)
+       is
+               expects(x == 1)
+       do
+               x=1
+       end
+
+       fun bar(x: Float): Bool
+       is
+               ensures(result)
+       do
+               return true
+       end
+end
+
+class MyClass2
+       super MyClass
+
+       redef fun foo(x: Int)
+       is
+               ensures(x == 0)
+       do
+               x=0
+       end
+
+       redef fun bar(x: Float)
+       is
+               expects(x == 1)
+       do
+               return true
+       end
+end
+
+var first = new MyClass2
+first.foo(1)
+first.bar(1.0)
+first.foo(0)# Fail because the expect is x == 1
diff --git a/tests/contracts_attributs.nit b/tests/contracts_attributs.nit
new file mode 100644 (file)
index 0000000..504f0f9
--- /dev/null
@@ -0,0 +1,52 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Verification if it's possible to define a contract with a call of an attribute and a method call
+
+class MyClass
+
+       var bar = 10
+
+       fun foo(x: Int)
+       is
+               expects(bar == 10)
+               ensures(x > 0)
+       do
+               if bar != 10 then print "Error"
+       end
+end
+
+class MyClass2
+
+       var my_class: MyClass
+
+       fun baz: Bool
+       do
+               return false
+       end
+
+       fun foo(bool: Bool)
+       is
+               expects(not self.baz)
+               ensures(my_class.bar == 11)
+       do
+               if baz then print "Error"
+               my_class.bar = 11
+       end
+end
+
+var first = new MyClass
+first.foo(1) # Ok
+var second = new MyClass2(first)
+second.foo(false) # Ok
diff --git a/tests/contracts_constructor.nit b/tests/contracts_constructor.nit
new file mode 100644 (file)
index 0000000..72eb9a9
--- /dev/null
@@ -0,0 +1,27 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Test the contract on constructor.
+
+class MyClass
+       init construct(test: Int)
+       is
+               expects(test > 10)
+       do
+
+       end
+end
+
+var first = new MyClass.construct(13)
+var second = new MyClass.construct(9)
diff --git a/tests/contracts_ensures.nit b/tests/contracts_ensures.nit
new file mode 100644 (file)
index 0000000..24a6ffc
--- /dev/null
@@ -0,0 +1,38 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Verification if it's possible to define a simple ensures contract.
+
+class MyClass
+       fun foo(x: Int)
+       is
+               ensures(x > 0)
+       do
+
+       end
+end
+
+class MyClass2
+       fun foo(bool: Bool)
+       is
+               ensures(not bool)
+       do
+
+       end
+end
+
+var first = new MyClass
+first.foo(1)
+var second = new MyClass2
+second.foo(true) #Fail because the ensure is bool == false
diff --git a/tests/contracts_ensures_1.nit b/tests/contracts_ensures_1.nit
new file mode 100644 (file)
index 0000000..be6798e
--- /dev/null
@@ -0,0 +1,38 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Verification if the contract is inherited
+
+class MyClass
+       fun foo(x: Int)
+       is
+               ensures(x > 0)
+       do
+               print "Good"
+       end
+end
+
+class SubClass
+       super MyClass
+
+       redef fun foo(x: Int) do
+               print "Fail"
+       end
+end
+
+var first = new MyClass
+first.foo(1)
+var sub = new SubClass
+# Check if the contract is inherited
+sub.foo(0) # Fail
\ No newline at end of file
diff --git a/tests/contracts_ensures_2.nit b/tests/contracts_ensures_2.nit
new file mode 100644 (file)
index 0000000..c102e33
--- /dev/null
@@ -0,0 +1,41 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Check if the expects contract is redef with `and`
+
+class MyClass
+       fun foo(x: Int, y: Float)
+       is
+               ensures(x > 0)
+       do
+               print "Good"
+       end
+end
+
+class SubClass
+       super MyClass
+
+       redef fun foo(x: Int, y: Float)
+       is
+               ensures(y == 1.2)
+       do
+               print "Good"
+       end
+end
+
+var first = new MyClass
+first.foo(1,1.2) # OK
+var sub = new SubClass
+sub.foo(1,1.2) # OK
+sub.foo(1,1.0) # Fail
\ No newline at end of file
diff --git a/tests/contracts_ensures_3.nit b/tests/contracts_ensures_3.nit
new file mode 100644 (file)
index 0000000..5557ef2
--- /dev/null
@@ -0,0 +1,28 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Check the ensures with a contract on a result (the return result of the method)
+
+class MyClass
+       fun foo(x: Int): Int
+       is
+               ensures(result > 0)
+       do
+               return x
+       end
+end
+
+var first = new MyClass
+first.foo(1) # OK
+first.foo(0) # FAIL
diff --git a/tests/contracts_ensures_4.nit b/tests/contracts_ensures_4.nit
new file mode 100644 (file)
index 0000000..d5cd82d
--- /dev/null
@@ -0,0 +1,40 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Check the result with the super call
+
+class MyClass
+       fun foo(x: Int): Bool
+       is
+               ensures(x > 0, result)
+       do
+               return true
+       end
+end
+
+class MySubClass
+       super MyClass
+
+       redef fun foo(x: Int)
+       is
+               ensures(not result)
+       do
+               return super
+       end
+end
+
+var first = new MyClass
+first.foo(1)
+var second = new MySubClass
+second.foo(2) #Fail
diff --git a/tests/contracts_ensures_sequence.nit b/tests/contracts_ensures_sequence.nit
new file mode 100644 (file)
index 0000000..ab66e57
--- /dev/null
@@ -0,0 +1,38 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+class MyClass
+       fun foo(x: Int, y: Float)
+       is
+               ensures(x > 2)
+       do
+
+       end
+end
+
+class MySubClass
+       super MyClass
+
+       redef fun foo(x: Int, y: Float)
+       is
+               ensures(y > 1.0)
+       do
+
+       end
+end
+
+var first = new MyClass
+first.foo(2, 1.1)
+var second = new MySubClass
+second.foo(1, 0.5) #Fail
diff --git a/tests/contracts_error.nit b/tests/contracts_error.nit
new file mode 100644 (file)
index 0000000..d103f58
--- /dev/null
@@ -0,0 +1,31 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Test the error if the annotation parameter is not an good expression (ie is not a comparisons or a method calls returning bouleans)
+
+class MyClass
+
+       fun bar_no_return do end
+
+       fun foo(x: Int)
+       is
+               expects(bar_no_return)
+               ensures(assert x == 1)
+       do
+               x = 0
+       end
+end
+
+var first = new MyClass
+first.foo(1)
diff --git a/tests/contracts_expects.nit b/tests/contracts_expects.nit
new file mode 100644 (file)
index 0000000..ec2f4d2
--- /dev/null
@@ -0,0 +1,38 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Verification if it's possible to define a simple expects contract.
+
+class MyClass
+       fun foo(x: Int)
+       is
+               expects(x > 0)
+       do
+               if x <= 0 then print "FAIL"
+       end
+end
+
+class MyClass2
+       fun foo(bool: Bool)
+       is
+               expects(not bool)
+       do
+               if bool then print "FAIL"
+       end
+end
+
+var first = new MyClass
+first.foo(1) # OK
+var second = new MyClass2
+second.foo(false) # OK
diff --git a/tests/contracts_expects_1.nit b/tests/contracts_expects_1.nit
new file mode 100644 (file)
index 0000000..eb923ab
--- /dev/null
@@ -0,0 +1,37 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Check if the contract is inherited
+
+class MyClass
+       fun foo(x: Int)
+       is
+               expects(x > 0)
+       do
+               if x <= 0 then print "FAIL"
+       end
+end
+
+class SubClass
+       super MyClass
+
+       redef fun foo(x: Int) do
+               if x <= 0 then print "FAIL"
+       end
+end
+
+var first = new MyClass
+first.foo(1) # OK
+var sub = new SubClass
+sub.foo(0) # Fail
diff --git a/tests/contracts_expects_2.nit b/tests/contracts_expects_2.nit
new file mode 100644 (file)
index 0000000..3af9ebb
--- /dev/null
@@ -0,0 +1,41 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Check if the expects contract is redef with `or`
+
+class MyClass
+       fun foo(x: Int)
+       is
+               expects(x > 0)
+       do
+               if x <= 0 then print "FAIL"
+       end
+end
+
+class SubClass
+       super MyClass
+
+       redef fun foo(x: Int)
+       is
+               expects(x == 0)
+       do
+               if x < 0 then print "FAIL"
+       end
+end
+
+var first = new MyClass
+first.foo(1)
+var sub = new SubClass
+sub.foo(3) # OK
+sub.foo(0) # OK
diff --git a/tests/contracts_expects_3.nit b/tests/contracts_expects_3.nit
new file mode 100644 (file)
index 0000000..63bf318
--- /dev/null
@@ -0,0 +1,49 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Check if the adding expects contract in a redefinition on an existing method return a warning
+
+class MyClass
+       fun foo(x: Int)
+       do
+               print "Good"
+       end
+end
+
+class SubClass
+       super MyClass
+
+       redef fun foo(x: Int)
+       is
+               expects(x == 0)
+       do
+               if x != 0 then print "Good"
+       end
+end
+
+class SubSubClass
+       super SubClass
+
+       redef fun foo(x: Int)
+       do
+               if x != 0 then print "Good"
+       end
+end
+
+var first = new MyClass
+first.foo(1) # OK
+var sub = new SubClass
+sub.foo(0) # OK
+var subsub = new SubSubClass
+subsub.foo(1) # Ok
diff --git a/tests/contracts_inheritance.nit b/tests/contracts_inheritance.nit
new file mode 100644 (file)
index 0000000..015d483
--- /dev/null
@@ -0,0 +1,58 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Check usage of contract on a diamond inheritance
+
+class ArrayInt
+       super Array[Int]
+
+       fun toto(e: Int)
+       do
+               print "toto ArrayInt"
+       end
+end
+
+
+class MyArrayInt
+       super ArrayInt
+
+       redef fun toto(e)
+       is
+               ensures(e == 12)
+       do
+               print "toto MyArrayInt"
+               super e
+       end
+end
+
+class MyArrayInt2
+       super ArrayInt
+
+       redef fun toto(e)
+       is
+               ensures(e == 11)
+       do
+               print "toto MyArrayInt2"
+               super e
+               print "Good"
+       end
+end
+
+class MySubArray
+       super MyArrayInt
+       super MyArrayInt2
+end
+
+var test = new MySubArray
+test.toto(11)# fail contract on MyArrayInt define e == 12
diff --git a/tests/contracts_same_contract.nit b/tests/contracts_same_contract.nit
new file mode 100644 (file)
index 0000000..a34005f
--- /dev/null
@@ -0,0 +1,29 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Test when to same contracts are use in a same method definition
+
+class MyClass
+
+       fun foo(x: Int)
+       is
+               expects(x == 10)
+               expects(x >= 10)
+       do
+               x = 0
+       end
+end
+
+var first = new MyClass
+first.foo(10)
diff --git a/tests/sav/contracts.res b/tests/sav/contracts.res
new file mode 100644 (file)
index 0000000..6be0568
--- /dev/null
@@ -0,0 +1 @@
+Runtime error: Assert 'expects' failed (contracts.nit:31)
diff --git a/tests/sav/contracts_abstract.res b/tests/sav/contracts_abstract.res
new file mode 100644 (file)
index 0000000..b69a60e
--- /dev/null
@@ -0,0 +1 @@
+Runtime error: Assert 'ensures' failed (contracts_abstract.nit:26)
diff --git a/tests/sav/contracts_add.res b/tests/sav/contracts_add.res
new file mode 100644 (file)
index 0000000..f74e59a
--- /dev/null
@@ -0,0 +1,2 @@
+contracts_add.nit:46,3--17: Useless contract: No contract defined at the introduction of the method
+Runtime error: Assert 'ensures' failed (contracts_add.nit:39)
diff --git a/tests/sav/contracts_attributs.res b/tests/sav/contracts_attributs.res
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/sav/contracts_constructor.res b/tests/sav/contracts_constructor.res
new file mode 100644 (file)
index 0000000..180b9c7
--- /dev/null
@@ -0,0 +1 @@
+Runtime error: Assert 'expects' failed (contracts_constructor.nit:20)
diff --git a/tests/sav/contracts_ensures.res b/tests/sav/contracts_ensures.res
new file mode 100644 (file)
index 0000000..b710ec9
--- /dev/null
@@ -0,0 +1 @@
+Runtime error: Assert 'ensures' failed (contracts_ensures.nit:29)
diff --git a/tests/sav/contracts_ensures_1.res b/tests/sav/contracts_ensures_1.res
new file mode 100644 (file)
index 0000000..99f2817
--- /dev/null
@@ -0,0 +1,3 @@
+Runtime error: Assert 'ensures' failed (contracts_ensures_1.nit:20)
+Good
+Fail
diff --git a/tests/sav/contracts_ensures_2.res b/tests/sav/contracts_ensures_2.res
new file mode 100644 (file)
index 0000000..a778c12
--- /dev/null
@@ -0,0 +1,4 @@
+Runtime error: Assert 'ensures' failed (contracts_ensures_2.nit:31)
+Good
+Good
+Good
diff --git a/tests/sav/contracts_ensures_3.res b/tests/sav/contracts_ensures_3.res
new file mode 100644 (file)
index 0000000..8bf6416
--- /dev/null
@@ -0,0 +1 @@
+Runtime error: Assert 'ensures' failed (contracts_ensures_3.nit:20)
diff --git a/tests/sav/contracts_ensures_4.res b/tests/sav/contracts_ensures_4.res
new file mode 100644 (file)
index 0000000..c0a39ad
--- /dev/null
@@ -0,0 +1 @@
+Runtime error: Assert 'ensures' failed (contracts_ensures_4.nit:31)
diff --git a/tests/sav/contracts_ensures_5.res b/tests/sav/contracts_ensures_5.res
new file mode 100644 (file)
index 0000000..fedb42c
--- /dev/null
@@ -0,0 +1 @@
+Runtime error: Assert 'ensures' failed (contracts_ensures_5.nit:29)
diff --git a/tests/sav/contracts_ensures_sequence.res b/tests/sav/contracts_ensures_sequence.res
new file mode 100644 (file)
index 0000000..e462610
--- /dev/null
@@ -0,0 +1 @@
+Runtime error: Assert 'ensures' failed (contracts_ensures_sequence.nit:18)
diff --git a/tests/sav/contracts_error.res b/tests/sav/contracts_error.res
new file mode 100644 (file)
index 0000000..560ce7a
--- /dev/null
@@ -0,0 +1,2 @@
+contracts_error.nit:23,11--23: Error: expected an expression.
+contracts_error.nit:24,11--23: Error: expected an expression.
diff --git a/tests/sav/contracts_expects.res b/tests/sav/contracts_expects.res
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/sav/contracts_expects_1.res b/tests/sav/contracts_expects_1.res
new file mode 100644 (file)
index 0000000..1cfc3f6
--- /dev/null
@@ -0,0 +1 @@
+Runtime error: Assert 'expects' failed (contracts_expects_1.nit:20)
diff --git a/tests/sav/contracts_expects_2.res b/tests/sav/contracts_expects_2.res
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/sav/contracts_expects_3.res b/tests/sav/contracts_expects_3.res
new file mode 100644 (file)
index 0000000..622d67c
--- /dev/null
@@ -0,0 +1,3 @@
+contracts_expects_3.nit:29,3--17: Useless contract: No contract defined at the introduction of the method
+Good
+Good
diff --git a/tests/sav/contracts_inheritance.res b/tests/sav/contracts_inheritance.res
new file mode 100644 (file)
index 0000000..65c6bf5
--- /dev/null
@@ -0,0 +1,6 @@
+contracts_inheritance.nit:58,6--9: Warning: conflicting property definitions for property `toto` in `MySubArray`: contracts_inheritance$MyArrayInt$toto contracts_inheritance$MyArrayInt2$toto
+Runtime error: Assert 'ensures' failed (contracts_inheritance.nit:32)
+toto MyArrayInt2
+toto MyArrayInt
+toto ArrayInt
+Good
diff --git a/tests/sav/contracts_same_contract.res b/tests/sav/contracts_same_contract.res
new file mode 100644 (file)
index 0000000..cf99218
--- /dev/null
@@ -0,0 +1 @@
+contracts_same_contract.nit:22,3--18: The method already has a defined `expects` contract at line 21
index ad80c05..a04e1b8 100644 (file)
@@ -5,7 +5,7 @@ _DUMMY_TOOL()
        COMPREPLY=()
        cur="${COMP_WORDS[COMP_CWORD]}"
        prev="${COMP_WORDS[COMP_CWORD-1]}"
-       opts="--warn --warning --quiet --stop-on-first-error --keep-going --no-color --log --log-dir --nit-dir --help --version --set-dummy-tool --verbose --bash-completion --stub-man --option-a --option-b"
+       opts="--warn --warning --quiet --stop-on-first-error --keep-going --no-color --log --log-dir --nit-dir --help --version --set-dummy-tool --verbose --bash-completion --stub-man --no-contract --full-contract --option-a --option-b"
        if [[ ${cur} == -* ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
                return 0
index f7e7da5..9d4104e 100644 (file)
@@ -12,6 +12,8 @@ Test for ToolContext, try --bash-completion.
   -h, -?, --help          Show Help (This screen)
   --version               Show version and exit
   -v, --verbose           Additional messages from the tool
+  --no-contract           Disable the contracts usage
+  --full-contract         Enable all contracts usage
   -a, --option-a          option a, do nothing
   -b, --option-b          option b, do nothing
   -c                      option c, do nothing