1 module UnitTests
.Distribution
.Client
.Init
.Simple
8 import Test
.Tasty
.HUnit
10 import Distribution
.Client
.Init
.Defaults
11 import Distribution
.Client
.Init
.Simple
12 import Distribution
.Client
.Init
.Types
15 import Data
.List
.NonEmpty
hiding (zip)
16 import Distribution
.Client
.Types
17 import Distribution
.Simple
.PackageIndex
hiding (fromList
)
18 import Distribution
.Types
.PackageName
19 import Distribution
.Verbosity
22 import UnitTests
.Distribution
.Client
.Init
.Utils
23 import Distribution
.Simple
.Setup
24 import qualified Data
.List
.NonEmpty
as NEL
25 import Distribution
.Types
.Dependency
26 import Distribution
.Client
.Init
.Utils
(mkPackageNameDep
, getBaseDep
)
27 import qualified Data
.Set
as Set
28 import Distribution
.Client
.Init
.FlagExtractors
(getCabalVersionNoPrompt
)
33 -> InstalledPackageIndex
36 tests v _initFlags pkgIx srcDb
= testGroup
"Distribution.Client.Init.Simple.hs"
37 [ simpleCreateProjectTests v pkgIx srcDb pkgName
40 pkgName
= mkPackageName
"simple-test"
42 simpleCreateProjectTests
44 -> InstalledPackageIndex
48 simpleCreateProjectTests v pkgIx srcDb pkgName
=
49 testGroup
"Simple createProject tests"
50 [ testCase
"Simple lib createProject - no tests" $ do
52 [ "1" -- package type: Library
53 , "simple.test" -- package dir: used for determining package name;
54 -- note that . will be replaced with - in a sanitization step,
55 -- and we get the expected "simple-test" -- regression test for #8404
56 , "simple.test" -- package dir again: the prompt monad needs extra parameter for every
57 -- IO call, and this one will be used for canonicalizePath,
58 -- which is called as a part of sanitization
62 flags
= emptyFlags
{ packageType
= Flag Library
}
63 settings
= ProjectSettings
64 (WriteOpts
False False False v
"/home/test/1" Library pkgName defaultCabalVersion
)
65 (simplePkgDesc pkgName
) (Just
$ simpleLibTarget baseDep
)
68 case _runPrompt
(createProject v pkgIx srcDb flags
) inputs
of
69 Left e
-> assertFailure
$ "Failed to create simple lib project: " ++ show e
70 Right
(settings
', _
) -> settings
@=? settings
'
72 , testCase
"Simple lib createProject - with tests" $ do
73 let inputs
= fromList
["1", "simple-test", "simple-test", "y", "1"]
74 flags
= emptyFlags
{ packageType
= Flag Library
}
75 settings
= ProjectSettings
76 (WriteOpts
False False False v
"/home/test/1" Library pkgName defaultCabalVersion
)
77 (simplePkgDesc pkgName
) (Just
$ simpleLibTarget baseDep
)
78 Nothing
(Just
$ simpleTestTarget
(Just pkgName
) baseDep
)
80 case _runPrompt
(createProject v pkgIx srcDb flags
) inputs
of
81 Left e
-> assertFailure
$ "Failed to create simple lib (with tests)project: " ++ show e
82 Right
(settings
', _
) -> settings
@=? settings
'
84 , testCase
"Simple exe createProject" $ do
85 let inputs
= fromList
["2", "simple-test", "simple-test"]
86 flags
= emptyFlags
{ packageType
= Flag Executable
}
87 settings
= ProjectSettings
88 (WriteOpts
False False False v
"/home/test/2" Executable pkgName defaultCabalVersion
)
89 (simplePkgDesc pkgName
) Nothing
90 (Just
$ simpleExeTarget Nothing baseDep
) Nothing
92 case _runPrompt
(createProject v pkgIx srcDb flags
) inputs
of
93 Left e
-> assertFailure
$ "Failed to create simple exe project: " ++ show e
94 Right
(settings
', _
) -> settings
@=? settings
'
96 , testCase
"Simple lib+exe createProject - no tests" $ do
97 let inputs
= fromList
["2", "simple-test", "simple-test", "n"]
98 flags
= emptyFlags
{ packageType
= Flag LibraryAndExecutable
}
99 settings
= ProjectSettings
100 (WriteOpts
False False False v
"/home/test/2" LibraryAndExecutable pkgName defaultCabalVersion
)
101 (simplePkgDesc pkgName
) (Just
$ simpleLibTarget baseDep
)
102 (Just
$ simpleExeTarget
(Just pkgName
) baseDep
) Nothing
104 case _runPrompt
(createProject v pkgIx srcDb flags
) inputs
of
105 Left e
-> assertFailure
$ "Failed to create simple lib+exe project: " ++ show e
106 Right
(settings
', _
) -> settings
@=? settings
'
107 , testCase
"Simple lib+exe createProject - with tests" $ do
108 let inputs
= fromList
["2", "simple-test", "simple-test", "y", "1"]
109 flags
= emptyFlags
{ packageType
= Flag LibraryAndExecutable
}
110 settings
= ProjectSettings
111 (WriteOpts
False False False v
"/home/test/2" LibraryAndExecutable pkgName defaultCabalVersion
)
112 (simplePkgDesc pkgName
) (Just
$ simpleLibTarget baseDep
)
113 (Just
$ simpleExeTarget
(Just pkgName
) baseDep
)
114 (Just
$ simpleTestTarget
(Just pkgName
) baseDep
)
116 case _runPrompt
(createProject v pkgIx srcDb flags
) inputs
of
117 Left e
-> assertFailure
$ "Failed to create simple lib+exe (with tests) project: " ++ show e
118 Right
(settings
', _
) -> settings
@=? settings
'
120 , testCase
"Simple standalone tests" $ do
121 let inputs
= fromList
["2", "simple-test", "simple-test", "y", "1"]
122 flags
= emptyFlags
{ packageType
= Flag TestSuite
}
123 settings
= ProjectSettings
124 (WriteOpts
False False False v
"/home/test/2" TestSuite pkgName defaultCabalVersion
)
125 (simplePkgDesc pkgName
) Nothing Nothing
126 (Just
$ simpleTestTarget Nothing baseDep
)
128 case _runPrompt
(createProject v pkgIx srcDb flags
) inputs
of
129 Left e
-> assertFailure
$ "Failed to create simple standalone test project: " ++ show e
130 Right
(settings
', _
) -> settings
@=? settings
'
133 baseDep
= case _runPrompt
(getBaseDep pkgIx emptyFlags
) $ fromList
[] of
134 Left e
-> error $ show e
137 -- -------------------------------------------------------------------- --
140 mkPkgDep
:: Maybe PackageName
-> [Dependency
]
141 mkPkgDep Nothing
= []
142 mkPkgDep
(Just pn
) = [mkPackageNameDep pn
]
144 simplePkgDesc
:: PackageName
-> PkgDescription
145 simplePkgDesc pkgName
= PkgDescription
149 (defaultLicense
$ getCabalVersionNoPrompt dummyFlags
)
152 (Just
$ Set
.singleton defaultChangelog
)
154 simpleLibTarget
:: [Dependency
] -> LibTarget
155 simpleLibTarget baseDep
= LibTarget
158 (myLibModule NEL
.:|
[])
161 simpleExeTarget
:: Maybe PackageName
-> [Dependency
] -> ExeTarget
162 simpleExeTarget pn baseDep
= ExeTarget
164 [defaultApplicationDir
]
166 [] [] (baseDep
++ mkPkgDep pn
) []
168 simpleTestTarget
:: Maybe PackageName
-> [Dependency
] -> TestTarget
169 simpleTestTarget pn baseDep
= TestTarget
173 [] [] (baseDep
++ mkPkgDep pn
) []