forked from commercialhaskell/stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUntarSpec.hs
More file actions
49 lines (42 loc) · 1.61 KB
/
UntarSpec.hs
File metadata and controls
49 lines (42 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Stack.Untar.UntarSpec where
import Data.List (sort)
import Path
import Path.IO (removeDirRecur)
import qualified System.FilePath as FP
import Stack.Fetch (untar)
import Stack.Prelude
import Test.Hspec
spec :: Spec
spec = do
describe "Untarring ignores strange entries" $
mapM_ testTarFile tarFiles
where
-- XXX tests are run in the project root folder, but data files are next to
-- this source data.
currentFolder = $(mkRelDir $ "src" FP.</> "test" FP.</> "Stack" FP.</> "Untar")
-- Pairs test tarball names + list of unexpected entries contained: for each
-- entry, a tar pathname + description.
tarFilesBase = [ ("test1", [])
, ("test2", [ ("bar", "named pipe")
, ("devB", "block device")
, ("devC", "character device")])]
-- Prepend tarball name to tar pathnames:
tarFiles =
[ (name,
[ (name FP.</> entryName, d)
| (entryName, d) <- entries])
| (name, entries) <- tarFilesBase ]
testTarFile (name, expected) =
it ("works on test " ++ name) $
getEntries name `shouldReturn` sort expected
getEntries name = do
tarballName <- parseRelFile $ name ++ ".tar.gz"
expectedTarFolder <- parseRelDir name
entries <- untar (currentFolder </> tarballName) expectedTarFolder currentFolder
removeDirRecur $ currentFolder </> expectedTarFolder
return $ sort entries