validate dependabot configuration
[cabal.git] / cabal-install / tests / UnitTests / Distribution / Client / Init / Interactive.hs
blob9ba237cbadc82e88e9b09fefeab82c22bd10500b
1 module UnitTests.Distribution.Client.Init.Interactive
2 ( tests
3 ) where
5 import Test.Tasty
6 import Test.Tasty.HUnit
7 import Prelude as P
9 import Distribution.Client.Init.Defaults
10 import Distribution.Client.Init.Interactive.Command
11 import Distribution.Client.Init.Types
13 import qualified Distribution.SPDX as SPDX
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.Types.Version
20 import Distribution.Verbosity
22 import Language.Haskell.Extension
24 import qualified Data.Set as Set
25 import Distribution.CabalSpecVersion
26 import Distribution.Client.Init.FlagExtractors
27 import Distribution.FieldGrammar.Newtypes
28 import Distribution.Simple.Setup
29 import UnitTests.Distribution.Client.Init.Utils
31 -- -------------------------------------------------------------------- --
32 -- Init Test main
34 tests
35 :: Verbosity
36 -> InitFlags
37 -> InstalledPackageIndex
38 -> SourcePackageDb
39 -> TestTree
40 tests _v initFlags pkgIx srcDb =
41 testGroup
42 "Distribution.Client.Init.Interactive.Command.hs"
43 [ createProjectTest pkgIx srcDb
44 , fileCreatorTests pkgIx srcDb pkgName
45 , interactiveTests srcDb
47 where
48 pkgName =
49 evalPrompt (packageNamePrompt srcDb initFlags) $
50 fromList ["test-package", "y"]
52 -- pkgNm = evalPrompt (getPackageName srcDb initFlags) $ fromList ["test-package", "y"]
54 createProjectTest
55 :: InstalledPackageIndex
56 -> SourcePackageDb
57 -> TestTree
58 createProjectTest pkgIx srcDb =
59 testGroup
60 "createProject tests"
61 [ testGroup
62 "with flags"
63 [ testCase "Check the interactive workflow" $ do
64 let dummyFlags' =
65 dummyFlags
66 { packageType = Flag LibraryAndExecutable
67 , minimal = Flag False
68 , overwrite = Flag False
69 , packageDir = Flag "/home/test/test-package"
70 , extraSrc = NoFlag
71 , exposedModules = Flag []
72 , otherModules = Flag []
73 , otherExts = Flag []
74 , buildTools = Flag []
75 , mainIs = Flag "quxApp/Main.hs"
76 , dependencies = Flag []
79 case (runPrompt $ createProject silent pkgIx srcDb dummyFlags') (fromList ["[]", "3", "quxTest/Main.hs"]) of
80 Right (ProjectSettings opts desc (Just lib) (Just exe) (Just test), _) -> do
81 _optOverwrite opts @?= False
82 _optMinimal opts @?= False
83 _optNoComments opts @?= True
84 _optVerbosity opts @?= silent
85 _optPkgDir opts @?= "/home/test/test-package"
86 _optPkgType opts @?= LibraryAndExecutable
87 _optPkgName opts @?= mkPackageName "QuxPackage"
89 _pkgCabalVersion desc @?= CabalSpecV2_2
90 _pkgName desc @?= mkPackageName "QuxPackage"
91 _pkgVersion desc @?= mkVersion [4, 2, 6]
92 _pkgLicense desc @?! (SpecLicense . Left $ SPDX.NONE)
93 _pkgAuthor desc @?= "Foobar"
94 _pkgEmail desc @?= "foobar@qux.com"
95 _pkgHomePage desc @?= "qux.com"
96 _pkgSynopsis desc @?= "We are Qux, and this is our package"
97 _pkgCategory desc @?= "Control"
98 _pkgExtraSrcFiles desc @?= mempty
99 _pkgExtraDocFiles desc @?= pure (Set.singleton "CHANGELOG.md")
101 _libSourceDirs lib @?= ["quxSrc"]
102 _libLanguage lib @?= Haskell98
103 _libExposedModules lib @?= myLibModule :| []
104 _libOtherModules lib @?= []
105 _libOtherExts lib @?= []
106 _libDependencies lib @?= []
107 _libBuildTools lib @?= []
109 _exeMainIs exe @?= HsFilePath "quxApp/Main.hs" Standard
110 _exeApplicationDirs exe @?= ["quxApp"]
111 _exeLanguage exe @?= Haskell98
112 _exeOtherModules exe @?= []
113 _exeOtherExts exe @?= []
114 _exeDependencies exe @?! []
115 _exeBuildTools exe @?= []
117 _testMainIs test @?= HsFilePath "quxTest/Main.hs" Standard
118 _testDirs test @?= ["quxTest"]
119 _testLanguage test @?= Haskell98
120 _testOtherModules test @?= []
121 _testOtherExts test @?= []
122 _testDependencies test @?! []
123 _testBuildTools test @?= []
124 Right (ProjectSettings _ _ lib exe test, _) -> do
125 lib @?! Nothing
126 exe @?! Nothing
127 test @?! Nothing
128 Left e -> assertFailure $ show e
130 , testGroup
131 "with tests"
132 [ testCase "Check the interactive library and executable workflow" $ do
133 let inputs =
134 fromList
135 -- package type
136 [ "3"
137 , -- overwrite (not asked, pristine folder)
138 "test-package-dir"
139 , "[]"
140 , -- package dir
141 "test-package"
142 , -- package description
143 -- cabal version
145 , -- package name
146 "test-package"
147 , "test-package"
148 , "test-package"
149 , -- version
150 "3.1.2.3"
151 , -- license
153 , -- author
154 "git username"
155 , "Foobar"
156 , -- email
157 "git email"
158 , "foobar@qux.com"
159 , -- homepage
160 "qux.com"
161 , -- synopsis
162 "Qux's package"
163 , -- category
165 , -- library target
166 -- source dir
168 , -- language
170 , -- executable target
171 -- main file
173 , -- application dir
175 , -- language
177 , -- test target
179 , -- main file
181 , -- test dir
182 "test"
183 , -- language
185 , -- comments
189 case (runPrompt $ createProject silent pkgIx srcDb emptyFlags) inputs of
190 Right (ProjectSettings opts desc (Just lib) (Just exe) (Just test), _) -> do
191 _optOverwrite opts @?= False
192 _optMinimal opts @?= False
193 _optNoComments opts @?= False
194 _optVerbosity opts @?= silent
195 _optPkgDir opts @?= "/home/test/test-package"
196 _optPkgType opts @?= LibraryAndExecutable
197 _optPkgName opts @?= mkPackageName "test-package"
199 _pkgCabalVersion desc @?= CabalSpecV2_4
200 _pkgName desc @?= mkPackageName "test-package"
201 _pkgVersion desc @?= mkVersion [3, 1, 2, 3]
202 _pkgLicense desc @?! (SpecLicense . Left $ SPDX.NONE)
203 _pkgAuthor desc @?= "Foobar"
204 _pkgEmail desc @?= "foobar@qux.com"
205 _pkgHomePage desc @?= "qux.com"
206 _pkgSynopsis desc @?= "Qux's package"
207 _pkgCategory desc @?= "Control"
208 _pkgExtraSrcFiles desc @?= mempty
209 _pkgExtraDocFiles desc @?= pure (Set.singleton "CHANGELOG.md")
211 _libSourceDirs lib @?= ["src"]
212 _libLanguage lib @?= Haskell98
213 _libExposedModules lib @?= myLibModule :| []
214 _libOtherModules lib @?= []
215 _libOtherExts lib @?= []
216 _libDependencies lib @?! []
217 _libBuildTools lib @?= []
219 _exeMainIs exe @?= HsFilePath "Main.hs" Standard
220 _exeApplicationDirs exe @?= ["exe"]
221 _exeLanguage exe @?= Haskell98
222 _exeOtherModules exe @?= []
223 _exeOtherExts exe @?= []
224 _exeDependencies exe @?! []
225 _exeBuildTools exe @?= []
227 _testMainIs test @?= HsFilePath "Main.hs" Standard
228 _testDirs test @?= ["test"]
229 _testLanguage test @?= Haskell2010
230 _testOtherModules test @?= []
231 _testOtherExts test @?= []
232 _testDependencies test @?! []
233 _testBuildTools test @?= []
234 Right (ProjectSettings _ _ lib exe test, _) -> do
235 lib @?! Nothing
236 exe @?! Nothing
237 test @?! Nothing
238 Left e -> assertFailure $ show e
239 , testCase "Check the interactive library workflow" $ do
240 let inputs =
241 fromList
242 -- package type
243 [ "1"
244 , -- overwrite (not asked, pristine folder)
245 "test-package-dir"
246 , "[]"
247 , -- package dir
248 "test-package"
249 , -- package description
250 -- cabal version
252 , -- package name
253 "test-package"
254 , "test-package"
255 , "test-package"
256 , -- version
257 "3.1.2.3"
258 , -- license
260 , -- author
261 "git username"
262 , "Foobar"
263 , -- email
264 "git email"
265 , "foobar@qux.com"
266 , -- homepage
267 "qux.com"
268 , -- synopsis
269 "Qux's package"
270 , -- category
272 , -- library target
273 -- source dir
275 , -- language
277 , -- test target
279 , -- main file
281 , -- test dir
282 "test"
283 , -- language
285 , -- comments
289 case (runPrompt $ createProject silent pkgIx srcDb emptyFlags) inputs of
290 Right (ProjectSettings opts desc (Just lib) Nothing (Just test), _) -> do
291 _optOverwrite opts @?= False
292 _optMinimal opts @?= False
293 _optNoComments opts @?= False
294 _optVerbosity opts @?= silent
295 _optPkgDir opts @?= "/home/test/test-package"
296 _optPkgType opts @?= Library
297 _optPkgName opts @?= mkPackageName "test-package"
299 _pkgCabalVersion desc @?= CabalSpecV2_4
300 _pkgName desc @?= mkPackageName "test-package"
301 _pkgVersion desc @?= mkVersion [3, 1, 2, 3]
302 _pkgLicense desc @?! (SpecLicense . Left $ SPDX.NONE)
303 _pkgAuthor desc @?= "Foobar"
304 _pkgEmail desc @?= "foobar@qux.com"
305 _pkgHomePage desc @?= "qux.com"
306 _pkgSynopsis desc @?= "Qux's package"
307 _pkgCategory desc @?= "Control"
308 _pkgExtraSrcFiles desc @?= mempty
309 _pkgExtraDocFiles desc @?= pure (Set.singleton "CHANGELOG.md")
311 _libSourceDirs lib @?= ["src"]
312 _libLanguage lib @?= Haskell98
313 _libExposedModules lib @?= myLibModule :| []
314 _libOtherModules lib @?= []
315 _libOtherExts lib @?= []
316 _libDependencies lib @?! []
317 _libBuildTools lib @?= []
319 _testMainIs test @?= HsFilePath "Main.hs" Standard
320 _testDirs test @?= ["test"]
321 _testLanguage test @?= Haskell2010
322 _testOtherModules test @?= []
323 _testOtherExts test @?= []
324 _testDependencies test @?! []
325 _testBuildTools test @?= []
326 Right (ProjectSettings _ _ lib exe test, _) -> do
327 lib @?! Nothing
328 exe @?= Nothing
329 test @?! Nothing
330 Left e -> assertFailure $ show e
331 , testCase "Check the interactive library workflow" $ do
332 let inputs =
333 fromList
334 -- package type
335 [ "4"
336 , -- overwrite (not asked, pristine folder)
337 "test-package-dir"
338 , "[]"
339 , -- package dir
340 "test-package"
341 , -- package description
342 -- cabal version
344 , -- package name
345 "test-package"
346 , "test-package"
347 , "test-package"
348 , -- version
349 "3.1.2.3"
350 , -- license
352 , -- author
353 "git username"
354 , "Foobar"
355 , -- email
356 "git email"
357 , "foobar@qux.com"
358 , -- homepage
359 "qux.com"
360 , -- synopsis
361 "Qux's package"
362 , -- category
364 , -- test target
365 -- main file
367 , -- test dir
368 "test"
369 , -- language
371 , -- comments
375 case (runPrompt $ createProject silent pkgIx srcDb emptyFlags) inputs of
376 Right (ProjectSettings opts desc Nothing Nothing (Just test), _) -> do
377 _optOverwrite opts @?= False
378 _optMinimal opts @?= False
379 _optNoComments opts @?= False
380 _optVerbosity opts @?= silent
381 _optPkgDir opts @?= "/home/test/test-package"
382 _optPkgType opts @?= TestSuite
383 _optPkgName opts @?= mkPackageName "test-package"
385 _pkgCabalVersion desc @?= CabalSpecV2_4
386 _pkgName desc @?= mkPackageName "test-package"
387 _pkgVersion desc @?= mkVersion [3, 1, 2, 3]
388 _pkgLicense desc @?! (SpecLicense . Left $ SPDX.NONE)
389 _pkgAuthor desc @?= "Foobar"
390 _pkgEmail desc @?= "foobar@qux.com"
391 _pkgHomePage desc @?= "qux.com"
392 _pkgSynopsis desc @?= "Qux's package"
393 _pkgCategory desc @?= "Control"
394 _pkgExtraSrcFiles desc @?= mempty
395 _pkgExtraDocFiles desc @?= pure (Set.singleton "CHANGELOG.md")
397 _testMainIs test @?= HsFilePath "Main.hs" Standard
398 _testDirs test @?= ["test"]
399 _testLanguage test @?= Haskell2010
400 _testOtherModules test @?= []
401 _testOtherExts test @?= []
402 _testDependencies test @?! []
403 _testBuildTools test @?= []
404 Right (ProjectSettings _ _ lib exe test, _) -> do
405 lib @?= Nothing
406 exe @?= Nothing
407 test @?! Nothing
408 Left e -> assertFailure $ show e
410 , testGroup
411 "without tests"
412 [ testCase "Check the interactive library and executable workflow" $ do
413 let inputs =
414 fromList
415 -- package type
416 [ "3"
417 , -- overwrite (not asked, pristine folder)
418 "test-package-dir"
419 , "[]"
420 , -- package dir
421 "test-package"
422 , -- package description
423 -- cabal version
425 , -- package name
426 "test-package"
427 , "test-package"
428 , "test-package"
429 , -- version
430 "3.1.2.3"
431 , -- license
433 , -- author
434 "git username"
435 , "Foobar"
436 , -- email
437 "git email"
438 , "foobar@qux.com"
439 , -- homepage
440 "qux.com"
441 , -- synopsis
442 "Qux's package"
443 , -- category
445 , -- library target
446 -- source dir
448 , -- language
450 , -- executable target
451 -- main file
453 , -- application dir
455 , -- language
457 , -- test suite
459 , -- comments
463 case (runPrompt $ createProject silent pkgIx srcDb emptyFlags) inputs of
464 Right (ProjectSettings opts desc (Just lib) (Just exe) Nothing, _) -> do
465 _optOverwrite opts @?= False
466 _optMinimal opts @?= False
467 _optNoComments opts @?= False
468 _optVerbosity opts @?= silent
469 _optPkgDir opts @?= "/home/test/test-package"
470 _optPkgType opts @?= LibraryAndExecutable
471 _optPkgName opts @?= mkPackageName "test-package"
473 _pkgCabalVersion desc @?= CabalSpecV2_4
474 _pkgName desc @?= mkPackageName "test-package"
475 _pkgVersion desc @?= mkVersion [3, 1, 2, 3]
476 _pkgLicense desc @?! (SpecLicense . Left $ SPDX.NONE)
477 _pkgAuthor desc @?= "Foobar"
478 _pkgEmail desc @?= "foobar@qux.com"
479 _pkgHomePage desc @?= "qux.com"
480 _pkgSynopsis desc @?= "Qux's package"
481 _pkgCategory desc @?= "Control"
482 _pkgExtraSrcFiles desc @?= mempty
483 _pkgExtraDocFiles desc @?= pure (Set.singleton "CHANGELOG.md")
485 _libSourceDirs lib @?= ["src"]
486 _libLanguage lib @?= Haskell98
487 _libExposedModules lib @?= myLibModule :| []
488 _libOtherModules lib @?= []
489 _libOtherExts lib @?= []
490 _libDependencies lib @?! []
491 _libBuildTools lib @?= []
493 _exeMainIs exe @?= HsFilePath "Main.hs" Standard
494 _exeApplicationDirs exe @?= ["exe"]
495 _exeLanguage exe @?= Haskell98
496 _exeOtherModules exe @?= []
497 _exeOtherExts exe @?= []
498 _exeDependencies exe @?! []
499 _exeBuildTools exe @?= []
500 Right (ProjectSettings _ _ lib exe test, _) -> do
501 lib @?! Nothing
502 exe @?! Nothing
503 test @?= Nothing
504 Left e -> assertFailure $ show e
505 , testCase "Check the interactive library workflow" $ do
506 let inputs =
507 fromList
508 -- package type
509 [ "1"
510 , -- overwrite (not asked, pristine folder)
511 "test-package-dir"
512 , "[]"
513 , -- package dir
514 "test-package"
515 , -- package description
516 -- cabal version
518 , -- package name
519 "test-package"
520 , "test-package"
521 , "test-package"
522 , -- version
523 "3.1.2.3"
524 , -- license
526 , -- author
527 "git username"
528 , "Foobar"
529 , -- email
530 "git email"
531 , "foobar@qux.com"
532 , -- homepage
533 "qux.com"
534 , -- synopsis
535 "Qux's package"
536 , -- category
538 , -- library target
539 -- source dir
541 , -- language
543 , -- test suite
545 , -- comments
549 case (runPrompt $ createProject silent pkgIx srcDb emptyFlags) inputs of
550 Right (ProjectSettings opts desc (Just lib) Nothing Nothing, _) -> do
551 _optOverwrite opts @?= False
552 _optMinimal opts @?= False
553 _optNoComments opts @?= False
554 _optVerbosity opts @?= silent
555 _optPkgDir opts @?= "/home/test/test-package"
556 _optPkgType opts @?= Library
557 _optPkgName opts @?= mkPackageName "test-package"
559 _pkgCabalVersion desc @?= CabalSpecV2_4
560 _pkgName desc @?= mkPackageName "test-package"
561 _pkgVersion desc @?= mkVersion [3, 1, 2, 3]
562 _pkgLicense desc @?! (SpecLicense . Left $ SPDX.NONE)
563 _pkgAuthor desc @?= "Foobar"
564 _pkgEmail desc @?= "foobar@qux.com"
565 _pkgHomePage desc @?= "qux.com"
566 _pkgSynopsis desc @?= "Qux's package"
567 _pkgCategory desc @?= "Control"
568 _pkgExtraSrcFiles desc @?= mempty
569 _pkgExtraDocFiles desc @?= pure (Set.singleton "CHANGELOG.md")
571 _libSourceDirs lib @?= ["src"]
572 _libLanguage lib @?= Haskell98
573 _libExposedModules lib @?= myLibModule :| []
574 _libOtherModules lib @?= []
575 _libOtherExts lib @?= []
576 _libDependencies lib @?! []
577 _libBuildTools lib @?= []
578 Right (ProjectSettings _ _ lib exe test, _) -> do
579 lib @?! Nothing
580 exe @?= Nothing
581 test @?= Nothing
582 Left e -> assertFailure $ show e
583 , testCase "Check the interactive library workflow - cabal < 1.18" $ do
584 let inputs =
585 fromList
586 -- package type
587 [ "1"
588 , -- overwrite (not asked, pristine folder)
589 "test-package-dir"
590 , "[]"
591 , -- package dir
592 "test-package"
593 , -- package description
594 -- cabal version
596 , -- package name
597 "test-package"
598 , "test-package"
599 , "test-package"
600 , -- version
601 "3.1.2.3"
602 , -- license
604 , -- author
605 "git username"
606 , "Foobar"
607 , -- email
608 "git email"
609 , "foobar@qux.com"
610 , -- homepage
611 "qux.com"
612 , -- synopsis
613 "Qux's package"
614 , -- category
616 , -- library target
617 -- source dir
619 , -- language
621 , -- test suite
623 , -- comments
627 flags =
628 emptyFlags
629 { cabalVersion = Flag CabalSpecV1_10
630 , extraDoc = Flag [defaultChangelog]
631 , extraSrc = Flag ["README.md"]
634 case (runPrompt $ createProject silent pkgIx srcDb flags) inputs of
635 Right (ProjectSettings opts desc (Just lib) Nothing Nothing, _) -> do
636 _optOverwrite opts @?= False
637 _optMinimal opts @?= False
638 _optNoComments opts @?= False
639 _optVerbosity opts @?= silent
640 _optPkgDir opts @?= "/home/test/test-package"
641 _optPkgType opts @?= Library
642 _optPkgName opts @?= mkPackageName "test-package"
644 _pkgCabalVersion desc @?= CabalSpecV1_10
645 _pkgName desc @?= mkPackageName "test-package"
646 _pkgVersion desc @?= mkVersion [3, 1, 2, 3]
647 _pkgLicense desc @?! (SpecLicense . Left $ SPDX.NONE)
648 _pkgAuthor desc @?= "Foobar"
649 _pkgEmail desc @?= "foobar@qux.com"
650 _pkgHomePage desc @?= "qux.com"
651 _pkgSynopsis desc @?= "Qux's package"
652 _pkgCategory desc @?= "Control"
653 _pkgExtraSrcFiles desc @?= Set.fromList [defaultChangelog, "README.md"]
654 _pkgExtraDocFiles desc @?= Nothing
656 _libSourceDirs lib @?= ["src"]
657 _libLanguage lib @?= Haskell98
658 _libExposedModules lib @?= myLibModule :| []
659 _libOtherModules lib @?= []
660 _libOtherExts lib @?= []
661 _libDependencies lib @?! []
662 _libBuildTools lib @?= []
663 Right (ProjectSettings _ _ lib exe test, _) -> do
664 lib @?! Nothing
665 exe @?= Nothing
666 test @?= Nothing
667 Left e -> assertFailure $ show e
668 , testCase "Check the interactive executable workflow" $ do
669 let inputs =
670 fromList
671 -- package type
672 [ "2"
673 , -- overwrite (not asked, pristine folder)
674 "test-package-dir"
675 , "[]"
676 , -- package dir
677 "test-package"
678 , -- package description
679 -- cabal version
681 , -- package name
682 "test-package"
683 , "test-package"
684 , "test-package"
685 , -- version
686 "3.1.2.3"
687 , -- license
689 , -- author
690 "git username"
691 , "Foobar"
692 , -- email
693 "git email"
694 , "foobar@qux.com"
695 , -- homepage
696 "qux.com"
697 , -- synopsis
698 "Qux's package"
699 , -- category
701 , -- executable target
702 -- main file
704 , -- application dir
706 , -- language
708 , -- comments
712 case (runPrompt $ createProject silent pkgIx srcDb emptyFlags) inputs of
713 Right (ProjectSettings opts desc Nothing (Just exe) Nothing, _) -> do
714 _optOverwrite opts @?= False
715 _optMinimal opts @?= False
716 _optNoComments opts @?= False
717 _optVerbosity opts @?= silent
718 _optPkgDir opts @?= "/home/test/test-package"
719 _optPkgType opts @?= Executable
720 _optPkgName opts @?= mkPackageName "test-package"
722 _pkgCabalVersion desc @?= CabalSpecV2_4
723 _pkgName desc @?= mkPackageName "test-package"
724 _pkgVersion desc @?= mkVersion [3, 1, 2, 3]
725 _pkgLicense desc @?! (SpecLicense . Left $ SPDX.NONE)
726 _pkgAuthor desc @?= "Foobar"
727 _pkgEmail desc @?= "foobar@qux.com"
728 _pkgHomePage desc @?= "qux.com"
729 _pkgSynopsis desc @?= "Qux's package"
730 _pkgCategory desc @?= "Control"
731 _pkgExtraSrcFiles desc @?= mempty
732 _pkgExtraDocFiles desc @?= pure (Set.singleton "CHANGELOG.md")
734 _exeMainIs exe @?= HsFilePath "Main.hs" Standard
735 _exeApplicationDirs exe @?= ["exe"]
736 _exeLanguage exe @?= Haskell98
737 _exeOtherModules exe @?= []
738 _exeOtherExts exe @?= []
739 _exeDependencies exe @?! []
740 _exeBuildTools exe @?= []
741 Right (ProjectSettings _ _ lib exe test, _) -> do
742 lib @?= Nothing
743 exe @?! Nothing
744 test @?= Nothing
745 Left e -> assertFailure $ show e
749 fileCreatorTests :: InstalledPackageIndex -> SourcePackageDb -> PackageName -> TestTree
750 fileCreatorTests pkgIx srcDb _pkgName =
751 testGroup
752 "generators"
753 [ testGroup
754 "genPkgDescription"
755 [ testCase "Check common package flags workflow" $ do
756 let inputs =
757 fromList
758 [ "1" -- pick the first cabal version in the list
759 , "my-test-package" -- package name
760 , "my-test-package" -- current dir for the purpose of guessing the package name
761 , "y" -- "yes to prompt internal to package name"
762 , "0.2.0.1" -- package version
763 , "2" -- pick the second license in the list
764 , "git username" -- name guessed by calling "git config user.name"
765 , "Foobar" -- author name
766 , "git email" -- email guessed by calling "git config user.email"
767 , "foobar@qux.com" -- maintainer email
768 , "qux.com" -- package homepage
769 , "Qux's package" -- package synopsis
770 , "3" -- pick the third category in the list
772 runGenTest inputs $ genPkgDescription emptyFlags srcDb
774 , testGroup
775 "genLibTarget"
776 [ testCase "Check library package flags workflow" $ do
777 let inputs =
778 fromList
779 [ "1" -- pick the first source directory in the list
780 , "2" -- pick the second language in the list
783 runGenTest inputs $ genLibTarget emptyFlags pkgIx
785 , testGroup
786 "genExeTarget"
787 [ testCase "Check executable package flags workflow" $ do
788 let inputs =
789 fromList
790 [ "1" -- pick the first main file option in the list
791 , "2" -- pick the second application directory in the list
792 , "1" -- pick the first language in the list
795 runGenTest inputs $ genExeTarget emptyFlags pkgIx
797 , testGroup
798 "genTestTarget"
799 [ testCase "Check test package flags workflow" $ do
800 let inputs =
801 fromList
802 [ "y" -- say yes to tests
803 , "1" -- pick the first main file option in the list
804 , "test" -- package test dir
805 , "1" -- pick the first language in the list
808 runGenTest inputs $ genTestTarget emptyFlags pkgIx
811 where
812 runGenTest inputs go = case runPrompt go inputs of
813 Left e -> assertFailure $ show e
814 Right{} -> return ()
816 interactiveTests :: SourcePackageDb -> TestTree
817 interactiveTests srcDb =
818 testGroup
819 "Check top level getter functions"
820 [ testGroup
821 "Simple prompt tests"
822 [ testGroup
823 "Check packageNamePrompt output"
824 [ testSimplePrompt
825 "New package name 1"
826 (packageNamePrompt srcDb)
827 (mkPackageName "test-package")
828 [ "test-package"
829 , "test-package"
830 , "test-package"
832 , testSimplePrompt
833 "New package name 2"
834 (packageNamePrompt srcDb)
835 (mkPackageName "test-package")
836 [ "test-package"
837 , "test-package"
838 , ""
840 , testSimplePrompt
841 "Existing package name 1"
842 (packageNamePrompt srcDb)
843 (mkPackageName "test-package")
844 [ "test-package"
845 , "test-package"
846 , "cabal-install"
847 , "y"
848 , "test-package"
850 , testSimplePrompt
851 "Existing package name 2"
852 (packageNamePrompt srcDb)
853 (mkPackageName "cabal-install")
854 [ "test-package"
855 , "test-package"
856 , "cabal-install"
857 , "n"
860 , testGroup
861 "Check mainFilePrompt output"
862 [ testSimplePrompt
863 "New valid main file"
864 mainFilePrompt
865 defaultMainIs
866 [ "1"
868 , testSimplePrompt
869 "New valid other main file"
870 mainFilePrompt
871 (HsFilePath "Main.hs" Standard)
872 [ "3"
873 , "Main.hs"
875 , testSimplePrompt
876 "Invalid other main file"
877 mainFilePrompt
878 (HsFilePath "Main.lhs" Literate)
879 [ "3"
880 , "Yoink.jl"
881 , "2"
884 , testGroup
885 "Check versionPrompt output"
886 [ testSimplePrompt
887 "Proper PVP"
888 versionPrompt
889 (mkVersion [0, 3, 1, 0])
890 [ "0.3.1.0"
892 , testSimplePrompt
893 "No PVP"
894 versionPrompt
895 (mkVersion [0, 3, 1, 0])
896 [ "yee-haw"
897 , "0.3.1.0"
900 , testGroup
901 "Check synopsisPrompt output"
902 [ testSimplePrompt
904 synopsisPrompt
905 "We are Qux, and this is our package"
906 ["We are Qux, and this is our package"]
907 , testSimplePrompt
909 synopsisPrompt
910 "Resistance is futile, you will be assimilated"
911 ["Resistance is futile, you will be assimilated"]
913 , testSimplePrompt
914 "Check authorPrompt output (name supplied by the user)"
915 authorPrompt
916 "Foobar"
917 ["git username", "Foobar"]
918 , testSimplePrompt
919 "Check authorPrompt output (name guessed from git config)"
920 authorPrompt
921 "git username"
922 ["git username", ""]
923 , testSimplePrompt
924 "Check emailPrompt output (email supplied by the user)"
925 emailPrompt
926 "foobar@qux.com"
927 ["git email", "foobar@qux.com"]
928 , testSimplePrompt
929 "Check emailPrompt output (email guessed from git config)"
930 emailPrompt
931 "git@email"
932 ["git@email", ""]
933 , testSimplePrompt
934 "Check homepagePrompt output"
935 homepagePrompt
936 "qux.com"
937 ["qux.com"]
938 , testSimplePrompt
939 "Check testDirsPrompt output"
940 testDirsPrompt
941 ["quxTest"]
942 ["quxTest"]
943 , -- this tests 4) other, and can be used to model more inputs in case of failure
944 testSimplePrompt
945 "Check srcDirsPrompt output"
946 srcDirsPrompt
947 ["app"]
948 ["4", "app"]
950 , testGroup
951 "Numbered prompt tests"
952 [ testGroup
953 "Check categoryPrompt output"
954 [ testNumberedPrompt
955 "Category indices"
956 categoryPrompt
957 defaultCategories
958 , testSimplePrompt
959 "Other category"
960 categoryPrompt
961 "Unlisted"
962 [ show $ P.length defaultCategories + 1
963 , "Unlisted"
965 , testSimplePrompt
966 "No category"
967 categoryPrompt
969 [ ""
972 , testGroup "Check licensePrompt output" $
973 let other = show (1 + P.length defaultLicenseIds)
974 in [ testNumberedPrompt "License indices" licensePrompt $
975 fmap (\l -> SpecLicense . Left . SPDX.License $ SPDX.ELicense (SPDX.ELicenseId l) Nothing) defaultLicenseIds
976 , testSimplePrompt
977 "Other license 1"
978 licensePrompt
979 (SpecLicense . Left $ mkLicense SPDX.CC_BY_NC_ND_4_0)
980 [ other
981 , "CC-BY-NC-ND-4.0"
983 , testSimplePrompt
984 "Other license 2"
985 licensePrompt
986 (SpecLicense . Left $ mkLicense SPDX.D_FSL_1_0)
987 [ other
988 , "D-FSL-1.0"
990 , testSimplePrompt
991 "Other license 3"
992 licensePrompt
993 (SpecLicense . Left $ mkLicense SPDX.NPOSL_3_0)
994 [ other
995 , "NPOSL-3.0"
997 , testSimplePrompt
998 "Invalid license"
999 licensePrompt
1000 (SpecLicense $ Left SPDX.NONE)
1001 [ other
1002 , "yay"
1003 , other
1004 , "NONE"
1006 , testPromptBreak
1007 "Invalid index"
1008 licensePrompt
1009 [ "42"
1012 , testGroup
1013 "Check languagePrompt output"
1014 [ testNumberedPrompt
1015 "Language indices"
1016 (`languagePrompt` "test")
1017 [Haskell2010, Haskell98, GHC2021, GHC2024]
1018 , testSimplePrompt
1019 "Other language"
1020 (`languagePrompt` "test")
1021 (UnknownLanguage "Haskell2022")
1022 [ "5"
1023 , "Haskell2022"
1025 , testSimplePrompt
1026 "Invalid language"
1027 (`languagePrompt` "test")
1028 (UnknownLanguage "Lang_TS!")
1029 [ "5"
1030 , "Lang_TS!"
1033 , testGroup
1034 "Check languagePrompt session state"
1035 [ testSimplePrompt
1036 "Use last language"
1037 ( \flags -> do
1038 a <- languagePrompt flags "first language"
1039 b <- languagePrompt flags "second language"
1040 pure (a, b)
1042 (GHC2024, GHC2024)
1043 [ "4"
1044 , "" -- default
1047 , testGroup
1048 "Check srcDirsPrompt output"
1049 [ testNumberedPrompt
1050 "Source dirs indices"
1051 srcDirsPrompt
1052 [[defaultSourceDir], ["lib"], ["src-lib"]]
1053 , testSimplePrompt
1054 "Other source dir"
1055 srcDirsPrompt
1056 ["src"]
1057 [ "4"
1058 , "src"
1061 , testGroup
1062 "Check appDirsPrompt output"
1063 [ testNumberedPrompt
1064 "App dirs indices"
1065 appDirsPrompt
1066 [[defaultApplicationDir], ["exe"], ["src-exe"]]
1067 , testSimplePrompt
1068 "Other app dir"
1069 appDirsPrompt
1070 ["app"]
1071 [ "4"
1072 , "app"
1075 , testNumberedPrompt
1076 "Check packageTypePrompt output"
1077 packageTypePrompt
1078 [Library, Executable, LibraryAndExecutable]
1079 , testNumberedPrompt
1080 "Check cabalVersionPrompt output"
1081 cabalVersionPrompt
1082 defaultCabalVersions
1084 , testGroup
1085 "Bool prompt tests"
1086 [ testBoolPrompt "Check noCommentsPrompt output - y" noCommentsPrompt False "y"
1087 , testBoolPrompt "Check noCommentsPrompt output - Y" noCommentsPrompt False "Y"
1088 , testBoolPrompt "Check noCommentsPrompt output - n" noCommentsPrompt True "n"
1089 , testBoolPrompt "Check noCommentsPrompt output - N" noCommentsPrompt True "N"
1093 -- -------------------------------------------------------------------- --
1094 -- Prompt test utils
1096 testSimplePrompt
1097 :: Eq a
1098 => Show a
1099 => String
1100 -> (InitFlags -> PurePrompt a)
1101 -> a
1102 -> [String]
1103 -> TestTree
1104 testSimplePrompt label f target =
1105 testPrompt label f (assertFailure . show) (\(a, _) -> target @=? a)
1107 testPromptBreak
1108 :: Eq a
1109 => Show a
1110 => String
1111 -> (InitFlags -> PurePrompt a)
1112 -> [String]
1113 -> TestTree
1114 testPromptBreak label f =
1115 testPrompt label f go (assertFailure . show)
1116 where
1117 go BreakException{} =
1118 return ()
1120 testPrompt
1121 :: Eq a
1122 => Show a
1123 => String
1124 -> (InitFlags -> PurePrompt a)
1125 -> (BreakException -> Assertion)
1126 -> ((a, NonEmpty String) -> Assertion)
1127 -> [String]
1128 -> TestTree
1129 testPrompt label f g h input = testCase label $
1130 case (runPrompt $ f emptyFlags) (fromList input) of
1131 Left x -> g x -- :: BreakException
1132 Right x -> h x -- :: (a, other inputs)
1134 testNumberedPrompt :: (Eq a, Show a) => String -> (InitFlags -> PurePrompt a) -> [a] -> TestTree
1135 testNumberedPrompt label act = testGroup label . (++ goBreak) . fmap go . indexed1
1136 where
1137 indexed1 = zip [1 :: Int ..]
1138 mkLabel a n =
1139 "testing index "
1140 ++ show n
1141 ++ ") with: "
1142 ++ show a
1144 go (n, a) =
1145 testSimplePrompt (mkLabel a n) act a [show n]
1146 goBreak =
1147 [ testPromptBreak "testing index -1" act ["-1"]
1148 , testPromptBreak "testing index 1000" act ["1000"]
1151 testBoolPrompt
1152 :: String
1153 -> (InitFlags -> PurePrompt Bool)
1154 -> Bool
1155 -> String
1156 -> TestTree
1157 testBoolPrompt label act target b =
1158 testSimplePrompt label act target [b]