Permalink
Browse files

Added proper cabal test suite.

  • Loading branch information...
1 parent 903961d commit 34fd665798b68365faa56352116ca52b7891c089 John MacFarlane committed Oct 16, 2012
Showing with 37 additions and 24 deletions.
  1. +23 −11 Tests.hs → tests/test-zip-archive.hs
  2. +14 −13 zip-archive.cabal
View
34 Tests.hs → tests/test-zip-archive.hs
@@ -1,14 +1,18 @@
+{-# LANGUAGE CPP #-}
-- Test suite for Codec.Archive.Zip
-- runghc Test.hs
import Codec.Archive.Zip
import System.Directory
import Test.HUnit.Base
import Test.HUnit.Text
+#if MIN_VERSION_directory(1,2,0)
import System.Time
+#endif
import System.Process
import qualified Data.ByteString.Lazy as B
import Control.Applicative
+import System.Exit
-- define equality for Archives so timestamps aren't distinguished if they
-- correspond to the same MSDOS datetime.
@@ -21,27 +25,30 @@ instance Eq Archive where
main :: IO Counts
main = do
createDirectory "test-temp"
- counts <- runTestTT $ TestList [
- testReadWriteArchive
- , testReadExternalZip
- , testFromToArchive
- , testReadWriteEntry
- , testAddFilesOptions
- , testDeleteEntries
- , testExtractFiles
- ]
+ res <- runTestTT $ TestList [ testReadWriteArchive
+ , testReadExternalZip
+ , testFromToArchive
+ , testReadWriteEntry
+ , testAddFilesOptions
+ , testDeleteEntries
+ , testExtractFiles
+ ]
removeDirectoryRecursive "test-temp"
- return counts
+ exitWith $ case errors res of
+ 0 -> ExitSuccess
+ n -> ExitFailure n
+testReadWriteArchive :: Test
testReadWriteArchive = TestCase $ do
archive <- addFilesToArchive [OptRecursive] emptyArchive ["LICENSE", "Codec"]
B.writeFile "test-temp/test1.zip" $ fromArchive archive
archive' <- toArchive <$> B.readFile "test-temp/test1.zip"
assertEqual "for writing and reading test1.zip" archive archive'
assertEqual "for writing and reading test1.zip" archive archive'
+testReadExternalZip :: Test
testReadExternalZip = TestCase $ do
- runCommand "/usr/bin/zip -q -9 test-temp/test4.zip zip-archive.cabal Codec/Archive/Zip.hs" >>= waitForProcess
+ _ <- runCommand "/usr/bin/zip -q -9 test-temp/test4.zip zip-archive.cabal Codec/Archive/Zip.hs" >>= waitForProcess
archive <- toArchive <$> B.readFile "test-temp/test4.zip"
let files = filesInArchive archive
assertEqual "for results of filesInArchive" ["zip-archive.cabal", "Codec/Archive/Zip.hs"] files
@@ -50,10 +57,12 @@ testReadExternalZip = TestCase $ do
Nothing -> assertFailure "zip-archive.cabal not found in archive"
Just f -> assertEqual "for contents of zip-archive.cabal in archive" cabalContents (fromEntry f)
+testFromToArchive :: Test
testFromToArchive = TestCase $ do
archive <- addFilesToArchive [OptRecursive] emptyArchive ["LICENSE", "Codec"]
assertEqual "for (toArchive $ fromArchive archive)" archive (toArchive $ fromArchive archive)
+testReadWriteEntry :: Test
testReadWriteEntry = TestCase $ do
entry <- readEntry [] "zip-archive.cabal"
setCurrentDirectory "test-temp"
@@ -63,18 +72,21 @@ testReadWriteEntry = TestCase $ do
let entry'' = entry' { eRelativePath = eRelativePath entry, eLastModified = eLastModified entry }
assertEqual "for readEntry -> writeEntry -> readEntry" entry entry''
+testAddFilesOptions :: Test
testAddFilesOptions = TestCase $ do
archive1 <- addFilesToArchive [OptVerbose] emptyArchive ["LICENSE", "Codec"]
archive2 <- addFilesToArchive [OptRecursive, OptVerbose] archive1 ["LICENSE", "Codec"]
assertBool "for recursive and nonrecursive addFilesToArchive"
(length (filesInArchive archive1) < length (filesInArchive archive2))
+testDeleteEntries :: Test
testDeleteEntries = TestCase $ do
archive1 <- addFilesToArchive [] emptyArchive ["LICENSE", "Codec/"]
let archive2 = deleteEntryFromArchive "LICENSE" archive1
let archive3 = deleteEntryFromArchive "Codec/" archive2
assertEqual "for deleteFilesFromArchive" emptyArchive archive3
+testExtractFiles :: Test
testExtractFiles = TestCase $ do
createDirectory "test-temp/dir1"
createDirectory "test-temp/dir1/dir2"
View
27 zip-archive.cabal
@@ -1,6 +1,6 @@
Name: zip-archive
Version: 0.1.2
-Cabal-version: >= 1.2
+Cabal-Version: >= 1.10
Build-type: Simple
Synopsis: Library for creating and modifying zip archives.
Description: The zip-archive library provides functions for creating, modifying,
@@ -12,33 +12,25 @@ Homepage: http://github.com/jgm/zip-archive
Author: John MacFarlane
Maintainer: jgm@berkeley.edu
Build-Depends: base
-Extra-Source-Files: Tests.hs, COPYING
+Extra-Source-Files: COPYING
flag splitBase
Description: Choose the new, smaller, split-up base package.
Default: True
flag executable
Description: Build the Zip executable.
Default: False
-flag directory11
- Description: Use version 1.1.x or earlier of the directory package
- Default: False
-Library
+Library
if flag(splitBase)
Build-depends: base >= 3 && < 5, pretty, containers
else
Build-depends: base < 3
- if flag(directory11)
- Build-depends: directory < 1.2
- cpp-options: -D_DIRECTORY_1_1
- else
- Build-depends: directory >= 1.2, time
- Build-depends: binary < 0.6, zlib, filepath, bytestring >= 0.9.0, array, mtl, utf8-string >= 0.3.1, old-time, digest >= 0.0.0.1
+ Build-depends: binary < 0.6, zlib, filepath, bytestring >= 0.9.0, array, mtl, utf8-string >= 0.3.1, old-time, digest >= 0.0.0.1, directory, time
Exposed-modules: Codec.Archive.Zip
Hs-Source-Dirs: .
Ghc-Options: -Wall
- Extensions: CPP
+ Default-Extensions: CPP
if os(windows)
cpp-options: -D_WINDOWS
else
@@ -51,3 +43,12 @@ Executable Zip
Buildable: False
Main-is: Zip.hs
Ghc-Options: -Wall
+
+Test-Suite test-zip-archive
+ Type: exitcode-stdio-1.0
+ Main-Is: test-zip-archive.hs
+ Hs-Source-Dirs: tests
+ Build-Depends: base >= 4.2 && < 5,
+ directory, bytestring >= 0.9.0, process, time, old-time,
+ HUnit, zip-archive
+ Ghc-Options: -Wall

0 comments on commit 34fd665

Please sign in to comment.