@@ -16,7 +16,7 @@ import Distribution.Server.Packages.Unpack
16
16
import Distribution.Server.Packages.UnpackTest
17
17
18
18
import Test.Tasty (defaultMain , TestTree , testGroup )
19
- import Test.Tasty.HUnit (testCase , Assertion )
19
+ import Test.Tasty.HUnit (testCase , Assertion , HasCallStack )
20
20
21
21
main :: IO ()
22
22
main = defaultMain allTests
@@ -105,15 +105,43 @@ badSpecVer =
105
105
106
106
missingDirsInTarFileTest :: Assertion
107
107
missingDirsInTarFileTest =
108
- do tar <- fmap keepOnlyFiles (tarGzFile " correct-package-0.1.0.0" )
109
- now <- getCurrentTime
110
- case unpackPackage now " correct-package-0.1.0.0.tar.gz" tar of
111
- Right _ -> return ()
112
- Left err ->
113
- HUnit. assertFailure (" Expected success but got: " ++ show err)
108
+ successTestTGZ pkg =<< do keepOnlyFiles <$> tarGzFile pkg
109
+ where
110
+ pkg = " correct-package-0.1.0.0"
111
+
112
+ ---------------------------------------------------------------------------
113
+ -- * Auxiliary functions to construct tests
114
+
115
+ -- | A generic successful test, given a directory with the package contents.
116
+ --
117
+ -- Note: the 'HasCallStack' constraint ensures that the assertion failure
118
+ -- is thrown at the invocation site of this function.
119
+ --
120
+ successTest
121
+ :: HasCallStack
122
+ => String -- ^ The directory which is also the package name.
123
+ -> Assertion
124
+ successTest pkg = successTestTGZ pkg =<< tarGzFile pkg
125
+
126
+ -- | A successful test, given the package name and its @.tgz@ stream.
127
+ --
128
+ -- Note: the 'HasCallStack' constraint ensures that the assertion failure
129
+ -- is thrown at the invocation site of this function.
130
+ --
131
+ successTestTGZ
132
+ :: HasCallStack
133
+ => String -- ^ The package name which is also the stem of the @.tgz@ file.
134
+ -> ByteString -- ^ The content of the @.tgz@ archive.
135
+ -> Assertion
136
+ successTestTGZ pkg tar = do
137
+ now <- getCurrentTime
138
+ case unpackPackage now (pkg ++ " .tar.gz" ) tar of
139
+ Right _ -> return ()
140
+ Left err ->
141
+ HUnit. assertFailure $ " Expected success, but got: " ++ show err
114
142
115
143
---------------------------------------------------------------------------
116
- -- * Auxiliary functions
144
+ -- * Tar utilities
117
145
118
146
tarGzFile :: String -> IO ByteString
119
147
tarGzFile name = do
0 commit comments