2 import Test
.Cabal
.Prelude
4 import Control
.Monad
.IO.Class
5 import Distribution
.ModuleName
hiding (main
)
6 import Distribution
.Simple
.LocalBuildInfo
7 import Distribution
.PackageDescription
9 -- Test that setup parses and uses 'autogen-modules' fields correctly
10 main
= setupAndCabalTest
$ do
12 dist_dir
<- fmap testDistDir getTestEnv
14 -- Calling sdist without running configure first makes test fail with:
15 -- "Exception: Run the 'configure' command first."
16 -- This is because we are calling getPersistBuildConfig
18 configureResult
<- setup
' "configure" []
19 sdistResult
<- setup
' "sdist" []
21 -- Now check that all the correct modules were parsed.
22 lbi
<- getLocalBuildInfoM
23 let Just gotLibrary
= library
(localPkgDescr lbi
)
24 let gotExecutable
= head $ executables
(localPkgDescr lbi
)
25 let gotTestSuite
= head $ testSuites
(localPkgDescr lbi
)
26 let gotBenchmark
= head $ benchmarks
(localPkgDescr lbi
)
27 assertEqual
"library 'autogen-modules' field does not match expected"
28 [fromString
"PackageInfo_AutogenModules", fromString
"Paths_AutogenModules", fromString
"MyLibHelperModule"]
29 (libModulesAutogen gotLibrary
)
30 assertEqual
"executable 'autogen-modules' field does not match expected"
31 [fromString
"PackageInfo_AutogenModules", fromString
"Paths_AutogenModules", fromString
"MyExeHelperModule"]
32 (exeModulesAutogen gotExecutable
)
33 assertEqual
"test-suite 'autogen-modules' field does not match expected"
34 [fromString
"PackageInfo_AutogenModules", fromString
"Paths_AutogenModules", fromString
"MyTestHelperModule"]
35 (testModulesAutogen gotTestSuite
)
36 assertEqual
"benchmark 'autogen-modules' field does not match expected"
37 [fromString
"PackageInfo_AutogenModules", fromString
"Paths_AutogenModules", fromString
"MyBenchHelperModule"]
38 (benchmarkModulesAutogen gotBenchmark
)
40 -- Package check messages.
42 "An 'autogen-module' is neither on 'exposed-modules' or "
45 "On executable 'Exe' an 'autogen-module' is not on "
48 "On test suite 'Test' an 'autogen-module' is not on "
51 "On benchmark 'Bench' an 'autogen-module' is not on "
54 "Packages using 'cabal-version: 2.0' and the autogenerated"
56 -- Asserts for the undesired check messages after configure.
57 assertOutputDoesNotContain libAutogenMsg configureResult
58 assertOutputDoesNotContain exeAutogenMsg configureResult
59 assertOutputDoesNotContain testAutogenMsg configureResult
60 assertOutputDoesNotContain benchAutogenMsg configureResult
61 assertOutputDoesNotContain pathsAutogenMsg configureResult
63 -- Asserts for the undesired check messages after sdist.
64 assertOutputDoesNotContain
"Distribution quality errors:" sdistResult
65 assertOutputDoesNotContain libAutogenMsg sdistResult
66 assertOutputDoesNotContain exeAutogenMsg sdistResult
67 assertOutputDoesNotContain testAutogenMsg sdistResult
68 assertOutputDoesNotContain benchAutogenMsg sdistResult
69 assertOutputDoesNotContain
"Distribution quality warnings:" sdistResult
70 assertOutputDoesNotContain pathsAutogenMsg sdistResult
72 -- Assert sdist --list-sources output.
73 -- If called before configure fails, dist directory is not created.
74 let listSourcesFileGot
= dist_dir
++ "/" ++ "list-sources.txt"
75 setup
"sdist" ["--list-sources=" ++ listSourcesFileGot
]
76 let listSourcesStrExpected
=
77 #if defined
(mingw32_HOST_OS
)
79 ++ ".\\MyLibModule.hs\n"
81 ++ ".\\MyExeModule.hs\n"
83 ++ ".\\MyTestModule.hs\n"
85 ++ ".\\MyBenchModule.hs\n"
87 ++ ".\\AutogenModules.cabal\n"
90 ++ "./MyLibModule.hs\n"
92 ++ "./MyExeModule.hs\n"
94 ++ "./MyTestModule.hs\n"
96 ++ "./MyBenchModule.hs\n"
98 ++ "./AutogenModules.cabal\n"
100 listSourcesStrGot
<- liftIO
$ readFile listSourcesFileGot
101 assertEqual
"sdist --list-sources does not match the expected files"
102 listSourcesStrExpected