git.iko.soy/typeable/cabal2nix
on master help sign in
regression-test: ensure that our test suite can run with 1K stack space again
commitc6f91ab9b186d940207c74240ea9c162cef4c53e authorPeter Simons <simons@cryp.to> dateThu 28 Jun 2018, 14:47 (8 years ago) parente2d3438
2 files changed+33−3
cabal2nix.cabal+2−2 test/Main.hs+31−1
cabal2nix.cabal+2−2
@@ -193,11 +193,11 @@ test-suite regression-test
193193 , Cabal >2.2
194194 , cabal2nix
195195 , filepath
196+ , directory
196197 , language-nix
197198 , lens
198199 , pretty
199200 , tasty
200201 , tasty-golden
201− -- TODO: Why does 1K not work any longer?
202− ghc-options: -Wall -with-rtsopts=-K48K
202+ ghc-options: -Wall -with-rtsopts=-K1K
203203 default-language: Haskell2010
test/Main.hs+31−1
@@ -5,6 +5,7 @@ import Distribution.Nixpkgs.Haskell.Derivation
55import Distribution.Nixpkgs.Fetch
66
77import Control.Lens
8+import Control.Monad
89import Distribution.Compiler
910import Distribution.PackageDescription
1011import Distribution.PackageDescription.Parsec
@@ -12,6 +13,7 @@ import Distribution.System
1213import Distribution.Verbosity
1314import Distribution.Version
1415import Language.Nix
16+import System.Directory
1517import System.FilePath
1618import Test.Tasty
1719import Test.Tasty.Golden
@@ -21,7 +23,7 @@ main :: IO ()
2123main = do
2224 -- TODO: run this test with all kinds of setLocaleEncoding values to ensure we don't
2325 -- depend on the system environment: https://github.com/NixOS/cabal2nix/issues/333
24− testCases <- findByExtension [".cabal"] "test/golden-test-cases"
26+ testCases <- listDirectoryFilesBySuffix ".cabal" "test/golden-test-cases"
2527 defaultMain $ testGroup "regression-tests" (map regressionTest testCases)
2628
2729regressionTest :: String -> TestTree
@@ -50,3 +52,31 @@ regressionTest cabalFile = do
5052 goldenFile
5153 nixFile
5254 (readGenericPackageDescription silent cabalFile >>= writeFile nixFile . prettyShow . cabal2nix)
55+
56+
57+-------------------------------------------------------------------------------
58+-- * Helper functions
59+-------------------------------------------------------------------------------
60+
61+-- | Find all *files* in the given directory. This function does not recurse,
62+-- nor does it include the special entries @'.'@ or @'..'@ in the result.
63+
64+listDirectoryFiles :: FilePath -> IO [FilePath]
65+listDirectoryFiles dirPath = do
66+ entries <- listDirectory dirPath
67+ filterM doesFileExist (map (dirPath </>) entries)
68+
69+-- | Find all *files* in the given directory that end with the given suffix.
70+-- This function does not recurse, nor does it include the special entries
71+-- @'.'@ or @'..'@ in the result.
72+--
73+-- "Test.Tasty.Golden" offers 'findByExtension', which does something similar
74+-- (and arguably more general) as those two functions, but unfortunately that
75+-- function recurses through the directory hierarchy and in the process needs
76+-- plenty of stack space. There might be a space leak in that code, I am not
77+-- sure. Anyhow, since our test suite is supposed to run with 1K stack space,
78+-- we prefer our own simpler code.
79+
80+listDirectoryFilesBySuffix :: String -> FilePath -> IO [FilePath]
81+listDirectoryFilesBySuffix suff =
82+ fmap (filter ((suff ==) . takeExtension)) . listDirectoryFiles