@@ -41,6 +41,7 @@ data TomlSettings = TomlSettings {
41
41
, tomlSettingsProjectName :: String
42
42
, tomlSettingsLibrary :: (Maybe Library )
43
43
, tomlSettingsExecutables :: [Executable ]
44
+ , tomlSettingsTests :: [Executable ]
44
45
}
45
46
46
47
data AppSettings = AppSettings {
@@ -50,6 +51,7 @@ data AppSettings = AppSettings {
50
51
, appSettingsFlags :: [String ]
51
52
, appSettingsLibrary :: (Maybe Library )
52
53
, appSettingsExecutables :: [Executable ]
54
+ , appSettingsTests :: [Executable ]
53
55
}
54
56
55
57
data Library = Library { librarySourceDir :: String }
@@ -87,7 +89,17 @@ app args settings = case command' args of
87
89
(appSettingsExecutables settings)
88
90
let executables = map (buildPrefix </> ) executableNames
89
91
mapM_ runCommand executables
90
- Test -> putStrLn " Test"
92
+ Test -> do
93
+ build settings
94
+ let buildPrefix = appSettingsBuildPrefix settings
95
+ let
96
+ executableNames = map
97
+ (\ Executable { executableSourceDir = sourceDir, executableMainFile = mainFile, executableName = name } ->
98
+ sourceDir </> name
99
+ )
100
+ (appSettingsTests settings)
101
+ let executables = map (buildPrefix </> ) executableNames
102
+ mapM_ runCommand executables
91
103
92
104
build :: AppSettings -> IO ()
93
105
build settings = do
@@ -96,6 +108,7 @@ build settings = do
96
108
let buildPrefix = appSettingsBuildPrefix settings
97
109
let flags = appSettingsFlags settings
98
110
let executables = appSettingsExecutables settings
111
+ let tests = appSettingsTests settings
99
112
executableDepends <- case appSettingsLibrary settings of
100
113
Just librarySettings -> do
101
114
let librarySourceDir' = librarySourceDir librarySettings
@@ -122,6 +135,19 @@ build settings = do
122
135
mainFile
123
136
)
124
137
executables
138
+ mapM_
139
+ (\ Executable { executableSourceDir = sourceDir, executableMainFile = mainFile, executableName = name } ->
140
+ do
141
+ buildProgram sourceDir
142
+ executableDepends
143
+ [" .f90" , " .f" , " .F" , " .F90" , " .f95" , " .f03" ]
144
+ (buildPrefix </> sourceDir)
145
+ compiler
146
+ flags
147
+ name
148
+ mainFile
149
+ )
150
+ tests
125
151
126
152
getArguments :: IO Arguments
127
153
getArguments = execParser
@@ -169,6 +195,8 @@ settingsCodec =
169
195
.= tomlSettingsLibrary
170
196
<*> Toml. list executableCodec " executable"
171
197
.= tomlSettingsExecutables
198
+ <*> Toml. list executableCodec " test"
199
+ .= tomlSettingsTests
172
200
173
201
libraryCodec :: TomlCodec Library
174
202
libraryCodec = Library <$> Toml. string " source-dir" .= librarySourceDir
@@ -190,6 +218,7 @@ toml2AppSettings tomlSettings release = do
190
218
executableSettings <- getExecutableSettings
191
219
(tomlSettingsExecutables tomlSettings)
192
220
projectName
221
+ testSettings <- getTestSettings $ tomlSettingsTests tomlSettings
193
222
return AppSettings
194
223
{ appSettingsCompiler = tomlSettingsCompiler tomlSettings
195
224
, appSettingsProjectName = projectName
@@ -222,6 +251,7 @@ toml2AppSettings tomlSettings release = do
222
251
]
223
252
, appSettingsLibrary = librarySettings
224
253
, appSettingsExecutables = executableSettings
254
+ , appSettingsTests = testSettings
225
255
}
226
256
227
257
getLibrarySettings :: Maybe Library -> IO (Maybe Library )
@@ -249,3 +279,20 @@ getExecutableSettings [] projectName = do
249
279
else return []
250
280
else return []
251
281
getExecutableSettings executables _ = return executables
282
+
283
+ getTestSettings :: [Executable ] -> IO [Executable ]
284
+ getTestSettings [] = do
285
+ defaultDirectoryExists <- doesDirectoryExist " test"
286
+ if defaultDirectoryExists
287
+ then do
288
+ defaultMainExists <- doesFileExist (" test" </> " main.f90" )
289
+ if defaultMainExists
290
+ then return
291
+ [ Executable { executableSourceDir = " test"
292
+ , executableMainFile = " main.f90"
293
+ , executableName = " runTests"
294
+ }
295
+ ]
296
+ else return []
297
+ else return []
298
+ getTestSettings tests = return tests
0 commit comments