aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/unit_test/ProgramSourceConstructionTest.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/ProgramSourceConstructionTest.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/ProgramSourceConstructionTest.hs')
-rw-r--r--bootstrap/unit_test/ProgramSourceConstructionTest.hs69
1 files changed, 69 insertions, 0 deletions
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"