(cabal check) Add "Version signatures" test
[cabal.git] / cabal-testsuite / PackageTests / AutogenModules / SrcDist / setup.test.hs
blobb6be6672ccbd38df37ba13529590fbc5735fbfe9
1 {-# LANGUAGE CPP #-}
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 "Paths_AutogenModules", fromString "MyLibHelperModule"]
29 (libModulesAutogen gotLibrary)
30 assertEqual "executable 'autogen-modules' field does not match expected"
31 [fromString "Paths_AutogenModules", fromString "MyExeHelperModule"]
32 (exeModulesAutogen gotExecutable)
33 assertEqual "test-suite 'autogen-modules' field does not match expected"
34 [fromString "Paths_AutogenModules", fromString "MyTestHelperModule"]
35 (testModulesAutogen gotTestSuite)
36 assertEqual "benchmark 'autogen-modules' field does not match expected"
37 [fromString "Paths_AutogenModules", fromString "MyBenchHelperModule"]
38 (benchmarkModulesAutogen gotBenchmark)
40 -- Package check messages.
41 let libAutogenMsg =
42 "An 'autogen-module' is neither on 'exposed-modules' or "
43 ++ "'other-modules'"
44 let exeAutogenMsg =
45 "On executable 'Exe' an 'autogen-module' is not on "
46 ++ "'other-modules'"
47 let testAutogenMsg =
48 "On test suite 'Test' an 'autogen-module' is not on "
49 ++ "'other-modules'"
50 let benchAutogenMsg =
51 "On benchmark 'Bench' an 'autogen-module' is not on "
52 ++ "'other-modules'"
53 let pathsAutogenMsg =
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)
78 ".\\MyLibrary.hs\n"
79 ++ ".\\MyLibModule.hs\n"
80 ++ ".\\Dummy.hs\n"
81 ++ ".\\MyExeModule.hs\n"
82 ++ ".\\Dummy.hs\n"
83 ++ ".\\MyTestModule.hs\n"
84 ++ ".\\Dummy.hs\n"
85 ++ ".\\MyBenchModule.hs\n"
86 ++ "LICENSE\n"
87 ++ ".\\AutogenModules.cabal\n"
88 #else
89 "./MyLibrary.hs\n"
90 ++ "./MyLibModule.hs\n"
91 ++ "./Dummy.hs\n"
92 ++ "./MyExeModule.hs\n"
93 ++ "./Dummy.hs\n"
94 ++ "./MyTestModule.hs\n"
95 ++ "./Dummy.hs\n"
96 ++ "./MyBenchModule.hs\n"
97 ++ "LICENSE\n"
98 ++ "./AutogenModules.cabal\n"
99 #endif
100 listSourcesStrGot <- liftIO $ readFile listSourcesFileGot
101 assertEqual "sdist --list-sources does not match the expected files"
102 listSourcesStrExpected
103 listSourcesStrGot
105 return ()