@@ -28,6 +28,7 @@ import Options.Applicative ( Parser
28
28
import System.Directory ( doesDirectoryExist
29
29
, doesFileExist
30
30
)
31
+ import System.Process ( runCommand )
31
32
import Toml ( TomlCodec
32
33
, (.=)
33
34
)
@@ -40,6 +41,7 @@ data TomlSettings = TomlSettings {
40
41
, tomlSettingsProjectName :: String
41
42
, tomlSettingsLibrary :: (Maybe Library )
42
43
, tomlSettingsExecutables :: [Executable ]
44
+ , tomlSettingsTests :: [Executable ]
43
45
}
44
46
45
47
data AppSettings = AppSettings {
@@ -49,6 +51,7 @@ data AppSettings = AppSettings {
49
51
, appSettingsFlags :: [String ]
50
52
, appSettingsLibrary :: (Maybe Library )
51
53
, appSettingsExecutables :: [Executable ]
54
+ , appSettingsTests :: [Executable ]
52
55
}
53
56
54
57
data Library = Library { librarySourceDir :: String }
@@ -74,18 +77,38 @@ main = do
74
77
75
78
app :: Arguments -> AppSettings -> IO ()
76
79
app args settings = case command' args of
77
- Run -> putStrLn " Run"
78
- Test -> putStrLn " Test"
79
80
Build -> build settings
81
+ Run -> do
82
+ build settings
83
+ let buildPrefix = appSettingsBuildPrefix settings
84
+ let
85
+ executableNames = map
86
+ (\ Executable { executableSourceDir = sourceDir, executableMainFile = mainFile, executableName = name } ->
87
+ sourceDir </> name
88
+ )
89
+ (appSettingsExecutables settings)
90
+ let executables = map (buildPrefix </> ) executableNames
91
+ mapM_ runCommand executables
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
80
103
81
104
build :: AppSettings -> IO ()
82
105
build settings = do
83
- putStrLn " Building"
84
106
let compiler = appSettingsCompiler settings
85
107
let projectName = appSettingsProjectName settings
86
108
let buildPrefix = appSettingsBuildPrefix settings
87
109
let flags = appSettingsFlags settings
88
110
let executables = appSettingsExecutables settings
111
+ let tests = appSettingsTests settings
89
112
executableDepends <- case appSettingsLibrary settings of
90
113
Just librarySettings -> do
91
114
let librarySourceDir' = librarySourceDir librarySettings
@@ -112,6 +135,19 @@ build settings = do
112
135
mainFile
113
136
)
114
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
115
151
116
152
getArguments :: IO Arguments
117
153
getArguments = execParser
@@ -159,6 +195,8 @@ settingsCodec =
159
195
.= tomlSettingsLibrary
160
196
<*> Toml. list executableCodec " executable"
161
197
.= tomlSettingsExecutables
198
+ <*> Toml. list executableCodec " test"
199
+ .= tomlSettingsTests
162
200
163
201
libraryCodec :: TomlCodec Library
164
202
libraryCodec = Library <$> Toml. string " source-dir" .= librarySourceDir
@@ -180,6 +218,7 @@ toml2AppSettings tomlSettings release = do
180
218
executableSettings <- getExecutableSettings
181
219
(tomlSettingsExecutables tomlSettings)
182
220
projectName
221
+ testSettings <- getTestSettings $ tomlSettingsTests tomlSettings
183
222
return AppSettings
184
223
{ appSettingsCompiler = tomlSettingsCompiler tomlSettings
185
224
, appSettingsProjectName = projectName
@@ -212,6 +251,7 @@ toml2AppSettings tomlSettings release = do
212
251
]
213
252
, appSettingsLibrary = librarySettings
214
253
, appSettingsExecutables = executableSettings
254
+ , appSettingsTests = testSettings
215
255
}
216
256
217
257
getLibrarySettings :: Maybe Library -> IO (Maybe Library )
@@ -239,3 +279,20 @@ getExecutableSettings [] projectName = do
239
279
else return []
240
280
else return []
241
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