diff --git a/cabal-testsuite/PackageTests/SDist/ListSources/Main.hs b/cabal-testsuite/PackageTests/SDist/ListSources/Main.hs new file mode 100644 index 00000000000..b3549c2fe3d --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/ListSources/Main.hs @@ -0,0 +1 @@ +main = return () diff --git a/cabal-testsuite/PackageTests/SDist/ListSources/data/blah/a.dat b/cabal-testsuite/PackageTests/SDist/ListSources/data/blah/a.dat new file mode 100644 index 00000000000..907b308167f --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/ListSources/data/blah/a.dat @@ -0,0 +1 @@ +blah diff --git a/cabal-testsuite/PackageTests/SDist/ListSources/extra-doc/blah/a.tex b/cabal-testsuite/PackageTests/SDist/ListSources/extra-doc/blah/a.tex new file mode 100644 index 00000000000..907b308167f --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/ListSources/extra-doc/blah/a.tex @@ -0,0 +1 @@ +blah diff --git a/cabal-testsuite/PackageTests/SDist/ListSources/extra-src/blah/a.html b/cabal-testsuite/PackageTests/SDist/ListSources/extra-src/blah/a.html new file mode 100644 index 00000000000..907b308167f --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/ListSources/extra-src/blah/a.html @@ -0,0 +1 @@ +blah diff --git a/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.cabal b/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.cabal new file mode 100644 index 00000000000..c0c0abfb781 --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.cabal @@ -0,0 +1,11 @@ +cabal-version: 2.2 +name: list-sources +version: 0 +data-dir: data +data-files: blah/*.dat +extra-source-files: extra-src/blah/*.html +extra-doc-files: extra-doc/blah/*.tex + +executable dummy + default-language: Haskell2010 + main-is: Main.hs diff --git a/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.cabal.out b/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.cabal.out new file mode 100644 index 00000000000..2482a13d897 --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.cabal.out @@ -0,0 +1,3 @@ +# cabal sdist +List of package sources written to file '/sources' +List of package sources written to file '/sources' diff --git a/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.out b/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.out new file mode 100644 index 00000000000..c7b1ba4eaa2 --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.out @@ -0,0 +1,2 @@ +# Setup sdist +List of package sources written to file '/sources' diff --git a/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.test.hs b/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.test.hs new file mode 100644 index 00000000000..618e13d7c7a --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.test.hs @@ -0,0 +1,12 @@ +import Control.Monad.IO.Class +import System.FilePath (normalise) +import Test.Cabal.Prelude +main = setupTest $ do + tmpdir <- fmap testTmpDir getTestEnv + let fn = tmpdir "sources" + setup "sdist" ["--list-sources=" ++ fn] + liftIO $ putStrLn =<< readFile fn + -- --list-sources outputs with slashes on posix and backslashes on Windows. 'normalise' converts our needle to the necessary format. + assertFileDoesContain fn $ normalise "data/blah/a.dat" + assertFileDoesContain fn $ normalise "extra-src/blah/a.html" + assertFileDoesContain fn $ normalise "extra-doc/blah/a.tex" diff --git a/cabal-testsuite/Test/Cabal/Monad.hs b/cabal-testsuite/Test/Cabal/Monad.hs index 377e8795264..032a6bf1c90 100644 --- a/cabal-testsuite/Test/Cabal/Monad.hs +++ b/cabal-testsuite/Test/Cabal/Monad.hs @@ -87,6 +87,7 @@ import System.Exit import System.FilePath import System.IO import System.IO.Error (isDoesNotExistError) +import System.IO.Temp (withSystemTempDirectory) import System.Process hiding (env) import Options.Applicative import Text.Regex @@ -232,7 +233,7 @@ diffProgram = simpleProgram "diff" -- | Run a test in the test monad according to program's arguments. runTestM :: String -> TestM a -> IO a -runTestM mode m = do +runTestM mode m = withSystemTempDirectory "cabal-testsuite" $ \tmp_dir -> do args <- execParser (info testArgParser mempty) let dist_dir = testArgDistDir args (script_dir0, script_filename) = splitFileName (testArgScriptPath args) @@ -300,6 +301,7 @@ runTestM mode m = do Just _ -> [GlobalPackageDB] env = TestEnv { testSourceDir = script_dir, + testTmpDir = tmp_dir, testSubName = script_base, testMode = mode, testProgramDb = program_db, @@ -409,6 +411,7 @@ normalizeOutput nenv = -- string search-replace. Make sure we do this before backslash -- normalization! . resub (posixRegexEscape (normalizerRoot nenv)) "/" + . resub (posixRegexEscape (normalizerTmpDir nenv)) "/" . appEndo (F.fold (map (Endo . packageIdRegex) (normalizerKnownPackages nenv))) -- Look for foo-0.1/installed-0d6... -- These installed packages will vary depending on GHC version @@ -435,6 +438,7 @@ normalizeOutput nenv = data NormalizerEnv = NormalizerEnv { normalizerRoot :: FilePath, + normalizerTmpDir :: FilePath, normalizerGhcVersion :: Version, normalizerKnownPackages :: [PackageId], normalizerPlatform :: Platform @@ -451,6 +455,8 @@ mkNormalizerEnv = do return NormalizerEnv { normalizerRoot = addTrailingPathSeparator (testSourceDir env), + normalizerTmpDir + = addTrailingPathSeparator (testTmpDir env), normalizerGhcVersion = compilerVersion (testCompiler env), normalizerKnownPackages @@ -505,6 +511,8 @@ data TestEnv = TestEnv -- | Path to the test directory, as specified by path to test -- script. testSourceDir :: FilePath + -- | Somewhere to stow temporary files needed by the test. + , testTmpDir :: FilePath -- | Test sub-name, used to qualify dist/database directory to avoid -- conflicts. , testSubName :: String diff --git a/cabal-testsuite/cabal-testsuite.cabal b/cabal-testsuite/cabal-testsuite.cabal index 05604c69e19..bcbe695b7e3 100644 --- a/cabal-testsuite/cabal-testsuite.cabal +++ b/cabal-testsuite/cabal-testsuite.cabal @@ -45,6 +45,7 @@ library filepath, regex-compat-tdfa, regex-tdfa, + temporary, text, Cabal >= 2.3 ghc-options: -Wall -fwarn-tabs