Skip to content

Commit 5e64eb4

Browse files
author
Tristan Webb
committed
Test build options are set from stack.yaml fields
Fixed some missing transforms from monoid to buildopts
1 parent 660cc84 commit 5e64eb4

4 files changed

Lines changed: 105 additions & 37 deletions

File tree

src/Stack/Config/Build.hs

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,57 @@ import Data.Maybe (fromMaybe)
77
import Stack.Types
88

99
-- | Interprets BuildOptsMonoid options.
10-
buildOptsFromMonoid :: BuildOptsMonoid -> BuildOpts
10+
buildOptsFromMonoid :: BuildOptsMonoid -> BuildOpts
1111
buildOptsFromMonoid BuildOptsMonoid{..} =
1212
defaultBuildOpts
13-
{ boptsLibProfile = fromMaybe
14-
(boptsLibProfile defaultBuildOpts)
15-
buildMonoidLibProfile
16-
, boptsExeProfile = fromMaybe
17-
(boptsExeProfile defaultBuildOpts)
18-
buildMonoidExeProfile
19-
, boptsHaddock = fromMaybe
20-
(boptsHaddock defaultBuildOpts)
21-
buildMonoidHaddock
22-
, boptsInstallExes = fromMaybe
23-
(boptsInstallExes defaultBuildOpts)
24-
buildMonoidInstallExes
25-
, boptsPreFetch = fromMaybe
26-
(boptsPreFetch defaultBuildOpts)
27-
buildMonoidPreFetch
28-
, boptsForceDirty = fromMaybe
29-
(boptsForceDirty defaultBuildOpts)
30-
buildMonoidForceDirty
31-
, boptsTests = fromMaybe
32-
(boptsTests defaultBuildOpts)
33-
buildMonoidTests
34-
, boptsBenchmarks = fromMaybe
35-
(boptsBenchmarks defaultBuildOpts)
36-
buildMonoidBenchmarks
37-
, boptsReconfigure = fromMaybe
38-
(boptsReconfigure defaultBuildOpts)
39-
buildMonoidReconfigure
40-
, boptsCabalVerbose = fromMaybe
41-
(boptsCabalVerbose defaultBuildOpts)
42-
buildMonoidCabalVerbose
43-
}
13+
{ boptsLibProfile = fromMaybe
14+
(boptsLibProfile defaultBuildOpts)
15+
buildMonoidLibProfile
16+
, boptsExeProfile = fromMaybe
17+
(boptsExeProfile defaultBuildOpts)
18+
buildMonoidExeProfile
19+
, boptsHaddock = fromMaybe
20+
(boptsHaddock defaultBuildOpts)
21+
buildMonoidHaddock
22+
, boptsHaddockDeps = buildMonoidHaddockDeps
23+
, boptsInstallExes = fromMaybe
24+
(boptsInstallExes defaultBuildOpts)
25+
buildMonoidInstallExes
26+
, boptsPreFetch = fromMaybe
27+
(boptsPreFetch defaultBuildOpts)
28+
buildMonoidPreFetch
29+
, boptsKeepGoing = buildMonoidKeepGoing
30+
, boptsForceDirty = fromMaybe
31+
(boptsForceDirty defaultBuildOpts)
32+
buildMonoidForceDirty
33+
, boptsTests = fromMaybe (boptsTests defaultBuildOpts) buildMonoidTests
34+
, boptsTestOpts = testOptsFromMonoid buildMonoidTestOpts
35+
, boptsBenchmarks = fromMaybe
36+
(boptsBenchmarks defaultBuildOpts)
37+
buildMonoidBenchmarks
38+
, boptsBenchmarkOpts = benchmarkOptsFromMonoid buildMonoidBenchmarkOpts
39+
, boptsReconfigure = fromMaybe
40+
(boptsReconfigure defaultBuildOpts)
41+
buildMonoidReconfigure
42+
, boptsCabalVerbose = fromMaybe
43+
(boptsCabalVerbose defaultBuildOpts)
44+
buildMonoidCabalVerbose
45+
}
46+
47+
testOptsFromMonoid :: TestOptsMonoid -> TestOpts
48+
testOptsFromMonoid TestOptsMonoid{..} =
49+
defaultTestOpts
50+
{ toRerunTests = fromMaybe (toRerunTests defaultTestOpts) toMonoidRerunTests
51+
, toAdditionalArgs = toMonoidAdditionalArgs
52+
, toCoverage = fromMaybe (toCoverage defaultTestOpts) toMonoidCoverage
53+
, toDisableRun = fromMaybe (toDisableRun defaultTestOpts) toMonoidDisableRun
54+
}
55+
56+
benchmarkOptsFromMonoid :: BenchmarkOptsMonoid -> BenchmarkOpts
57+
benchmarkOptsFromMonoid BenchmarkOptsMonoid{..} =
58+
defaultBenchmarkOpts
59+
{ beoAdditionalArgs = beoMonoidAdditionalArgs
60+
, beoDisableRun = fromMaybe
61+
(beoDisableRun defaultBenchmarkOpts)
62+
beoMonoidDisableRun
63+
}

src/Stack/Options.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ buildOptsMonoidParser hide0 =
306306
, buildMonoidExeProfile = Just True
307307
, buildMonoidBenchmarkOpts = bopts
308308
{ beoMonoidAdditionalArgs = beoMonoidAdditionalArgs bopts <>
309-
Just (unwords additionalArgs)
309+
Just (" " <> unwords additionalArgs)
310310
}
311311
, buildMonoidTestOpts = topts
312312
{ toMonoidAdditionalArgs = (toMonoidAdditionalArgs topts) <>
@@ -321,8 +321,7 @@ buildOptsMonoidParser hide0 =
321321
topts =
322322
buildMonoidTestOpts opts
323323
additionalArgs =
324-
"+RTS" :
325-
catMaybes [trac, prof]
324+
"+RTS" : catMaybes [trac, prof, Just "-RTS"]
326325
trac =
327326
if tracing
328327
then Just "-xc"

src/Stack/Types/Config/Build.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,5 +344,3 @@ data FileWatchOpts
344344
| FileWatch
345345
| FileWatchPoll
346346
deriving (Show,Eq)
347-
348-

src/test/Stack/ConfigSpec.hs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,32 @@ sampleConfig =
2727
"resolver: lts-2.10\n" ++
2828
"packages: ['.']\n"
2929

30+
buildOptsConfig :: String
31+
buildOptsConfig =
32+
"resolver: lts-2.10\n" ++
33+
"packages: ['.']\n" ++
34+
"build:\n" ++
35+
" library-profiling: true\n" ++
36+
" executable-profiling: true\n" ++
37+
" haddock: true\n" ++
38+
" haddock-deps: true\n" ++
39+
" copy-bins: true\n" ++
40+
" prefetch: true\n" ++
41+
" force-dirty: true\n" ++
42+
" keep-going: true\n" ++
43+
" test: true\n" ++
44+
" test-arguments:\n" ++
45+
" rerun-tests: true\n" ++
46+
" additional-args: ['-fprof']\n" ++
47+
" coverage: true\n" ++
48+
" no-run-tests: true\n" ++
49+
" bench: true\n" ++
50+
" benchmark-opts:\n" ++
51+
" benchmark-arguments: -O2\n" ++
52+
" no-run-benchmarks: true\n" ++
53+
" reconfigure: true\n" ++
54+
" cabal-verbose: true\n"
55+
3056
stackDotYaml :: Path Rel File
3157
stackDotYaml = $(mkRelFile "stack.yaml")
3258

@@ -43,6 +69,9 @@ setup = do
4369
teardown :: T -> IO ()
4470
teardown _ = return ()
4571

72+
noException :: Selector SomeException
73+
noException = const False
74+
4675
spec :: Spec
4776
spec = beforeAll setup $ afterAll teardown $ do
4877
let logLevel = LevelDebug
@@ -73,6 +102,28 @@ spec = beforeAll setup $ afterAll teardown $ do
73102
-- TODO(danburton): more specific test for exception
74103
loadConfig' manager `shouldThrow` anyException
75104

105+
it "parses build config options" $ \T{..} -> inTempDir $ do
106+
writeFile (toFilePath stackDotYaml) buildOptsConfig
107+
BuildOpts{..} <- configBuild . lcConfig <$> loadConfig' manager
108+
boptsLibProfile `shouldBe` True
109+
boptsExeProfile `shouldBe` True
110+
boptsHaddock `shouldBe` True
111+
boptsHaddockDeps `shouldBe` (Just True)
112+
boptsInstallExes `shouldBe` True
113+
boptsPreFetch `shouldBe` True
114+
boptsKeepGoing `shouldBe` (Just True)
115+
boptsForceDirty `shouldBe` True
116+
boptsTests `shouldBe` True
117+
boptsTestOpts `shouldBe` (TestOpts {toRerunTests = True
118+
,toAdditionalArgs = ["-fprof"]
119+
,toCoverage = True
120+
,toDisableRun = True})
121+
boptsBenchmarks `shouldBe` True
122+
boptsBenchmarkOpts `shouldBe` (BenchmarkOpts {beoAdditionalArgs = Just "-O2"
123+
,beoDisableRun = True})
124+
boptsReconfigure `shouldBe` True
125+
boptsCabalVerbose `shouldBe` True
126+
76127
it "finds the config file in a parent directory" $ \T{..} -> inTempDir $ do
77128
writeFile (toFilePath stackDotYaml) sampleConfig
78129
parentDir <- getCurrentDirectory >>= parseAbsDir

0 commit comments

Comments
 (0)