Commit 1923b4a8 authored by quasicomputational's avatar quasicomputational Committed by Alexis Williams

Fix up the new-sdist tests.

parent 7a029caa
......@@ -488,7 +488,8 @@ and two archives of the same format built from the same source will hash to the
``cabal new-sdist`` takes the following flags:
- ``-l``, ``--list-only``: Rather than creating an archive, lists files that would be included.
Output is to ``stdout`` by default.
Output is to ``stdout`` by default. The file paths are relative to the project's root
directory.
- ``--targz``: Output an archive in ``.tar.gz`` format.
......
......@@ -79,7 +79,7 @@ import System.Directory
( getCurrentDirectory, setCurrentDirectory
, createDirectoryIfMissing, makeAbsolute )
import System.FilePath
( (</>), (<.>), normalise, takeDirectory )
( (</>), (<.>), makeRelative, normalise, takeDirectory )
sdistCommand :: CommandUI SdistFlags
sdistCommand = CommandUI
......@@ -202,7 +202,7 @@ sdistAction SdistFlags{..} targetStrings globalFlags = do
| length pkgs > 1, not listSources, Just "-" <- mOutputPath' ->
die' verbosity "Can't write multiple tarballs to standard output!"
| otherwise ->
mapM_ (\pkg -> packageToSdist verbosity format (outputPath pkg) pkg) pkgs
mapM_ (\pkg -> packageToSdist verbosity (distProjectRootDirectory distLayout) format (outputPath pkg) pkg) pkgs
data IsExec = Exec | NoExec
deriving (Show, Eq)
......@@ -211,8 +211,8 @@ data OutputFormat = SourceList Char
| Archive ArchiveFormat
deriving (Show, Eq)
packageToSdist :: Verbosity -> OutputFormat -> FilePath -> UnresolvedSourcePackage -> IO ()
packageToSdist verbosity format outputFile pkg = do
packageToSdist :: Verbosity -> FilePath -> OutputFormat -> FilePath -> UnresolvedSourcePackage -> IO ()
packageToSdist verbosity projectRootDir format outputFile pkg = do
dir <- case packageSource pkg of
LocalUnpackedPackage path -> return path
_ -> die' verbosity "The impossible happened: a local package isn't local"
......@@ -226,10 +226,13 @@ packageToSdist verbosity format outputFile pkg = do
then putStr . withOutputMarker verbosity . BSL.unpack
else BSL.writeFile outputFile
files = nub . sortOn snd $ nonexec ++ exec
prefix = makeRelative projectRootDir dir
case format of
SourceList nulSep ->
write (BSL.pack . (++ [nulSep]) . intercalate [nulSep] . fmap snd $ files)
SourceList nulSep -> do
write (BSL.pack . (++ [nulSep]) . intercalate [nulSep] . fmap ((prefix </>) . snd) $ files)
when (outputFile /= "-") $
notice verbosity $ "Wrote source list to " ++ outputFile ++ "\n"
Archive TargzFormat -> do
let entriesM :: StateT (Set.Set FilePath) (WriterT [Tar.Entry] IO) ()
entriesM = forM_ files $ \(perm, file) -> do
......@@ -257,7 +260,8 @@ packageToSdist verbosity format outputFile pkg = do
(first, rest) = BSL.splitAt 9 bs
rest' = BSL.tail rest
write . normalize . GZip.compress . Tar.write $ entries
notice verbosity $ "Wrote tarball sdist to " ++ outputFile ++ "\n"
when (outputFile /= "-") $
notice verbosity $ "Wrote tarball sdist to " ++ outputFile ++ "\n"
Archive ZipFormat -> do
entries <- forM files $ \(perm, file) -> do
let perm' = case perm of
......
import Test.Cabal.Prelude
import System.Directory
main = cabalTest $ withSourceCopy $ do
cwd <- testCurrentDir <$> getTestEnv
cwd <- fmap testCurrentDir getTestEnv
liftIO $ createDirectoryIfMissing False $ cwd </> "archives"
cabal "new-sdist" ["all", "--output-dir", "archives"]
shouldNotExist $ cwd </> "dist-newstyle/sdist/a-0.1.tar.gz"
......
import Test.Cabal.Prelude
main = cabalTest $ withSourceCopy $ do
cwd <- testCurrentDir <$> getTestEnv
cwd <- fmap testCurrentDir getTestEnv
fails $ cabal "new-sdist" ["all:tests"]
shouldNotExist $ cwd </> "dist-newstyle/sdist/a-0.1.tar.gz"
shouldNotExist $ cwd </> "dist-newstyle/sdist/b-0.1.tar.gz"
import Test.Cabal.Prelude
main = cabalTest $ withSourceCopy $ do
cwd <- testCurrentDir <$> getTestEnv
cwd <- fmap testCurrentDir getTestEnv
cabal "new-sdist" ["all"]
shouldExist $ cwd </> "dist-newstyle/sdist/a-0.1.tar.gz"
shouldExist $ cwd </> "dist-newstyle/sdist/b-0.1.tar.gz"
# cabal new-sdist
Wrote source list to <ROOT>/list-sources-output-dir.dist/source/lists/a-0.1.list
Wrote source list to <ROOT>/list-sources-output-dir.dist/source/lists/b-0.1.list
import Test.Cabal.Prelude
import System.Directory
main = cabalTest $ withSourceCopy $ do
cwd <- testCurrentDir <$> getTestEnv
cwd <- fmap testCurrentDir getTestEnv
liftIO $ createDirectoryIfMissing False $ cwd </> "lists"
cabal "new-sdist" ["all", "--list-only", "--output-dir", "lists"]
assertFindInFile "a/a.cabal" (cwd </> "lists/a-0.1.list")
......
import Test.Cabal.Prelude
main = cabalTest $ withSourceCopy $ do
cwd <- testCurrentDir <$> getTestEnv
cwd <- fmap testCurrentDir getTestEnv
fails $ cabal "new-sdist" ["a", "b", "--output-dir", "-"]
shouldNotExist $ cwd </> "dist-newstyle/sdist/a-0.1.tar.gz"
shouldNotExist $ cwd </> "dist-newstyle/sdist/b-0.1.tar.gz"
import Test.Cabal.Prelude
main = cabalTest $ withSourceCopy $ do
cwd <- testCurrentDir <$> getTestEnv
cwd <- fmap testCurrentDir getTestEnv
cabal "new-sdist" ["a", "b"]
shouldExist $ cwd </> "dist-newstyle/sdist/a-0.1.tar.gz"
shouldExist $ cwd </> "dist-newstyle/sdist/b-0.1.tar.gz"
import Test.Cabal.Prelude
main = cabalTest $ withSourceCopy $ do
cwd <- testCurrentDir <$> getTestEnv
cwd <- fmap testCurrentDir getTestEnv
fails $ cabal "new-sdist" ["a", "base"]
shouldNotExist $ cwd </> "dist-newstyle/sdist/a-0.1.tar.gz"
import Test.Cabal.Prelude
main = cabalTest $ withSourceCopy $ do
cwd <- testCurrentDir <$> getTestEnv
cwd <- fmap testCurrentDir getTestEnv
fails $ cabal "new-sdist" ["a", "b", "a-test"]
shouldNotExist $ cwd </> "dist-newstyle/sdist/a-0.1.tar.gz"
shouldNotExist $ cwd </> "dist-newstyle/sdist/b-0.1.tar.gz"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment