Skip to content

Commit

Permalink
Created test for deferred procedure
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Hovy committed Sep 21, 2018
1 parent 8fb2418 commit 833819d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
18 changes: 16 additions & 2 deletions tests/TestTypeProcedure.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ def setUp(self):
self.testChild = SubroutineFullName('__typeprocedure_MOD_testChild')
self.callGraphChild = callGraphBuilder.buildCallGraph(self.testChild)


self.testDeferred = SubroutineFullName('__typeprocedure_MOD_testDeferred')
self.callGraphDeferred = callGraphBuilder.buildCallGraph(self.testDeferred)

self.fileExist = os.path.exists(self.srcFile)

def testAssemberFileExists(self):
Expand All @@ -70,7 +74,7 @@ def testSourceFiles(self):
self.assertIsNotNone(module)

simpleNames = set(module.getSubroutines().keys())
self.assertEqual({'test', 'dump', 'testadd', 'addint', 'testanother', 'addanother', 'testindirect', 'testgeneric', 'testchild', 'new_dump'}, simpleNames)
self.assertEqual({'test', 'third_interface', 'dump', 'testadd', 'addint', 'testanother', 'addanother', 'testindirect', 'testgeneric', 'testchild', 'testdeferred', 'new_dump'}, simpleNames)

def testCallGraphs(self):
if not self.filesExist:
Expand All @@ -82,13 +86,14 @@ def testCallGraphs(self):
self.assertEqual({'testanother', 'addanother'}, set(map(SubroutineFullName.getSimpleName, self.callGraphAnother.getAllSubroutineNames())))
self.assertEqual({'testgeneric', 'addanother'}, set(map(SubroutineFullName.getSimpleName, self.callGraphGeneric.getAllSubroutineNames())))
self.assertEqual({'testchild', 'new_dump', 'addint'}, set(map(SubroutineFullName.getSimpleName, self.callGraphChild.getAllSubroutineNames())))
#self.assertEqual({'testdeferred', 'dump'}, set(map(SubroutineFullName.getSimpleName, self.callGraphDeferred.getAllSubroutineNames())))

def testUseTraversal(self):
if not self.fileExist:
self.skipTest('Files not there')

self.assertEqual(0, len(self.useTraversal.getInterfaces()))
self.assertEqual(2, len(self.useTraversal.getTypes()))
self.assertEqual(3, len(self.useTraversal.getTypes()))

def testChildType(self):
if not self.fileExist:
Expand Down Expand Up @@ -153,6 +158,15 @@ def testChild(self):

expressions = set(map(VariableReference.getExpression, tracker.trackDerivedTypeArguments(self.callGraphChild)))
self.assertEqual({'t%ttest%second'}, expressions)

def testDeferred(self):
if not self.filesExist:
self.skipTest('Files not there')

tracker = VariableTracker(self.sourceFiles, [], [], self.useTraversal.getInterfaces(), self.useTraversal.getTypes())

expressions = set(map(VariableReference.getExpression, tracker.trackDerivedTypeArguments(self.callGraphDeferred)))
self.assertEqual(set(), expressions)


if __name__ == "__main__":
Expand Down
20 changes: 19 additions & 1 deletion tests/samples/typeprocedure/typeprocedure.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ MODULE typeprocedure

IMPLICIT NONE

TYPE :: ttest
TYPE, ABSTRACT :: atest
CONTAINS
PROCEDURE(third_interface), DEFERRED :: third
END TYPE atest

TYPE, EXTENDS(atest) :: ttest
INTEGER :: first(3)
INTEGER :: second(3)
CONTAINS
Expand All @@ -19,6 +24,11 @@ MODULE typeprocedure

CONTAINS

INTEGER FUNCTION third_interface(test, var)
CLASS(atest), INTENT(in) :: test
INTEGER, INTENT(in) :: var
END FUNCTION third_interface

INTEGER FUNCTION dump(test, var)
CLASS(ttest), INTENT(in) :: test
INTEGER, INTENT(in) :: var
Expand Down Expand Up @@ -99,4 +109,12 @@ SUBROUTINE testChild(t)

END SUBROUTINE testChild

SUBROUTINE testDeferred(a)

CLASS(atest), INTENT(in) :: a

WRITE (*,*) 'third: ', a%third(3)

END SUBROUTINE testDeferred

END MODULE typeprocedure

0 comments on commit 833819d

Please sign in to comment.