diff options
author | Brad Richardson <everythingfunctional@protonmail.com> | 2020-10-26 17:16:44 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-26 17:16:44 -0500 |
commit | 4443986b3d5690ce4ee8bbc348834caa2040be23 (patch) | |
tree | 0553b054c43c89edab17a3d6959f7adb84648a61 /bootstrap/unit_test/SubmoduleSourceConstructionTest.hs | |
parent | e92d9c9c406aff61d404d2afe71c416ed019beb0 (diff) | |
parent | 488bdd06ab78cec3085aa86b6dbe36a98f58eb86 (diff) | |
download | fpm-4443986b3d5690ce4ee8bbc348834caa2040be23.tar.gz fpm-4443986b3d5690ce4ee8bbc348834caa2040be23.zip |
Merge pull request #213 from everythingfunctional/bootstrap_submodule_support
Bootstrap submodule support
Diffstat (limited to 'bootstrap/unit_test/SubmoduleSourceConstructionTest.hs')
-rw-r--r-- | bootstrap/unit_test/SubmoduleSourceConstructionTest.hs | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/bootstrap/unit_test/SubmoduleSourceConstructionTest.hs b/bootstrap/unit_test/SubmoduleSourceConstructionTest.hs new file mode 100644 index 0000000..d07a6ed --- /dev/null +++ b/bootstrap/unit_test/SubmoduleSourceConstructionTest.hs @@ -0,0 +1,79 @@ +module SubmoduleSourceConstructionTest + ( test + ) +where + +import BuildModel ( RawSource(..) + , Source(..) + , processRawSource + ) +import Hedge ( Result + , Test + , assertEquals + , assertThat + , fail' + , givenInput + , then' + , whenTransformed + ) +import System.FilePath ( (</>) ) + +test :: IO (Test ()) +test = return $ givenInput + "a submodule" + exampleSubmodule + [ whenTransformed + "processed to a source" + processRawSource + [ then' "it is a Submodule" checkIsSubmodule + , then' "its source file name is the same as the original" + checkSubmoduleSourceFileName + , then' + "its object file name is the 'flattened' path of the source file with '.o' appeneded" + checkSubmoduleObjectFileName + , then' "it knows what modules it uses directly" checkSubmoduleModulesUsed + , then' "it knows its parent's name" checkSubmoduleParentName + , then' "it knows its name" checkSubmoduleName + ] + ] + +exampleSubmodule :: RawSource +exampleSubmodule = RawSource submoduleSourceFileName' $ unlines + [ "submodule (some_module:parent) child" + , " use module1" + , " USE MODULE2" + , " implicit none" + , "end submodule" + ] + +submoduleSourceFileName' :: String +submoduleSourceFileName' = "some" </> "file" </> "somewhere.f90" + +checkIsSubmodule :: Source -> Result +checkIsSubmodule Submodule{} = assertThat True +checkIsSubmodule _ = assertThat False + +checkSubmoduleSourceFileName :: Source -> Result +checkSubmoduleSourceFileName s@(Submodule{}) = + assertEquals submoduleSourceFileName' $ submoduleSourceFileName s +checkSubmoduleSourceFileName _ = fail' "wasn't a Submodule" + +checkSubmoduleObjectFileName :: Source -> Result +checkSubmoduleObjectFileName s@(Submodule{}) = + assertEquals ("." </> "some_file_somewhere.f90.o") + $ (submoduleObjectFileName s) "." +checkSubmoduleObjectFileName _ = fail' "wasn't a Submodule" + +checkSubmoduleModulesUsed :: Source -> Result +checkSubmoduleModulesUsed s@(Submodule{}) = + assertEquals ["module1", "module2"] $ submoduleModulesUsed s +checkSubmoduleModulesUsed _ = fail' "wasn't a Submodule" + +checkSubmoduleParentName :: Source -> Result +checkSubmoduleParentName s@(Submodule{}) = + assertEquals "some_module@parent" (submoduleParentName s) +checkSubmoduleParentName _ = fail' "wasn't a Submodule" + +checkSubmoduleName :: Source -> Result +checkSubmoduleName s@(Submodule{}) = assertEquals "child" $ submoduleName s +checkSubmoduleName _ = fail' "wasn't a Submodule" |