From 1c69913b1d0ff68deffee4ee57ca3faef95b4a9d Mon Sep 17 00:00:00 2001 From: Brad Richardson Date: Wed, 14 Oct 2020 15:03:09 -0500 Subject: Rename first set of unit tests --- .../unit_test/ProgramSourceConstructionTest.hs | 68 ++++++++++++++++++++++ bootstrap/unit_test/SourceConstructionTest.hs | 68 ---------------------- 2 files changed, 68 insertions(+), 68 deletions(-) create mode 100644 bootstrap/unit_test/ProgramSourceConstructionTest.hs delete mode 100644 bootstrap/unit_test/SourceConstructionTest.hs diff --git a/bootstrap/unit_test/ProgramSourceConstructionTest.hs b/bootstrap/unit_test/ProgramSourceConstructionTest.hs new file mode 100644 index 0000000..91f0d90 --- /dev/null +++ b/bootstrap/unit_test/ProgramSourceConstructionTest.hs @@ -0,0 +1,68 @@ +module ProgramSourceConstructionTest + ( test + ) +where + +import BuildModel ( RawSource(..) + , Source(..) + , processRawSource + ) +import System.FilePath ( () ) +import Hedge ( Result + , Test + , assertEquals + , assertThat + , fail' + , givenInput + , then' + , whenTransformed + ) + +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/SourceConstructionTest.hs b/bootstrap/unit_test/SourceConstructionTest.hs deleted file mode 100644 index 751d10c..0000000 --- a/bootstrap/unit_test/SourceConstructionTest.hs +++ /dev/null @@ -1,68 +0,0 @@ -module SourceConstructionTest - ( test - ) -where - -import BuildModel ( RawSource(..) - , Source(..) - , processRawSource - ) -import System.FilePath ( () ) -import Hedge ( Result - , Test - , assertEquals - , assertThat - , fail' - , givenInput - , then' - , whenTransformed - ) - -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" -- cgit v1.2.3