Skip to content

Commit a0ba0cc

Browse files
committed
tests: Add a test to show contracts in parallel execution
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>
1 parent a441e15 commit a0ba0cc

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

tests/contracts_threaded.nit

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# This file is part of NIT ( http://www.nitlanguage.org ).
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# This test shows the verification of contracts in a parallel execution.
16+
17+
import pthreads
18+
19+
fun foo is
20+
threaded
21+
expect(contract_foo)
22+
do
23+
print "Foo"
24+
bar("Foo thread")
25+
end
26+
27+
fun bar(thread_name: String)
28+
is
29+
threaded
30+
expect(contract_bar(thread_name))
31+
do
32+
sys.nanosleep(3,0)
33+
print "Bar called from {thread_name}"
34+
end
35+
36+
fun contract_foo: Bool
37+
do
38+
sys.nanosleep(1,0)
39+
print("Foo contract")
40+
return true
41+
end
42+
43+
fun contract_bar(thread_name: String): Bool
44+
do
45+
sys.nanosleep(2,0)
46+
print("Bar contract called from {thread_name}")
47+
sys.nanosleep(1,0)
48+
return true
49+
end
50+
51+
52+
foo
53+
bar("Main thread")
54+
sys.nanosleep(5,0)

tests/sav/contracts_threaded.res

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Foo contract
2+
Foo
3+
Bar contract called from Foo thread
4+
Bar contract called from Main thread
5+
Bar called from Foo thread
6+
Bar called from Main thread

0 commit comments

Comments
 (0)