1
1
-- | Integration Tests related to parsing of ProjectConfigs
2
-
3
2
module IntegrationTests2.ProjectConfig.ParsecTests (parserTests ) where
4
3
5
- import qualified Data.ByteString as BS
6
- import System.Directory
7
- import System.FilePath
8
- import Test.Tasty
9
- import Test.Tasty.HUnit
10
- import Test.Tasty.Options
11
-
12
- import Distribution.Client.HttpUtils
4
+ import qualified Data.ByteString as BS
13
5
import Distribution.Client.DistDirLayout
6
+ import Distribution.Client.HttpUtils
14
7
import Distribution.Client.ProjectConfig
8
+ import Distribution.Client.ProjectConfig.Parsec
15
9
import Distribution.Client.RebuildMonad (runRebuild )
10
+ import Distribution.Client.Types.SourceRepo
16
11
import Distribution.Types.CondTree (CondTree (.. ))
17
12
import Distribution.Types.PackageName
18
13
import Distribution.Types.PackageVersionConstraint (PackageVersionConstraint (.. ))
14
+ import Distribution.Types.SourceRepo (KnownRepoType (.. ), RepoType (.. ))
19
15
import Distribution.Types.Version (Version , mkVersion )
20
16
import Distribution.Types.VersionRange.Internal (VersionRange (.. ))
21
17
import Distribution.Verbosity
18
+ import System.Directory
19
+ import System.FilePath
20
+ import Test.Tasty
21
+ import Test.Tasty.HUnit
22
+ import Test.Tasty.Options
22
23
23
24
-- TODO create tests:
24
25
-- - parser tests to read and compare to expected values
25
26
-- - golden tests for warnings and errors
26
27
parserTests :: [TestTree ]
27
- parserTests = [
28
- -- testCase "read with legacy parser" testLegacyRead
29
- testCase " read packages" testPackages
30
- , testCase " read optional-packages" testOptionalPackages
31
- , testCase " read extra-packages" testExtraPackages
32
- , testCase " read source-repository-package" testSourceRepoList
28
+ parserTests =
29
+ [ testCase " read packages" testPackages,
30
+ testCase " read optional-packages" testOptionalPackages,
31
+ testCase " read extra-packages" testExtraPackages,
32
+ testCase " read source-repository-package" testSourceRepoList
33
33
]
34
34
35
- testLegacyRead :: Assertion
36
- testLegacyRead = do
37
- httpTransport <- configureTransport verbosity [] Nothing
38
- projectRootDir <- canonicalizePath basedir
39
-
40
- -- let projectRoot = ProjectRootImplicit projectRootDir
41
- let projectFileName = " cabal-minimal.project"
42
- projectRoot = ProjectRootExplicit projectRootDir projectFileName
43
- extensionName = " "
44
- distDirLayout = defaultDistDirLayout projectRoot Nothing
45
- extensionDescription = " description"
46
- distProjectConfigFp = distProjectFile distDirLayout extensionName
47
- print distProjectConfigFp
48
- exists <- doesFileExist distProjectConfigFp
49
- print $ exists
50
- projectConfigSkeletonLegacy <- runRebuild projectRootDir $
51
- readProjectFileSkeletonLegacy verbosity httpTransport distDirLayout extensionName extensionDescription
52
- projectConfigSkeleton <- runRebuild projectRootDir $
53
- readProjectFileSkeleton verbosity httpTransport distDirLayout extensionName extensionDescription
54
- projectConfigSkeleton @?= projectConfigSkeletonLegacy
55
-
56
35
testPackages :: Assertion
57
36
testPackages = do
58
37
let expected = [" ." , " packages/packages.cabal" ] -- TODO also test https link
@@ -69,23 +48,41 @@ testOptionalPackages = do
69
48
70
49
testSourceRepoList :: Assertion
71
50
testSourceRepoList = do
72
- let expected = [
73
- ]
51
+ let expected =
52
+ [ SourceRepositoryPackage
53
+ { srpType = KnownRepoType Git ,
54
+ srpLocation = " https://example.com/Project.git" ,
55
+ srpTag = Just " 1234" ,
56
+ srpBranch = Nothing ,
57
+ srpSubdir = [] ,
58
+ srpCommand = []
59
+ },
60
+ SourceRepositoryPackage
61
+ { srpType = KnownRepoType Git ,
62
+ srpLocation = " https://example.com/example-dir/" ,
63
+ srpTag = Just " 12345" ,
64
+ srpBranch = Nothing ,
65
+ srpSubdir = [" subproject" ],
66
+ srpCommand = []
67
+ }
68
+ ]
74
69
(config, legacy) <- readConfigDefault " source-repository-packages"
75
70
assertConfig expected config legacy (projectPackagesRepo . condTreeData)
76
71
77
72
testExtraPackages :: Assertion
78
73
testExtraPackages = do
79
- let expected = [
80
- PackageVersionConstraint (mkPackageName " a" ) (OrLaterVersion (mkVersion [0 ])),
81
- PackageVersionConstraint (mkPackageName " b" ) (IntersectVersionRanges (OrLaterVersion (mkVersion [0 ,7 , 3 ])) (EarlierVersion (mkVersion [0 ,9 ])))
82
- ]
74
+ let expected =
75
+ [ PackageVersionConstraint (mkPackageName " a" ) (OrLaterVersion (mkVersion [0 ])),
76
+ PackageVersionConstraint (mkPackageName " b" ) (IntersectVersionRanges (OrLaterVersion (mkVersion [0 , 7 , 3 ])) (EarlierVersion (mkVersion [0 , 9 ])))
77
+ ]
83
78
(config, legacy) <- readConfigDefault " extra-packages"
84
79
assertConfig expected config legacy (projectPackagesNamed . condTreeData)
85
80
86
81
readConfigDefault :: FilePath -> IO (ProjectConfigSkeleton , ProjectConfigSkeleton )
87
82
readConfigDefault rootFp = readConfig rootFp " cabal.project"
88
83
84
+ -- TODO this is an overkill, look at warningTests, they just use runParseResult without
85
+ -- httpTransport etc
89
86
readConfig :: FilePath -> FilePath -> IO (ProjectConfigSkeleton , ProjectConfigSkeleton )
90
87
readConfig rootFp projectFileName = do
91
88
-- TODO extract argument so it can be mocked
@@ -99,10 +96,12 @@ readConfig rootFp projectFileName = do
99
96
distProjectConfigFp = distProjectFile distDirLayout extensionName
100
97
exists <- doesFileExist distProjectConfigFp
101
98
assertBool (" projectConfig does not exist: " <> distProjectConfigFp) exists
102
- parsec <- runRebuild projectRootDir $
103
- readProjectFileSkeleton verbosity httpTransport distDirLayout extensionName extensionDescription
104
- legacy <- runRebuild projectRootDir $
105
- readProjectFileSkeletonLegacy verbosity httpTransport distDirLayout extensionName extensionDescription
99
+ parsec <-
100
+ runRebuild projectRootDir $
101
+ readProjectFileSkeleton verbosity httpTransport distDirLayout extensionName extensionDescription
102
+ legacy <-
103
+ runRebuild projectRootDir $
104
+ readProjectFileSkeletonLegacy verbosity httpTransport distDirLayout extensionName extensionDescription
106
105
return (parsec, legacy)
107
106
108
107
assertConfig' :: (Eq a , Show a ) => a -> ProjectConfigSkeleton -> (ProjectConfigSkeleton -> a ) -> IO ()
@@ -123,7 +122,7 @@ emptyProjectConfig :: ProjectConfig
123
122
emptyProjectConfig = mempty
124
123
125
124
verbosity :: Verbosity
126
- verbosity = minBound -- normal --verbose --maxBound --minBound
125
+ verbosity = normal -- minBound --normal --verbose --maxBound --minBound
127
126
128
127
basedir :: FilePath
129
128
basedir = " tests" </> " IntegrationTests2" </> " ProjectConfig" </> " files"
0 commit comments