packages feed

nix-eval 0.1.0.0 → 0.1.0.1

raw patch · 3 files changed

+26/−7 lines, 3 filesPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

API changes (from Hackage documentation)

+ Language.Eval.Internal: haveNix :: IO Bool

Files

nix-eval.cabal view
@@ -2,7 +2,7 @@ -- see http://haskell.org/cabal/users-guide/  name:                nix-eval-version:             0.1.0.0+version:             0.1.0.1 synopsis:            Evaluate Haskell expressions using Nix to get packages description:         Evaluate Haskell expressions using Nix to get packages homepage:            http://chriswarbo.net/git/nix-eval
src/Language/Eval/Internal.hs view
@@ -73,14 +73,22 @@                in concat ["haskellPackages.ghcWithPackages ",                           "(h: [", unwords pkgs, "])"] +-- | Turn an expression into a Haskell module, complete with imports and `main` mkHs :: Expr -> String mkHs (Expr (_, ms, e)) = unlines (imports ++ [main])   where imports = map (\(Mod m) -> "import " ++ m) ms         main    = "main = putStr (" ++ e ++ ")" +-- | Strip leading and trailing whitespace trim :: String -> String trim = reverse . dropWhile isSpace . reverse . dropWhile isSpace +-- | Check if the `nix-shell` command is available via the shell+haveNix :: IO Bool+haveNix = do+  (c, _, _) <- readCreateProcessWithExitCode (shell "hash nix-shell") ""+  return (c == ExitSuccess)+ -- User-facing combinators  -- | A raw String of Haskell code, with no packages or modules. You can use@@ -99,11 +107,15 @@ asString :: (Show a) => a -> Expr asString = raw . show +-- | Qualify an expression, eg. `qualified "Data.Bool" "not"` gives the+--   expression `Data.Bool.not` with "Data.Bool" in its module list qualified :: Mod -> String -> Expr qualified (Mod m) e = Expr ([], [Mod m], m ++ "." ++ e) +-- | Append modules to an expression's context withMods :: [Mod] -> Expr -> Expr withMods ms (Expr (ps, ms', e)) = Expr (ps, ms' ++ ms, e) +-- | Append packages to an expression's context withPkgs :: [Pkg] -> Expr -> Expr withPkgs ps (Expr (ps', ms, e)) = Expr (ps' ++ ps, ms, e)
tests/Main.hs view
@@ -21,17 +21,24 @@  module Main where +import Data.Maybe import Language.Eval+import Language.Eval.Internal (haveNix) import Test.QuickCheck.Monadic import Test.Tasty (defaultMain, testGroup) import Test.Tasty.QuickCheck -main = defaultMain $ testGroup "All tests" [-    testProperty "Can eval unit"       unitEval-  , testProperty "Can eval sums"       sumEval-  , testProperty "Can import modules"  modulesImport-  , testProperty "Can import packages" packagesImport-  ]+-- | Only test if `nix-shell` is available. In particular, when Nix builds and+--   tests this package, it uses a pure environment where nix-shell isn't+--   available+main = do nix <- haveNix+          defaultMain $ testGroup "All tests" $ if nix then [+                testProperty "Can eval unit"       unitEval+              , testProperty "Can eval sums"       sumEval+              , testProperty "Can import modules"  modulesImport+              , testProperty "Can import packages" packagesImport+              ]+            else []  unitEval = checkIO "()" (Just "()")