aboutsummaryrefslogtreecommitdiff
path: root/bootstrap
diff options
context:
space:
mode:
authorBrad Richardson <everythingfunctional@protonmail.com>2020-10-20 11:06:35 -0500
committerBrad Richardson <everythingfunctional@protonmail.com>2020-10-20 11:06:35 -0500
commitcfb8b07fcb102573b70f37de9421e14d1300ac58 (patch)
tree560bcac9f077dc8f1fdfb50251caf3cf05c791d3 /bootstrap
parent28b00953f12d2fc0de9de75f26fd3c4346a44974 (diff)
downloadfpm-cfb8b07fcb102573b70f37de9421e14d1300ac58.tar.gz
fpm-cfb8b07fcb102573b70f37de9421e14d1300ac58.zip
Add test for source file name of program's compile time info
Diffstat (limited to 'bootstrap')
-rw-r--r--bootstrap/src/BuildModel.hs11
-rw-r--r--bootstrap/unit_test/ProgramToCompileInfoTest.hs48
2 files changed, 59 insertions, 0 deletions
diff --git a/bootstrap/src/BuildModel.hs b/bootstrap/src/BuildModel.hs
index eba1440..9bc6b48 100644
--- a/bootstrap/src/BuildModel.hs
+++ b/bootstrap/src/BuildModel.hs
@@ -58,6 +58,10 @@ data Source =
, submoduleName :: String
}
+data CompileTimeInfo = CompileTimeInfo {
+ compileTimeInfoSourceFileName :: FilePath
+}
+
processRawSource :: RawSource -> Source
processRawSource rawSource =
let sourceFileName = rawSourceFilename rawSource
@@ -86,6 +90,13 @@ processRawSource rawSource =
}
else undefined
+constructCompileTimeInfo :: Source -> [Source] -> FilePath -> CompileTimeInfo
+constructCompileTimeInfo program@(Program{}) otherSources buildDirectory =
+ CompileTimeInfo
+ { compileTimeInfoSourceFileName = programSourceFileName program
+ }
+constructCompileTimeInfo _ otherSources buildDirectory = undefined
+
pathSeparatorsToUnderscores :: FilePath -> FilePath
pathSeparatorsToUnderscores fileName =
intercalate "_" (splitDirectories fileName)
diff --git a/bootstrap/unit_test/ProgramToCompileInfoTest.hs b/bootstrap/unit_test/ProgramToCompileInfoTest.hs
new file mode 100644
index 0000000..b855c66
--- /dev/null
+++ b/bootstrap/unit_test/ProgramToCompileInfoTest.hs
@@ -0,0 +1,48 @@
+module ProgramToCompileInfoTest
+ ( test
+ )
+where
+
+import BuildModel ( Source(..)
+ , CompileTimeInfo(..)
+ , constructCompileTimeInfo
+ )
+import Hedge ( Result
+ , Test
+ , assertEquals
+ , givenInput
+ , then'
+ , whenTransformed
+ )
+import System.FilePath ( (</>) )
+
+test :: IO (Test ())
+test = return $ givenInput
+ "a program and other sources"
+ (exampleProgram, exampleSources)
+ [ whenTransformed
+ "its compileTimeInfo is determined"
+ doCompileTimeTransformation
+ [then' "it still knows the original source file" checkSourceFileName]
+ ]
+
+exampleProgram :: Source
+exampleProgram = Program
+ { programSourceFileName = programSourceFileName'
+ , programObjectFileName = \bd -> bd </> "some_file_somewhere.f90.o"
+ , programModulesUsed = ["module1", "module2", "module3"]
+ }
+
+programSourceFileName' :: String
+programSourceFileName' = "some" </> "file" </> "somewhere.f90"
+
+exampleSources :: [Source]
+exampleSources = []
+
+doCompileTimeTransformation :: (Source, [Source]) -> CompileTimeInfo
+doCompileTimeTransformation (programSource, otherSources) =
+ constructCompileTimeInfo programSource otherSources "build_dir"
+
+checkSourceFileName :: CompileTimeInfo -> Result
+checkSourceFileName cti =
+ assertEquals programSourceFileName' (compileTimeInfoSourceFileName cti)