aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/unit_test/ProgramToCompileInfoTest.hs
blob: b855c669e42fd4c073c6825a0f603fa2db1e8daa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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)