aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/unit_test/ModuleToCompileInfoTest.hs
blob: 5a1f0a8431a414f76eb2c8ae8561ee4ce961edc1 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
module ModuleToCompileInfoTest
  ( test
  )
where

import           BuildModel                     ( CompileTimeInfo(..)
                                                , Source(..)
                                                , constructCompileTimeInfo
                                                )
import           Hedge                          ( Result
                                                , Test
                                                , assertEquals
                                                , givenInput
                                                , then'
                                                , whenTransformed
                                                )
import           System.FilePath                ( (</>) )

test :: IO (Test ())
test = return $ givenInput
  "a module and available modules"
  (exampleModule, availableModules)
  [ whenTransformed
      "its compileTimeInfo is determined"
      doCompileTimeTransformation
      [ then' "it stil knows the original source file"     checkSourceFileName
      , then' "it knows what object file will be produced" checkObjectFileName
      , then' "the mod and smod files are also produced" checkOtherFilesProduced
      , then' "the direct dependencies are only the available modules used"
              checkDirectDependencies
      ]
  ]

exampleModule :: Source
exampleModule = Module
  { moduleSourceFileName = moduleSourceFileName'
  , moduleObjectFileName = \bd -> bd </> "some_file_somewhere.f90.o"
  , moduleModulesUsed    = ["module1", "module2", "module3"]
  , moduleName           = "some_module"
  , moduleProducesSmod   = True
  }

moduleSourceFileName' :: FilePath
moduleSourceFileName' = "some" </> "file" </> "somewhere.f90"

availableModules :: [String]
availableModules = ["module1", "module3"]

doCompileTimeTransformation :: (Source, [String]) -> CompileTimeInfo
doCompileTimeTransformation (programSource, otherSources) =
  constructCompileTimeInfo programSource otherSources "build_dir"

checkSourceFileName :: CompileTimeInfo -> Result
checkSourceFileName cti =
  assertEquals moduleSourceFileName' (compileTimeInfoSourceFileName cti)

checkObjectFileName :: CompileTimeInfo -> Result
checkObjectFileName cti = assertEquals
  ("build_dir" </> "some_file_somewhere.f90.o")
  (compileTimeInfoObjectFileProduced cti)

checkOtherFilesProduced :: CompileTimeInfo -> Result
checkOtherFilesProduced cti = assertEquals
  ["build_dir" </> "some_module.mod", "build_dir" </> "some_module.smod"]
  (compileTimeInfoOtherFilesProduced cti)

checkDirectDependencies :: CompileTimeInfo -> Result
checkDirectDependencies cti = assertEquals
  ["build_dir" </> "module1.mod", "build_dir" </> "module3.mod"]
  (compileTimeInfoDirectDependencies cti)