diff options
author | Brad Richardson <everythingfunctional@protonmail.com> | 2020-10-15 10:36:58 -0500 |
---|---|---|
committer | Brad Richardson <everythingfunctional@protonmail.com> | 2020-10-15 10:36:58 -0500 |
commit | 134713a6c3620bf5b71ceaa2b6bed3a228d1c297 (patch) | |
tree | 37c1759b1cb0e791dffa445115065ad558261533 /bootstrap | |
parent | 84884be16503e506cd5ad7f927297fd7d25de779 (diff) | |
download | fpm-134713a6c3620bf5b71ceaa2b6bed3a228d1c297.tar.gz fpm-134713a6c3620bf5b71ceaa2b6bed3a228d1c297.zip |
Add test for modules a module uses
Diffstat (limited to 'bootstrap')
-rw-r--r-- | bootstrap/src/BuildModel.hs | 5 | ||||
-rw-r--r-- | bootstrap/unit_test/ModuleSourceConstructionTest.hs | 10 | ||||
-rw-r--r-- | bootstrap/unit_test/ProgramSourceConstructionTest.hs | 5 |
3 files changed, 15 insertions, 5 deletions
diff --git a/bootstrap/src/BuildModel.hs b/bootstrap/src/BuildModel.hs index 6446a12..1610784 100644 --- a/bootstrap/src/BuildModel.hs +++ b/bootstrap/src/BuildModel.hs @@ -45,6 +45,7 @@ data Source = | Module { moduleSourceFileName :: FilePath , moduleObjectFileName :: FilePath -> FilePath + , moduleModulesUsed :: [String] } processRawSource :: RawSource -> Source @@ -53,14 +54,16 @@ processRawSource rawSource = parsedContents = parseContents rawSource objectFileName = \bd -> bd </> (pathSeparatorsToUnderscores sourceFileName) <.> "o" + modulesUsed = getModulesUsed parsedContents in if hasProgramDeclaration parsedContents then Program { programSourceFileName = sourceFileName , programObjectFileName = objectFileName - , programModulesUsed = getModulesUsed parsedContents + , programModulesUsed = modulesUsed } else if hasModuleDeclaration parsedContents then Module { moduleSourceFileName = sourceFileName , moduleObjectFileName = objectFileName + , moduleModulesUsed = modulesUsed } else undefined diff --git a/bootstrap/unit_test/ModuleSourceConstructionTest.hs b/bootstrap/unit_test/ModuleSourceConstructionTest.hs index fd69844..20bc011 100644 --- a/bootstrap/unit_test/ModuleSourceConstructionTest.hs +++ b/bootstrap/unit_test/ModuleSourceConstructionTest.hs @@ -31,12 +31,13 @@ test = return $ givenInput , then' "its object file name is the 'flattened' path of the source file with '.o' appeneded" checkModuleObjectFileName + , then' "it knows what modules it uses directly" checkModuleModulesUsed ] ] exampleModule :: RawSource -exampleModule = - RawSource moduleSourceFileName' $ unlines ["module some_module", "end module"] +exampleModule = RawSource moduleSourceFileName' $ unlines + ["module some_module", " use module1", "USE MODULE2", "end module"] moduleSourceFileName' :: String moduleSourceFileName' = "some" </> "file" </> "somewhere.f90" @@ -55,3 +56,8 @@ checkModuleObjectFileName m@(Module{}) = assertEquals ("." </> "some_file_somewhere.f90.o") $ (moduleObjectFileName m) "." checkModuleObjectFileName _ = fail' "wasn't a Module" + +checkModuleModulesUsed :: Source -> Result +checkModuleModulesUsed m@(Module{}) = + assertEquals ["module1", "module2"] $ moduleModulesUsed m +checkModuleModulesUsed _ = fail' "wasn't a Module" diff --git a/bootstrap/unit_test/ProgramSourceConstructionTest.hs b/bootstrap/unit_test/ProgramSourceConstructionTest.hs index 91f0d90..6369965 100644 --- a/bootstrap/unit_test/ProgramSourceConstructionTest.hs +++ b/bootstrap/unit_test/ProgramSourceConstructionTest.hs @@ -7,7 +7,6 @@ import BuildModel ( RawSource(..) , Source(..) , processRawSource ) -import System.FilePath ( (</>) ) import Hedge ( Result , Test , assertEquals @@ -17,6 +16,7 @@ import Hedge ( Result , then' , whenTransformed ) +import System.FilePath ( (</>) ) test :: IO (Test ()) test = return $ givenInput @@ -64,5 +64,6 @@ checkProgramObjectFileName p@(Program{}) = checkProgramObjectFileName _ = fail' "wasn't a Program" checkProgramModulesUsed :: Source -> Result -checkProgramModulesUsed p@(Program{}) = assertEquals ["module1", "module2"] $ programModulesUsed p +checkProgramModulesUsed p@(Program{}) = + assertEquals ["module1", "module2"] $ programModulesUsed p checkProgramModulesUsed _ = fail' "wasn't a Program" |