git.iko.soy/typeable/cabal2nix
on master help sign in
regression-test: ensure that our test suite can run with 1K stack space again
c6f91abPeter Simons
cabal2nix.cabal+2−2
@@ -193,11 +193,11 @@ test-suite regression-test
193 , Cabal >2.2
193 , Cabal >2.2
194 , cabal2nix
194 , cabal2nix
195 , filepath
195 , filepath
196+ , directory
196 , language-nix
197 , language-nix
197 , lens
198 , lens
198 , pretty
199 , pretty
199 , tasty
200 , tasty
200 , tasty-golden
201 , 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
203 default-language: Haskell2010
203 default-language: Haskell2010
test/Main.hs+31−1
@@ -5,6 +5,7 @@ import Distribution.Nixpkgs.Haskell.Derivation
5import Distribution.Nixpkgs.Fetch
5import Distribution.Nixpkgs.Fetch
6
6
7import Control.Lens
7import Control.Lens
8+import Control.Monad
8import Distribution.Compiler
9import Distribution.Compiler
9import Distribution.PackageDescription
10import Distribution.PackageDescription
10import Distribution.PackageDescription.Parsec
11import Distribution.PackageDescription.Parsec
@@ -12,6 +13,7 @@ import Distribution.System
12import Distribution.Verbosity
13import Distribution.Verbosity
13import Distribution.Version
14import Distribution.Version
14import Language.Nix
15import Language.Nix
16+import System.Directory
15import System.FilePath
17import System.FilePath
16import Test.Tasty
18import Test.Tasty
17import Test.Tasty.Golden
19import Test.Tasty.Golden
@@ -21,7 +23,7 @@ main :: IO ()
21main = do
23main = do
22 -- TODO: run this test with all kinds of setLocaleEncoding values to ensure we don't
24 -- TODO: run this test with all kinds of setLocaleEncoding values to ensure we don't
23 -- depend on the system environment: https://github.com/NixOS/cabal2nix/issues/333
25 -- 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"
25 defaultMain $ testGroup "regression-tests" (map regressionTest testCases)
27 defaultMain $ testGroup "regression-tests" (map regressionTest testCases)
26
28
27regressionTest :: String -> TestTree
29regressionTest :: String -> TestTree
@@ -50,3 +52,31 @@ regressionTest cabalFile = do
50 goldenFile
52 goldenFile
51 nixFile
53 nixFile
52 (readGenericPackageDescription silent cabalFile >>= writeFile nixFile . prettyShow . cabal2nix)
54 (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