aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/unit_test
diff options
context:
space:
mode:
Diffstat (limited to 'bootstrap/unit_test')
-rw-r--r--bootstrap/unit_test/ModuleSourceConstructionTest.hs83
-rw-r--r--bootstrap/unit_test/ModuleToCompileInfoTest.hs70
-rw-r--r--bootstrap/unit_test/ProgramSourceConstructionTest.hs69
-rw-r--r--bootstrap/unit_test/ProgramToCompileInfoTest.hs68
-rw-r--r--bootstrap/unit_test/SubmoduleSourceConstructionTest.hs79
-rw-r--r--bootstrap/unit_test/SubmoduleToCompileInfoTest.hs75
-rw-r--r--bootstrap/unit_test/Trimmer.hs1
7 files changed, 445 insertions, 0 deletions
diff --git a/bootstrap/unit_test/ModuleSourceConstructionTest.hs b/bootstrap/unit_test/ModuleSourceConstructionTest.hs
new file mode 100644
index 0000000..b98e9d3
--- /dev/null
+++ b/bootstrap/unit_test/ModuleSourceConstructionTest.hs
@@ -0,0 +1,83 @@
+module ModuleSourceConstructionTest
+ ( 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 module"
+ exampleModule
+ [ whenTransformed
+ "processed to a source"
+ processRawSource
+ [ then' "it is a Module" checkIsModule
+ , then' "its source file name is the same as the original"
+ checkModuleSourceFileName
+ , 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
+ , then' "it knows its name" checkModuleName
+ , then' "it can tell that it will produce a '.smod' file" checkSmod
+ ]
+ ]
+
+exampleModule :: RawSource
+exampleModule = RawSource moduleSourceFileName' $ unlines
+ [ "module some_module"
+ , " use module1"
+ , " USE MODULE2"
+ , " implicit none"
+ , " interface"
+ , " pure module function some_func()"
+ , " integer :: some_func"
+ , " end function"
+ , " end interface"
+ , "end module"
+ ]
+
+moduleSourceFileName' :: String
+moduleSourceFileName' = "some" </> "file" </> "somewhere.f90"
+
+checkIsModule :: Source -> Result
+checkIsModule Module{} = assertThat True
+checkIsModule _ = assertThat False
+
+checkModuleSourceFileName :: Source -> Result
+checkModuleSourceFileName m@(Module{}) =
+ assertEquals moduleSourceFileName' $ moduleSourceFileName m
+checkModuleSourceFileName _ = fail' "wasn't a Module"
+
+checkModuleObjectFileName :: Source -> Result
+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"
+
+checkModuleName :: Source -> Result
+checkModuleName m@(Module{}) = assertEquals "some_module" $ moduleName m
+checkModuleName _ = fail' "wasn't a Module"
+
+checkSmod :: Source -> Result
+checkSmod m@(Module{}) = assertThat $ moduleProducesSmod m
+checkSmod _ = fail' "wasn't a Module"
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)
diff --git a/bootstrap/unit_test/ProgramSourceConstructionTest.hs b/bootstrap/unit_test/ProgramSourceConstructionTest.hs
new file mode 100644
index 0000000..6369965
--- /dev/null
+++ b/bootstrap/unit_test/ProgramSourceConstructionTest.hs
@@ -0,0 +1,69 @@
+module ProgramSourceConstructionTest
+ ( 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 program"
+ exampleProgram
+ [ whenTransformed
+ "processed to a source"
+ processRawSource
+ [ then' "it is a Program" checkIsProgram
+ , then' "its source file name is the same as the original"
+ checkProgramSourceFileName
+ , then'
+ "its object file name is the 'flattened' path of the source file with '.o' appended"
+ checkProgramObjectFileName
+ , then' "it knows what modules it uses directly" checkProgramModulesUsed
+ ]
+ ]
+
+exampleProgram :: RawSource
+exampleProgram = RawSource programSourceFileName' $ unlines
+ [ "program some_program"
+ , " use module1"
+ , " USE MODULE2"
+ , " implicit none"
+ , " print *, \"Hello, World!\""
+ , "end program"
+ ]
+
+programSourceFileName' :: String
+programSourceFileName' = "some" </> "file" </> "somewhere.f90"
+
+checkIsProgram :: Source -> Result
+checkIsProgram Program{} = assertThat True
+checkIsProgram _ = assertThat False
+
+checkProgramSourceFileName :: Source -> Result
+checkProgramSourceFileName p@(Program{}) =
+ assertEquals programSourceFileName' $ programSourceFileName p
+checkProgramSourceFileName _ = fail' "wasn't a Program"
+
+checkProgramObjectFileName :: Source -> Result
+checkProgramObjectFileName p@(Program{}) =
+ assertEquals ("." </> "some_file_somewhere.f90.o")
+ $ (programObjectFileName p) "."
+checkProgramObjectFileName _ = fail' "wasn't a Program"
+
+checkProgramModulesUsed :: Source -> Result
+checkProgramModulesUsed p@(Program{}) =
+ assertEquals ["module1", "module2"] $ programModulesUsed p
+checkProgramModulesUsed _ = fail' "wasn't a Program"
diff --git a/bootstrap/unit_test/ProgramToCompileInfoTest.hs b/bootstrap/unit_test/ProgramToCompileInfoTest.hs
new file mode 100644
index 0000000..f17a3df
--- /dev/null
+++ b/bootstrap/unit_test/ProgramToCompileInfoTest.hs
@@ -0,0 +1,68 @@
+module ProgramToCompileInfoTest
+ ( test
+ )
+where
+
+import BuildModel ( CompileTimeInfo(..)
+ , Source(..)
+ , constructCompileTimeInfo
+ )
+import Hedge ( Result
+ , Test
+ , assertEmpty
+ , assertEquals
+ , givenInput
+ , then'
+ , whenTransformed
+ )
+import System.FilePath ( (</>) )
+
+test :: IO (Test ())
+test = return $ givenInput
+ "a program and available modules"
+ (exampleProgram, 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' "there are no other files produced" checkOtherFilesProduced
+ , then' "the direct dependencies are only the available modules used"
+ checkDirectDependencies
+ ]
+ ]
+
+exampleProgram :: Source
+exampleProgram = Program
+ { programSourceFileName = programSourceFileName'
+ , programObjectFileName = \bd -> bd </> "some_file_somewhere.f90.o"
+ , programModulesUsed = ["module1", "module2", "module3"]
+ }
+
+programSourceFileName' :: FilePath
+programSourceFileName' = "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 programSourceFileName' (compileTimeInfoSourceFileName cti)
+
+checkObjectFileName :: CompileTimeInfo -> Result
+checkObjectFileName cti = assertEquals
+ ("build_dir" </> "some_file_somewhere.f90.o")
+ (compileTimeInfoObjectFileProduced cti)
+
+checkOtherFilesProduced :: CompileTimeInfo -> Result
+checkOtherFilesProduced cti =
+ assertEmpty (compileTimeInfoOtherFilesProduced cti)
+
+checkDirectDependencies :: CompileTimeInfo -> Result
+checkDirectDependencies cti = assertEquals
+ ["build_dir" </> "module1.mod", "build_dir" </> "module3.mod"]
+ (compileTimeInfoDirectDependencies cti)
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"
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)
diff --git a/bootstrap/unit_test/Trimmer.hs b/bootstrap/unit_test/Trimmer.hs
new file mode 100644
index 0000000..4e0f91d
--- /dev/null
+++ b/bootstrap/unit_test/Trimmer.hs
@@ -0,0 +1 @@
+{-# OPTIONS_GHC -F -pgmF hedge-trimmer #-}