1 module UnitTests
.Distribution
.Client
.Init
.Interactive
6 import Test
.Tasty
.HUnit
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 -- -------------------------------------------------------------------- --
37 -> InstalledPackageIndex
40 tests _v initFlags pkgIx srcDb
=
42 "Distribution.Client.Init.Interactive.Command.hs"
43 [ createProjectTest pkgIx srcDb
44 , fileCreatorTests pkgIx srcDb pkgName
45 , interactiveTests srcDb
49 evalPrompt
(packageNamePrompt srcDb initFlags
) $
50 fromList
["test-package", "y"]
52 -- pkgNm = evalPrompt (getPackageName srcDb initFlags) $ fromList ["test-package", "y"]
55 :: InstalledPackageIndex
58 createProjectTest pkgIx srcDb
=
63 [ testCase
"Check the interactive workflow" $ do
66 { packageType
= Flag LibraryAndExecutable
67 , minimal
= Flag
False
68 , overwrite
= Flag
False
69 , packageDir
= Flag
"/home/test/test-package"
71 , exposedModules
= Flag
[]
72 , otherModules
= 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
128 Left e
-> assertFailure
$ show e
132 [ testCase
"Check the interactive library and executable workflow" $ do
137 , -- overwrite (not asked, pristine folder)
142 , -- package description
170 , -- executable target
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
238 Left e
-> assertFailure
$ show e
239 , testCase
"Check the interactive library workflow" $ do
244 , -- overwrite (not asked, pristine folder)
249 , -- package description
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
330 Left e
-> assertFailure
$ show e
331 , testCase
"Check the interactive library workflow" $ do
336 , -- overwrite (not asked, pristine folder)
341 , -- package description
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
408 Left e
-> assertFailure
$ show e
412 [ testCase
"Check the interactive library and executable workflow" $ do
417 , -- overwrite (not asked, pristine folder)
422 , -- package description
450 , -- executable target
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
504 Left e
-> assertFailure
$ show e
505 , testCase
"Check the interactive library workflow" $ do
510 , -- overwrite (not asked, pristine folder)
515 , -- package description
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
582 Left e
-> assertFailure
$ show e
583 , testCase
"Check the interactive library workflow - cabal < 1.18" $ do
588 , -- overwrite (not asked, pristine folder)
593 , -- package description
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
667 Left e
-> assertFailure
$ show e
668 , testCase
"Check the interactive executable workflow" $ do
673 , -- overwrite (not asked, pristine folder)
678 , -- package description
701 , -- executable target
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
745 Left e
-> assertFailure
$ show e
749 fileCreatorTests
:: InstalledPackageIndex
-> SourcePackageDb
-> PackageName
-> TestTree
750 fileCreatorTests pkgIx srcDb _pkgName
=
755 [ testCase
"Check common package flags workflow" $ do
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
776 [ testCase
"Check library package flags workflow" $ do
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
787 [ testCase
"Check executable package flags workflow" $ do
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
799 [ testCase
"Check test package flags workflow" $ do
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
812 runGenTest inputs go
= case runPrompt go inputs
of
813 Left e
-> assertFailure
$ show e
816 interactiveTests
:: SourcePackageDb
-> TestTree
817 interactiveTests srcDb
=
819 "Check top level getter functions"
821 "Simple prompt tests"
823 "Check packageNamePrompt output"
826 (packageNamePrompt srcDb
)
827 (mkPackageName
"test-package")
834 (packageNamePrompt srcDb
)
835 (mkPackageName
"test-package")
841 "Existing package name 1"
842 (packageNamePrompt srcDb
)
843 (mkPackageName
"test-package")
851 "Existing package name 2"
852 (packageNamePrompt srcDb
)
853 (mkPackageName
"cabal-install")
861 "Check mainFilePrompt output"
863 "New valid main file"
869 "New valid other main file"
871 (HsFilePath
"Main.hs" Standard
)
876 "Invalid other main file"
878 (HsFilePath
"Main.lhs" Literate
)
885 "Check versionPrompt output"
889 (mkVersion
[0, 3, 1, 0])
895 (mkVersion
[0, 3, 1, 0])
901 "Check synopsisPrompt output"
905 "We are Qux, and this is our package"
906 ["We are Qux, and this is our package"]
910 "Resistance is futile, you will be assimilated"
911 ["Resistance is futile, you will be assimilated"]
914 "Check authorPrompt output (name supplied by the user)"
917 ["git username", "Foobar"]
919 "Check authorPrompt output (name guessed from git config)"
924 "Check emailPrompt output (email supplied by the user)"
927 ["git email", "foobar@qux.com"]
929 "Check emailPrompt output (email guessed from git config)"
934 "Check homepagePrompt output"
939 "Check testDirsPrompt output"
943 , -- this tests 4) other, and can be used to model more inputs in case of failure
945 "Check srcDirsPrompt output"
951 "Numbered prompt tests"
953 "Check categoryPrompt output"
962 [ show $ P
.length defaultCategories
+ 1
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
979 (SpecLicense
. Left
$ mkLicense SPDX
.CC_BY_NC_ND_4_0
)
986 (SpecLicense
. Left
$ mkLicense SPDX
.D_FSL_1_0
)
993 (SpecLicense
. Left
$ mkLicense SPDX
.NPOSL_3_0
)
1000 (SpecLicense
$ Left SPDX
.NONE
)
1013 "Check languagePrompt output"
1014 [ testNumberedPrompt
1016 (`languagePrompt`
"test")
1017 [Haskell2010
, Haskell98
, GHC2021
, GHC2024
]
1020 (`languagePrompt`
"test")
1021 (UnknownLanguage
"Haskell2022")
1027 (`languagePrompt`
"test")
1028 (UnknownLanguage
"Lang_TS!")
1034 "Check languagePrompt session state"
1038 a
<- languagePrompt flags
"first language"
1039 b
<- languagePrompt flags
"second language"
1048 "Check srcDirsPrompt output"
1049 [ testNumberedPrompt
1050 "Source dirs indices"
1052 [[defaultSourceDir
], ["lib"], ["src-lib"]]
1062 "Check appDirsPrompt output"
1063 [ testNumberedPrompt
1066 [[defaultApplicationDir
], ["exe"], ["src-exe"]]
1075 , testNumberedPrompt
1076 "Check packageTypePrompt output"
1078 [Library
, Executable
, LibraryAndExecutable
]
1079 , testNumberedPrompt
1080 "Check cabalVersionPrompt output"
1082 defaultCabalVersions
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
1100 -> (InitFlags
-> PurePrompt a
)
1104 testSimplePrompt label f target
=
1105 testPrompt label f
(assertFailure
. show) (\(a
, _
) -> target
@=? a
)
1111 -> (InitFlags
-> PurePrompt a
)
1114 testPromptBreak label f
=
1115 testPrompt label f go
(assertFailure
. show)
1117 go BreakException
{} =
1124 -> (InitFlags
-> PurePrompt a
)
1125 -> (BreakException
-> Assertion
)
1126 -> ((a
, NonEmpty
String) -> Assertion
)
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
1137 indexed1
= zip [1 :: Int ..]
1145 testSimplePrompt
(mkLabel a n
) act a
[show n
]
1147 [ testPromptBreak
"testing index -1" act
["-1"]
1148 , testPromptBreak
"testing index 1000" act
["1000"]
1153 -> (InitFlags
-> PurePrompt
Bool)
1157 testBoolPrompt label act target b
=
1158 testSimplePrompt label act target
[b
]