diff options
author | Brad Richardson <everythingfunctional@protonmail.com> | 2020-10-20 14:24:55 -0500 |
---|---|---|
committer | Brad Richardson <everythingfunctional@protonmail.com> | 2020-10-20 14:24:55 -0500 |
commit | 55590e78dd6df0eac312eaadfc230533adfe0018 (patch) | |
tree | 63f413b4d669a1158a034d8241c3bfeae3cff48c /bootstrap/unit_test/ModuleToCompileInfoTest.hs | |
parent | 5db397ddca9ffa5558fb80ebfad73332f8c52cd6 (diff) | |
download | fpm-55590e78dd6df0eac312eaadfc230533adfe0018.tar.gz fpm-55590e78dd6df0eac312eaadfc230533adfe0018.zip |
Add tests for module's compile time info
Diffstat (limited to 'bootstrap/unit_test/ModuleToCompileInfoTest.hs')
-rw-r--r-- | bootstrap/unit_test/ModuleToCompileInfoTest.hs | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/bootstrap/unit_test/ModuleToCompileInfoTest.hs b/bootstrap/unit_test/ModuleToCompileInfoTest.hs new file mode 100644 index 0000000..5a1f0a8 --- /dev/null +++ b/bootstrap/unit_test/ModuleToCompileInfoTest.hs @@ -0,0 +1,70 @@ +module ModuleToCompileInfoTest + ( 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 module and available modules" + (exampleModule, availableModules) + [ whenTransformed + "its compileTimeInfo is determined" + doCompileTimeTransformation + [ then' "it stil knows the original source file" checkSourceFileName + , then' "it knows what object file will be produced" checkObjectFileName + , then' "the mod and smod files are also produced" checkOtherFilesProduced + , then' "the direct dependencies are only the available modules used" + checkDirectDependencies + ] + ] + +exampleModule :: Source +exampleModule = Module + { moduleSourceFileName = moduleSourceFileName' + , moduleObjectFileName = \bd -> bd </> "some_file_somewhere.f90.o" + , moduleModulesUsed = ["module1", "module2", "module3"] + , moduleName = "some_module" + , moduleProducesSmod = True + } + +moduleSourceFileName' :: FilePath +moduleSourceFileName' = "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 moduleSourceFileName' (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" </> "some_module.mod", "build_dir" </> "some_module.smod"] + (compileTimeInfoOtherFilesProduced cti) + +checkDirectDependencies :: CompileTimeInfo -> Result +checkDirectDependencies cti = assertEquals + ["build_dir" </> "module1.mod", "build_dir" </> "module3.mod"] + (compileTimeInfoDirectDependencies cti) |