1
+ -- | Test that Hackage accepts or refuses certain packages.
2
+
1
3
module Main
2
4
( main
3
5
) where
@@ -22,7 +24,11 @@ main = defaultMain allTests
22
24
allTests :: TestTree
23
25
allTests = testGroup " PackageTests"
24
26
[ 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
26
32
27
33
tarPermissions :: [TestTree ]
28
34
tarPermissions =
@@ -34,7 +40,8 @@ tarPermissions =
34
40
(testPermissions " tests/permissions-tarballs/bad-file-perms.tar.gz" badFileMangler)
35
41
, testCase
36
42
" 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
+ ]
38
45
39
46
goodMangler :: (Tar. Entry -> Maybe CombinedTarErrs )
40
47
goodMangler = const Nothing
@@ -51,45 +58,62 @@ badDirMangler entry =
51
58
Tar. Directory -> Just $ PermissionsError (Tar. entryPath entry) 0o700
52
59
_ -> Nothing
53
60
61
+ ---------------------------------------------------------------------------
62
+ -- * Package integry tests
63
+
54
64
cabalPackageCheckTests :: [TestTree ]
55
65
cabalPackageCheckTests =
56
66
[ testCase " Missing ./configure script" missingConfigureScriptTest
57
67
, testCase " Missing directories in tar file" missingDirsInTarFileTest
58
68
, testCase " Bad spec-version" badSpecVer
59
69
]
60
70
71
+ ---------------------------------------------------------------------------
72
+ -- ** Tests that must fail
73
+
74
+ -- | If @build-type: Configure@, then there must be a @./configure@ script.
75
+
61
76
missingConfigureScriptTest :: Assertion
62
77
missingConfigureScriptTest =
63
78
do tar <- tarGzFile " missing-configure-0.1.0.0"
64
79
now <- getCurrentTime
65
80
case unpackPackage now " missing-configure-0.1.0.0.tar.gz" tar of
66
- Right _ -> HUnit. assertFailure " expected error"
81
+ Right _ -> HUnit. assertFailure " error: unexpected success "
67
82
Left err ->
68
83
HUnit. assertBool
69
84
(" Error found, but not about missing ./configure: " ++ err)
70
85
(" The 'build-type' is 'Configure'" `isInfixOf` err)
71
86
87
+ -- | The @cabal-version@ must be valid.
88
+
72
89
badSpecVer :: Assertion
73
90
badSpecVer =
74
91
do tar <- tarGzFile " bad-specver-package-0"
75
92
now <- getCurrentTime
76
93
case unpackPackage now " bad-specver-package-0.tar.gz" tar of
77
- Right _ -> HUnit. assertFailure " expected error"
94
+ Right _ -> HUnit. assertFailure " error: unexpected success "
78
95
Left err ->
79
96
HUnit. assertBool
80
97
(" Error found, but not about invalid spec version: " ++ err)
81
98
(" cabal spec version" `isInfixOf` err)
82
99
100
+ ---------------------------------------------------------------------------
101
+ -- ** Tests that must succeed
102
+
83
103
-- | Some tar files in hackage are missing directory entries.
84
104
-- Ensure that they can be verified even without the directory entries.
105
+
85
106
missingDirsInTarFileTest :: Assertion
86
107
missingDirsInTarFileTest =
87
108
do tar <- fmap keepOnlyFiles (tarGzFile " correct-package-0.1.0.0" )
88
109
now <- getCurrentTime
89
110
case unpackPackage now " correct-package-0.1.0.0.tar.gz" tar of
90
111
Right _ -> return ()
91
112
Left err ->
92
- HUnit. assertFailure (" Excpected success but got: " ++ show err)
113
+ HUnit. assertFailure (" Expected success but got: " ++ show err)
114
+
115
+ ---------------------------------------------------------------------------
116
+ -- * Auxiliary functions
93
117
94
118
tarGzFile :: String -> IO ByteString
95
119
tarGzFile name = do
0 commit comments