Skip to content

Commit

Permalink
tests: Add a test to show contracts in parallel execution
Browse files Browse the repository at this point in the history
Signed-off-by: Delja <[email protected]>
  • Loading branch information
Delja committed Aug 15, 2020
1 parent 3992521 commit a8b205d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/contracts_threaded.nit
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 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.

# This test shows the verification of contracts in a parallel execution.

import pthreads

fun foo is
threaded
expect(contract_foo)
do
print "Foo"
end

fun bar(thread_name: String)
is
threaded
expect(contract_bar(thread_name))
do
print "Bar called from {thread_name}"
end

fun contract_foo: Bool
do
sys.nanosleep(3,0)
print("Foo contract")
return true
end

fun contract_bar(thread_name: String): Bool
do
print("Bar contract called from {thread_name}")
return true
end


foo
bar("Main thread")
sys.nanosleep(4,0)
4 changes: 4 additions & 0 deletions tests/sav/contracts_threaded.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Foo contract
Foo
Bar contract called from Main thread
Bar called from Main thread

0 comments on commit a8b205d

Please sign in to comment.