packages feed

debug-diff (empty) → 0.1

raw patch · 5 files changed

+119/−0 lines, 5 filesdep +basedep +groomdep +processsetup-changed

Dependencies added: base, groom, process, temporary

Files

+ Debug/Diff.hs view
@@ -0,0 +1,6 @@+-- | Display a colorized diff between two Haskell values.+module Debug.Diff+    ( diff+    ) where++import Debug.Diff.Config
+ Debug/Diff/Config.hs view
@@ -0,0 +1,54 @@+-- | Display the difference between two Haskell values,+-- with control over the diff parameters.+module Debug.Diff.Config+    ( Config(..)+    , defConfig+    , diffWith+    , diff+    ) where++import Text.Groom+import Text.Printf+import System.IO+import System.IO.Temp+import System.Process+import System.Exit++-- | Configuration of the diff command+data Config = Config+    { context :: Maybe Int  -- ^ Lines of context, for a unified diff.+    , command :: String     -- ^ Diff command; @colordiff@ by default.+    , args    :: [String]   -- ^ Extra arguments to the diff command.+    } deriving (Eq, Ord, Read, Show)++-- | A default configuration.+defConfig :: Config+defConfig = Config+    { context = Just 3+    , command = "colordiff"+    , args    = [] }++-- | Display the difference between two Haskell values,+-- with control over the diff parameters.+diffWith :: (Show a, Show b) => Config -> a -> b -> IO ()+diffWith cfg x y =+    withSystemTempFile "ddiff_x" $ \px hx ->+    withSystemTempFile "ddiff_y" $ \py hy -> do+        hPutStrLn hx (groom x)+        hClose hx+        hPutStrLn hy (groom y)+        hClose hy+        let ctxArg n = ["-U", show n]+            allArgs = args cfg ++ maybe [] ctxArg (context cfg) ++ [px, py]+        (_, _, _, hdl) <- createProcess (proc (command cfg) allArgs)+        ec <- waitForProcess hdl+        case ec of+            ExitFailure n | n > 1 ->+                hPrintf stderr+                    "debug-diff: command %s with args %s exited with code %d\n"+                    (show (command cfg)) (show allArgs) n+            _ -> return ()++-- | Display a colorized diff between two Haskell values.+diff :: (Show a, Show b) => a -> b -> IO ()+diff = diffWith defConfig
+ LICENSE view
@@ -0,0 +1,26 @@+Copyright (c) Keegan McAllister 2011++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions+are met:+1. Redistributions of source code must retain the above copyright+   notice, this list of conditions and the following disclaimer.+2. Redistributions in binary form must reproduce the above copyright+   notice, this list of conditions and the following disclaimer in the+   documentation and/or other materials provided with the distribution.+3. Neither the name of the author nor the names of his contributors+   may be used to endorse or promote products derived from this software+   without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE+DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,4 @@+#! /usr/bin/runhaskell++import Distribution.Simple+main = defaultMain
+ debug-diff.cabal view
@@ -0,0 +1,29 @@+name:                debug-diff+version:             0.1+license:             BSD3+license-file:        LICENSE+synopsis:            Display a colorized diff between two Haskell values+category:            Debug+author:              Keegan McAllister <mcallister.keegan@gmail.com>+maintainer:          Keegan McAllister <mcallister.keegan@gmail.com>+build-type:          Simple+cabal-version:       >=1.2+description:+  @Debug.Diff@ is a quick tool for comparing two Haskell values, as+  when diagnosing a test failure.  It pretty-prints the values+  (using the @groom@ library) and passes them to an external @diff@+  command (@colordiff@ by default), which writes the diff to standard+  output.+  .+  @Debug.Diff.Config@ provides more control over the diff parameters.++library+  exposed-modules:+      Debug.Diff+    , Debug.Diff.Config+  ghc-options:      -Wall+  build-depends:+      base      >= 3 && < 5+    , groom     >= 0.1+    , temporary >= 1.1+    , process   >= 1.0