From 4b062f1f275d568099d6ebf4c1c687c50d039b84 Mon Sep 17 00:00:00 2001 From: Brad Richardson Date: Thu, 15 Oct 2020 10:13:35 -0500 Subject: Add constructor for Module Source --- .../unit_test/ModuleSourceConstructionTest.hs | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 bootstrap/unit_test/ModuleSourceConstructionTest.hs (limited to 'bootstrap/unit_test/ModuleSourceConstructionTest.hs') diff --git a/bootstrap/unit_test/ModuleSourceConstructionTest.hs b/bootstrap/unit_test/ModuleSourceConstructionTest.hs new file mode 100644 index 0000000..cc6d079 --- /dev/null +++ b/bootstrap/unit_test/ModuleSourceConstructionTest.hs @@ -0,0 +1,37 @@ +module ModuleSourceConstructionTest + ( test + ) +where + +import BuildModel ( RawSource(..) + , Source(..) + , processRawSource + ) +import Hedge ( Result + , Test + , assertThat + , 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] + ] + +exampleModule :: RawSource +exampleModule = + RawSource moduleSourceFileName' $ unlines ["module some_module", "end module"] + +moduleSourceFileName' :: String +moduleSourceFileName' = "some" "file" "somewhere.f90" + +checkIsModule :: Source -> Result +checkIsModule Module{} = assertThat True +checkIsModule _ = assertThat False -- cgit v1.2.3 From c2638957dd9aca90831e0b434fec9ccc05c77acc Mon Sep 17 00:00:00 2001 From: Brad Richardson Date: Thu, 15 Oct 2020 10:22:43 -0500 Subject: Add test for module source file name --- bootstrap/unit_test/ModuleSourceConstructionTest.hs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'bootstrap/unit_test/ModuleSourceConstructionTest.hs') diff --git a/bootstrap/unit_test/ModuleSourceConstructionTest.hs b/bootstrap/unit_test/ModuleSourceConstructionTest.hs index cc6d079..fae7c89 100644 --- a/bootstrap/unit_test/ModuleSourceConstructionTest.hs +++ b/bootstrap/unit_test/ModuleSourceConstructionTest.hs @@ -9,7 +9,9 @@ import BuildModel ( RawSource(..) ) import Hedge ( Result , Test + , assertEquals , assertThat + , fail' , givenInput , then' , whenTransformed @@ -20,9 +22,13 @@ test :: IO (Test ()) test = return $ givenInput "a module" exampleModule - [ whenTransformed "processed to a source" - processRawSource - [then' "it is a Module" checkIsModule] + [ whenTransformed + "processed to a source" + processRawSource + [ then' "it is a Module" checkIsModule + , then' "its source file name is the same as the original" + checkModuleSourceFileName + ] ] exampleModule :: RawSource @@ -35,3 +41,8 @@ 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" -- cgit v1.2.3 From 84884be16503e506cd5ad7f927297fd7d25de779 Mon Sep 17 00:00:00 2001 From: Brad Richardson Date: Thu, 15 Oct 2020 10:28:02 -0500 Subject: Add test for module object file name --- bootstrap/unit_test/ModuleSourceConstructionTest.hs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'bootstrap/unit_test/ModuleSourceConstructionTest.hs') diff --git a/bootstrap/unit_test/ModuleSourceConstructionTest.hs b/bootstrap/unit_test/ModuleSourceConstructionTest.hs index fae7c89..fd69844 100644 --- a/bootstrap/unit_test/ModuleSourceConstructionTest.hs +++ b/bootstrap/unit_test/ModuleSourceConstructionTest.hs @@ -28,6 +28,9 @@ test = return $ givenInput [ 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 ] ] @@ -46,3 +49,9 @@ 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" -- cgit v1.2.3 From 134713a6c3620bf5b71ceaa2b6bed3a228d1c297 Mon Sep 17 00:00:00 2001 From: Brad Richardson Date: Thu, 15 Oct 2020 10:36:58 -0500 Subject: Add test for modules a module uses --- bootstrap/unit_test/ModuleSourceConstructionTest.hs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'bootstrap/unit_test/ModuleSourceConstructionTest.hs') 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" -- cgit v1.2.3 From 311c695aa30f63fc1be0ef8b8c56ca372e01a31e Mon Sep 17 00:00:00 2001 From: Brad Richardson Date: Thu, 15 Oct 2020 10:47:40 -0500 Subject: Add test for a module's name --- bootstrap/unit_test/ModuleSourceConstructionTest.hs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'bootstrap/unit_test/ModuleSourceConstructionTest.hs') diff --git a/bootstrap/unit_test/ModuleSourceConstructionTest.hs b/bootstrap/unit_test/ModuleSourceConstructionTest.hs index 20bc011..26f08b2 100644 --- a/bootstrap/unit_test/ModuleSourceConstructionTest.hs +++ b/bootstrap/unit_test/ModuleSourceConstructionTest.hs @@ -32,6 +32,7 @@ test = return $ givenInput "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 ] ] @@ -61,3 +62,7 @@ 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" -- cgit v1.2.3 From bd27ae8161860f9a40c3953e20001af1f450d5f4 Mon Sep 17 00:00:00 2001 From: Brad Richardson Date: Thu, 15 Oct 2020 11:07:47 -0500 Subject: Add test for whether a module produces a .smod file --- bootstrap/unit_test/ModuleSourceConstructionTest.hs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'bootstrap/unit_test/ModuleSourceConstructionTest.hs') diff --git a/bootstrap/unit_test/ModuleSourceConstructionTest.hs b/bootstrap/unit_test/ModuleSourceConstructionTest.hs index 26f08b2..b98e9d3 100644 --- a/bootstrap/unit_test/ModuleSourceConstructionTest.hs +++ b/bootstrap/unit_test/ModuleSourceConstructionTest.hs @@ -33,12 +33,23 @@ test = return $ givenInput 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", "end module"] + [ "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" @@ -66,3 +77,7 @@ 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" -- cgit v1.2.3