Skip to content

Commit a8b205d

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

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

tests/contracts_threaded.nit

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
end
25+
26+
fun bar(thread_name: String)
27+
is
28+
threaded
29+
expect(contract_bar(thread_name))
30+
do
31+
print "Bar called from {thread_name}"
32+
end
33+
34+
fun contract_foo: Bool
35+
do
36+
sys.nanosleep(3,0)
37+
print("Foo contract")
38+
return true
39+
end
40+
41+
fun contract_bar(thread_name: String): Bool
42+
do
43+
print("Bar contract called from {thread_name}")
44+
return true
45+
end
46+
47+
48+
foo
49+
bar("Main thread")
50+
sys.nanosleep(4,0)

tests/sav/contracts_threaded.res

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

0 commit comments

Comments
 (0)