From 29be28f5e7de2d8a3fa405d61ec63e8c8d7ea809 Mon Sep 17 00:00:00 2001 From: Brad Richardson Date: Thu, 15 Oct 2020 11:43:20 -0500 Subject: Add constructor for Submodule Source --- .../unit_test/SubmoduleSourceConstructionTest.hs | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 bootstrap/unit_test/SubmoduleSourceConstructionTest.hs (limited to 'bootstrap/unit_test/SubmoduleSourceConstructionTest.hs') diff --git a/bootstrap/unit_test/SubmoduleSourceConstructionTest.hs b/bootstrap/unit_test/SubmoduleSourceConstructionTest.hs new file mode 100644 index 0000000..96492fb --- /dev/null +++ b/bootstrap/unit_test/SubmoduleSourceConstructionTest.hs @@ -0,0 +1,37 @@ +module SubmoduleSourceConstructionTest + ( 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 submodule" + exampleSubmodule + [ whenTransformed "processed to a source" + processRawSource + [then' "it is a Submodule" checkIsSubmodule] + ] + +exampleSubmodule :: RawSource +exampleSubmodule = RawSource submoduleSourceFileName' + $ unlines ["submodule (some_module:parent) child", "end submodule"] + +submoduleSourceFileName' :: String +submoduleSourceFileName' = "some" "file" "somewhere.f90" + +checkIsSubmodule :: Source -> Result +checkIsSubmodule Submodule{} = assertThat True +checkIsSubmodule _ = assertThat False -- cgit v1.2.3 From b927218b5690fe7cd4080af53831311d59db6987 Mon Sep 17 00:00:00 2001 From: Brad Richardson Date: Thu, 15 Oct 2020 11:52:11 -0500 Subject: Add test for submodule source file name --- bootstrap/unit_test/SubmoduleSourceConstructionTest.hs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'bootstrap/unit_test/SubmoduleSourceConstructionTest.hs') diff --git a/bootstrap/unit_test/SubmoduleSourceConstructionTest.hs b/bootstrap/unit_test/SubmoduleSourceConstructionTest.hs index 96492fb..6158939 100644 --- a/bootstrap/unit_test/SubmoduleSourceConstructionTest.hs +++ b/bootstrap/unit_test/SubmoduleSourceConstructionTest.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 submodule" exampleSubmodule - [ whenTransformed "processed to a source" - processRawSource - [then' "it is a Submodule" checkIsSubmodule] + [ whenTransformed + "processed to a source" + processRawSource + [ then' "it is a Submodule" checkIsSubmodule + , then' "its source file name is the same as the original" + checkSubmoduleSourceFileName + ] ] exampleSubmodule :: RawSource @@ -35,3 +41,8 @@ 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" -- cgit v1.2.3 From a981372352e881d1cc7d542628959c0ac501e96e Mon Sep 17 00:00:00 2001 From: Brad Richardson Date: Mon, 19 Oct 2020 15:42:22 -0500 Subject: Add test for submodule object file name --- bootstrap/unit_test/SubmoduleSourceConstructionTest.hs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'bootstrap/unit_test/SubmoduleSourceConstructionTest.hs') diff --git a/bootstrap/unit_test/SubmoduleSourceConstructionTest.hs b/bootstrap/unit_test/SubmoduleSourceConstructionTest.hs index 6158939..5295a97 100644 --- a/bootstrap/unit_test/SubmoduleSourceConstructionTest.hs +++ b/bootstrap/unit_test/SubmoduleSourceConstructionTest.hs @@ -28,6 +28,9 @@ test = return $ givenInput [ 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 ] ] @@ -46,3 +49,9 @@ 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" -- cgit v1.2.3 From f038a093bc0259bf7d72d86fb95f4a2aebf1a8df Mon Sep 17 00:00:00 2001 From: Brad Richardson Date: Mon, 19 Oct 2020 15:52:45 -0500 Subject: Add test for modules a submodule uses --- bootstrap/unit_test/SubmoduleSourceConstructionTest.hs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'bootstrap/unit_test/SubmoduleSourceConstructionTest.hs') diff --git a/bootstrap/unit_test/SubmoduleSourceConstructionTest.hs b/bootstrap/unit_test/SubmoduleSourceConstructionTest.hs index 5295a97..956d782 100644 --- a/bootstrap/unit_test/SubmoduleSourceConstructionTest.hs +++ b/bootstrap/unit_test/SubmoduleSourceConstructionTest.hs @@ -31,12 +31,18 @@ test = return $ givenInput , 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 ] ] exampleSubmodule :: RawSource -exampleSubmodule = RawSource submoduleSourceFileName' - $ unlines ["submodule (some_module:parent) child", "end submodule"] +exampleSubmodule = RawSource submoduleSourceFileName' $ unlines + [ "submodule (some_module:parent) child" + , " use module1" + , " USE MODULE2" + , " implicit none" + , "end submodule" + ] submoduleSourceFileName' :: String submoduleSourceFileName' = "some" "file" "somewhere.f90" @@ -55,3 +61,8 @@ 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" -- cgit v1.2.3 From 28b00953f12d2fc0de9de75f26fd3c4346a44974 Mon Sep 17 00:00:00 2001 From: Brad Richardson Date: Mon, 19 Oct 2020 16:13:53 -0500 Subject: Add test for a submodule's name --- bootstrap/unit_test/SubmoduleSourceConstructionTest.hs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'bootstrap/unit_test/SubmoduleSourceConstructionTest.hs') diff --git a/bootstrap/unit_test/SubmoduleSourceConstructionTest.hs b/bootstrap/unit_test/SubmoduleSourceConstructionTest.hs index 956d782..577207e 100644 --- a/bootstrap/unit_test/SubmoduleSourceConstructionTest.hs +++ b/bootstrap/unit_test/SubmoduleSourceConstructionTest.hs @@ -32,6 +32,7 @@ test = return $ givenInput "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 name" checkSubmoduleName ] ] @@ -66,3 +67,8 @@ checkSubmoduleModulesUsed :: Source -> Result checkSubmoduleModulesUsed s@(Submodule{}) = assertEquals ["module1", "module2"] $ submoduleModulesUsed s checkSubmoduleModulesUsed _ = fail' "wasn't a Submodule" + +checkSubmoduleName :: Source -> Result +checkSubmoduleName s@(Submodule{}) = + assertEquals "some_module@parent@child" $ submoduleName s +checkSubmoduleName _ = fail' "wasn't a Submodule" -- cgit v1.2.3 From 0799961cdd047005021549c32d8f8d7731f40d27 Mon Sep 17 00:00:00 2001 From: Brad Richardson Date: Tue, 20 Oct 2020 14:36:30 -0500 Subject: Split submodule name into two components --- bootstrap/unit_test/SubmoduleSourceConstructionTest.hs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'bootstrap/unit_test/SubmoduleSourceConstructionTest.hs') diff --git a/bootstrap/unit_test/SubmoduleSourceConstructionTest.hs b/bootstrap/unit_test/SubmoduleSourceConstructionTest.hs index 577207e..d07a6ed 100644 --- a/bootstrap/unit_test/SubmoduleSourceConstructionTest.hs +++ b/bootstrap/unit_test/SubmoduleSourceConstructionTest.hs @@ -32,6 +32,7 @@ test = return $ givenInput "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 ] ] @@ -68,7 +69,11 @@ 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 "some_module@parent@child" $ submoduleName s -checkSubmoduleName _ = fail' "wasn't a Submodule" +checkSubmoduleName s@(Submodule{}) = assertEquals "child" $ submoduleName s +checkSubmoduleName _ = fail' "wasn't a Submodule" -- cgit v1.2.3