1+ -- | Test that Hackage accepts or refuses certain packages.
2+
13module Main
24 ( main
35 ) where
@@ -14,15 +16,19 @@ import Distribution.Server.Packages.Unpack
1416import Distribution.Server.Packages.UnpackTest
1517
1618import Test.Tasty (defaultMain , TestTree , testGroup )
17- import Test.Tasty.HUnit (testCase , Assertion )
19+ import Test.Tasty.HUnit (testCase , Assertion , HasCallStack )
1820
1921main :: IO ()
2022main = defaultMain allTests
2123
2224allTests :: TestTree
2325allTests = testGroup " PackageTests"
2426 [ testGroup " Tar file permissions" tarPermissions
25- , testGroup " Cabal package integrity tests" cabalPackageCheckTests]
27+ , testGroup " Cabal package integrity tests" cabalPackageCheckTests
28+ ]
29+
30+ ---------------------------------------------------------------------------
31+ -- * File permission tests
2632
2733tarPermissions :: [TestTree ]
2834tarPermissions =
@@ -34,7 +40,8 @@ tarPermissions =
3440 (testPermissions " tests/permissions-tarballs/bad-file-perms.tar.gz" badFileMangler)
3541 , testCase
3642 " Bad Dir Permissions"
37- (testPermissions " tests/permissions-tarballs/bad-dir-perms.tar.gz" badDirMangler)]
43+ (testPermissions " tests/permissions-tarballs/bad-dir-perms.tar.gz" badDirMangler)
44+ ]
3845
3946goodMangler :: (Tar. Entry -> Maybe CombinedTarErrs )
4047goodMangler = const Nothing
@@ -51,45 +58,98 @@ badDirMangler entry =
5158 Tar. Directory -> Just $ PermissionsError (Tar. entryPath entry) 0o700
5259 _ -> Nothing
5360
61+ ---------------------------------------------------------------------------
62+ -- * Package integry tests
63+
5464cabalPackageCheckTests :: [TestTree ]
5565cabalPackageCheckTests =
66+ -- Failing tests
5667 [ testCase " Missing ./configure script" missingConfigureScriptTest
57- , testCase " Missing directories in tar file" missingDirsInTarFileTest
5868 , testCase " Bad spec-version" badSpecVer
69+ -- Successful tests
70+ , testCase " Missing directories in tar file" missingDirsInTarFileTest
71+ , testCase " Accept GHC 9.2 LANGUAGE extensions" acceptGHC902LanguageExtensions
5972 ]
6073
74+ ---------------------------------------------------------------------------
75+ -- ** Tests that must fail
76+
77+ -- | If @build-type: Configure@, then there must be a @./configure@ script.
78+
6179missingConfigureScriptTest :: Assertion
6280missingConfigureScriptTest =
6381 do tar <- tarGzFile " missing-configure-0.1.0.0"
6482 now <- getCurrentTime
6583 case unpackPackage now " missing-configure-0.1.0.0.tar.gz" tar of
66- Right _ -> HUnit. assertFailure " expected error"
84+ Right _ -> HUnit. assertFailure " error: unexpected success "
6785 Left err ->
6886 HUnit. assertBool
6987 (" Error found, but not about missing ./configure: " ++ err)
7088 (" The 'build-type' is 'Configure'" `isInfixOf` err)
7189
90+ -- | The @cabal-version@ must be valid.
91+
7292badSpecVer :: Assertion
7393badSpecVer =
7494 do tar <- tarGzFile " bad-specver-package-0"
7595 now <- getCurrentTime
7696 case unpackPackage now " bad-specver-package-0.tar.gz" tar of
77- Right _ -> HUnit. assertFailure " expected error"
97+ Right _ -> HUnit. assertFailure " error: unexpected success "
7898 Left err ->
7999 HUnit. assertBool
80100 (" Error found, but not about invalid spec version: " ++ err)
81101 (" cabal spec version" `isInfixOf` err)
82102
103+ ---------------------------------------------------------------------------
104+ -- ** Tests that must succeed
105+
83106-- | Some tar files in hackage are missing directory entries.
84107-- Ensure that they can be verified even without the directory entries.
108+
85109missingDirsInTarFileTest :: Assertion
86110missingDirsInTarFileTest =
87- do tar <- fmap keepOnlyFiles (tarGzFile " correct-package-0.1.0.0" )
88- now <- getCurrentTime
89- case unpackPackage now " correct-package-0.1.0.0.tar.gz" tar of
90- Right _ -> return ()
91- Left err ->
92- HUnit. assertFailure (" Excpected success but got: " ++ show err)
111+ successTestTGZ pkg =<< do keepOnlyFiles <$> tarGzFile pkg
112+ where
113+ pkg = " correct-package-0.1.0.0"
114+
115+ -- | Hackage should accept GHC 9.2 language extensions (issue #1030).
116+
117+ acceptGHC902LanguageExtensions :: Assertion
118+ acceptGHC902LanguageExtensions = successTest " LANGUAGE-GHC-9.2"
119+
120+ ---------------------------------------------------------------------------
121+ -- * Auxiliary functions to construct tests
122+
123+ -- | A generic successful test, given a directory with the package contents.
124+ --
125+ -- Note: the 'HasCallStack' constraint ensures that the assertion failure
126+ -- is thrown at the invocation site of this function.
127+ --
128+ successTest
129+ :: HasCallStack
130+ => String -- ^ The directory which is also the package name.
131+ -> Assertion
132+ successTest pkg = successTestTGZ pkg =<< tarGzFile pkg
133+
134+ -- | A successful test, given the package name and its @.tgz@ stream.
135+ --
136+ -- Note: the 'HasCallStack' constraint ensures that the assertion failure
137+ -- is thrown at the invocation site of this function.
138+ --
139+ successTestTGZ
140+ :: HasCallStack
141+ => String -- ^ The package name which is also the stem of the @.tgz@ file.
142+ -> ByteString -- ^ The content of the @.tgz@ archive.
143+ -> Assertion
144+ successTestTGZ pkg tar = do
145+ now <- getCurrentTime
146+ case unpackPackage now (pkg ++ " .tar.gz" ) tar of
147+ Right _ -> return ()
148+ Left err ->
149+ HUnit. assertFailure $ " Expected success, but got: " ++ show err
150+
151+ ---------------------------------------------------------------------------
152+ -- * Tar utilities
93153
94154tarGzFile :: String -> IO ByteString
95155tarGzFile name = do
0 commit comments