aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/unit_test/SubmoduleToCompileInfoTest.hs
diff options
context:
space:
mode:
authorBrad Richardson <everythingfunctional@protonmail.com>2020-10-26 17:16:44 -0500
committerGitHub <noreply@github.com>2020-10-26 17:16:44 -0500
commit4443986b3d5690ce4ee8bbc348834caa2040be23 (patch)
tree0553b054c43c89edab17a3d6959f7adb84648a61 /bootstrap/unit_test/SubmoduleToCompileInfoTest.hs
parente92d9c9c406aff61d404d2afe71c416ed019beb0 (diff)
parent488bdd06ab78cec3085aa86b6dbe36a98f58eb86 (diff)
downloadfpm-4443986b3d5690ce4ee8bbc348834caa2040be23.tar.gz
fpm-4443986b3d5690ce4ee8bbc348834caa2040be23.zip
Merge pull request #213 from everythingfunctional/bootstrap_submodule_support
Bootstrap submodule support
Diffstat (limited to 'bootstrap/unit_test/SubmoduleToCompileInfoTest.hs')
-rw-r--r--bootstrap/unit_test/SubmoduleToCompileInfoTest.hs75
1 files changed, 75 insertions, 0 deletions
diff --git a/bootstrap/unit_test/SubmoduleToCompileInfoTest.hs b/bootstrap/unit_test/SubmoduleToCompileInfoTest.hs
new file mode 100644
index 0000000..d5d3ad8
--- /dev/null
+++ b/bootstrap/unit_test/SubmoduleToCompileInfoTest.hs
@@ -0,0 +1,75 @@
+module SubmoduleToCompileInfoTest
+ ( test
+ )
+where
+
+import BuildModel ( CompileTimeInfo(..)
+ , Source(..)
+ , constructCompileTimeInfo
+ )
+import Hedge ( Result
+ , Test
+ , assertEquals
+ , givenInput
+ , then'
+ , whenTransformed
+ )
+import System.FilePath ( (</>) )
+
+test :: IO (Test ())
+test = return $ givenInput
+ "a submodule and available modules"
+ (exampleSubmodule, availableModules)
+ [ whenTransformed
+ "its compileTimeInfo is determined"
+ doCompileTimeTransformation
+ [ then' "it still knows the original source file" checkSourceFileName
+ , then' "it knows what object file will be produced" checkObjectFileName
+ , then' "the smod file is also produced" checkOtherFilesProduced
+ , then'
+ "the direct dependencies are the parent smod and the available modules used"
+ checkDirectDependencies
+ ]
+ ]
+
+exampleSubmodule :: Source
+exampleSubmodule = Submodule
+ { submoduleSourceFileName = submoduleSourceFileName'
+ , submoduleObjectFileName = \bd -> bd </> "some_file_somewhere.f90.o"
+ , submoduleModulesUsed = ["module1", "module2", "module3"]
+ , submoduleBaseModuleName = "base_module"
+ , submoduleParentName = "base_module@parent"
+ , submoduleName = "some_submodule"
+ }
+
+submoduleSourceFileName' :: FilePath
+submoduleSourceFileName' = "some" </> "file" </> "somewhere.f90"
+
+availableModules :: [String]
+availableModules = ["module1", "module3"]
+
+doCompileTimeTransformation :: (Source, [String]) -> CompileTimeInfo
+doCompileTimeTransformation (programSource, otherSources) =
+ constructCompileTimeInfo programSource otherSources "build_dir"
+
+checkSourceFileName :: CompileTimeInfo -> Result
+checkSourceFileName cti =
+ assertEquals submoduleSourceFileName' (compileTimeInfoSourceFileName cti)
+
+checkObjectFileName :: CompileTimeInfo -> Result
+checkObjectFileName cti = assertEquals
+ ("build_dir" </> "some_file_somewhere.f90.o")
+ (compileTimeInfoObjectFileProduced cti)
+
+checkOtherFilesProduced :: CompileTimeInfo -> Result
+checkOtherFilesProduced cti = assertEquals
+ ["build_dir" </> "base_module@some_submodule.smod"]
+ (compileTimeInfoOtherFilesProduced cti)
+
+checkDirectDependencies :: CompileTimeInfo -> Result
+checkDirectDependencies cti = assertEquals
+ [ "build_dir" </> "base_module@parent.smod"
+ , "build_dir" </> "module1.mod"
+ , "build_dir" </> "module3.mod"
+ ]
+ (compileTimeInfoDirectDependencies cti)