From bde2e32c77cb43ead0677f01652ee6d8dfe85843 Mon Sep 17 00:00:00 2001 From: quasicomputational Date: Sat, 28 Apr 2018 15:11:15 +0100 Subject: [PATCH 1/4] cabal-testsuite: provide tests with a temporary directory. By having the runner provide it (and hence know the name), it can then normalise any paths that mention the temporary directory without a problem. --- cabal-testsuite/Test/Cabal/Monad.hs | 10 +++++++++- cabal-testsuite/cabal-testsuite.cabal | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) 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 From 770901597a132b117a176269bf99bf538c9083ed Mon Sep 17 00:00:00 2001 From: quasicomputational Date: Sat, 28 Apr 2018 15:43:24 +0100 Subject: [PATCH 2/4] Rudimentary test for sdist --list-sources. --- .../PackageTests/SDist/ListSources/Main.hs | 1 + .../PackageTests/SDist/ListSources/data/blah/a.dat | 1 + .../SDist/ListSources/extra-doc/blah/a.tex | 1 + .../SDist/ListSources/extra-src/blah/a.html | 1 + .../PackageTests/SDist/ListSources/list-sources.cabal | 11 +++++++++++ .../SDist/ListSources/list-sources.cabal.out | 3 +++ .../PackageTests/SDist/ListSources/list-sources.out | 2 ++ .../SDist/ListSources/list-sources.test.hs | 8 ++++++++ 8 files changed, 28 insertions(+) create mode 100644 cabal-testsuite/PackageTests/SDist/ListSources/Main.hs create mode 100644 cabal-testsuite/PackageTests/SDist/ListSources/data/blah/a.dat create mode 100644 cabal-testsuite/PackageTests/SDist/ListSources/extra-doc/blah/a.tex create mode 100644 cabal-testsuite/PackageTests/SDist/ListSources/extra-src/blah/a.html create mode 100644 cabal-testsuite/PackageTests/SDist/ListSources/list-sources.cabal create mode 100644 cabal-testsuite/PackageTests/SDist/ListSources/list-sources.cabal.out create mode 100644 cabal-testsuite/PackageTests/SDist/ListSources/list-sources.out create mode 100644 cabal-testsuite/PackageTests/SDist/ListSources/list-sources.test.hs 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..03781f741b6 --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.test.hs @@ -0,0 +1,8 @@ +import Test.Cabal.Prelude +main = setupTest $ do + tmpdir <- fmap testTmpDir getTestEnv + let fn = tmpdir "sources" + setup "sdist" ["--list-sources=" ++ fn] + assertFileDoesContain fn "data/blah/a.dat" + assertFileDoesContain fn "extra-src/blah/a.html" + assertFileDoesContain fn "extra-doc/blah/a.tex" From 4777abe464b303a3a2e9d43bcbfa64178a405265 Mon Sep 17 00:00:00 2001 From: quasicomputational Date: Sat, 28 Apr 2018 19:33:22 +0100 Subject: [PATCH 3/4] Fix the --list-sources test by normalising paths before comparison --- .../PackageTests/SDist/ListSources/list-sources.test.hs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.test.hs b/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.test.hs index 03781f741b6..c3cf82c2b1b 100644 --- a/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.test.hs +++ b/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.test.hs @@ -1,8 +1,10 @@ +import System.FilePath (normalise) import Test.Cabal.Prelude main = setupTest $ do tmpdir <- fmap testTmpDir getTestEnv let fn = tmpdir "sources" setup "sdist" ["--list-sources=" ++ fn] - assertFileDoesContain fn "data/blah/a.dat" - assertFileDoesContain fn "extra-src/blah/a.html" - assertFileDoesContain fn "extra-doc/blah/a.tex" + -- --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" From 50f94819eee12e8834891a60f3b227a85b4fb0bc Mon Sep 17 00:00:00 2001 From: quasicomputational Date: Sat, 28 Apr 2018 20:06:15 +0100 Subject: [PATCH 4/4] Remote debugging: dump the file's contents. Windows is doing something funny here. Let's find out what it is. --- .../PackageTests/SDist/ListSources/list-sources.test.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.test.hs b/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.test.hs index c3cf82c2b1b..618e13d7c7a 100644 --- a/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.test.hs +++ b/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.test.hs @@ -1,9 +1,11 @@ +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"