packages feed

augeas 0.2.0 → 0.3.0

raw patch · 5 files changed

+465/−215 lines, 5 filesdep ~basesetup-changed

Dependency ranges changed: base

Files

HUnitAug.hs view
@@ -1,7 +1,7 @@ -- file: HUnitAug.hs  -- Haskell bindings for the Augeas library--- Copyright (c) 2009, Jude Nagurney+-- Copyright (c) 2009-2010, Jude Nagurney -- -- This program is free software; you can redistribute it and/or modify it -- under the terms of the GNU General Public License as published by the Free@@ -19,47 +19,58 @@ -- Contact the author at -- jude@pwan.org +{-# LANGUAGE CPP #-}++#ifndef _config_h+#include "Config.h"+#define _config_h+#endif+ module Main where +import Foreign+ import Test.HUnit import System.Augeas--- import AugeasHsc import Data.ByteString.Char8 -import Foreign-import Foreign.C.Types-import Foreign.ForeignPtr- import System.Directory import Data.List (isInfixOf) import System.IO as IO  -- constants+bs_BadPath :: ByteString bs_BadPath = (Data.ByteString.Char8.pack "/files/bad/path")  -- testBadRoot :: Test -- testBadRoot = TestCase (do --   aug_ptr <- aug_init (Data.ByteString.Char8.pack "./bad_testroot") empty [] --  assertEqual "Should get Nothing after a bad root" Nothing aug_ptr)-+with_augptr :: (Ptr Augeas -> IO ()) -> IO () with_augptr func = do cwd <- getCurrentDirectory                       maybe_aug_ptr <- aug_init (Data.ByteString.Char8.pack (cwd++"/testroot")) empty [save_newfile]                       case maybe_aug_ptr of                         Nothing -> assertFailure "aug_ptr shouldn't be nothing in with_augptr"                         Just aug_fp -> (withForeignPtr aug_fp $ \aug_ptr -> func aug_ptr) +testFirst :: Test+testFirst = TestCase ( assertEqual "keep the test list from complaining about a leading comma" True True+                     )+ -- ---------------- -- aug_defvar tests -- ----------------+#ifdef HAS_AUGEAS_DEFVAR testBadDefVar :: Test testBadDefVar = TestCase ( with_augptr $ \aug_ptr -> do-                            ret_defvar <- aug_defvar aug_ptr (Data.ByteString.Char8.pack "var") (Just (Data.ByteString.Char8.pack "$undefined"))-                            assertEqual "testBadDefVar " System.Augeas.error ret_defvar+                             ret_defvar <- aug_defvar aug_ptr (Data.ByteString.Char8.pack "var") (Just (Data.ByteString.Char8.pack "$undefined"))+                             assertEqual "testBadDefVar " System.Augeas.error ret_defvar+                                           +                             ret_error <- aug_error aug_ptr+                             assertEqual "testBadDefVar error" err_bad_path ret_error+                         ) -                            ret_error <- aug_error aug_ptr-                            assertEqual "testBadDefVar error" err_bad_path ret_error -                            )  testGoodDefVar :: Test testGoodDefVar  = TestCase  ( with_augptr $ \aug_ptr -> do@@ -78,11 +89,11 @@                                 ret_get <- aug_get aug_ptr (Data.ByteString.Char8.pack "$var")                                 assertEqual "testReplaceDefVar: Should have gotten localhost" (Right (Just "localhost")) ret_get -                                ret_defvar <- aug_defvar aug_ptr (Data.ByteString.Char8.pack "var") (Just (Data.ByteString.Char8.pack "/files/etc/hosts/1/ipaddr"))-                                assertEqual "testReplaceDefVar (2)" one ret_defvar+                                ret_defvar2 <- aug_defvar aug_ptr (Data.ByteString.Char8.pack "var") (Just (Data.ByteString.Char8.pack "/files/etc/hosts/1/ipaddr"))+                                assertEqual "testReplaceDefVar (2)" one ret_defvar2 -                                ret_get <- aug_get aug_ptr (Data.ByteString.Char8.pack "$var")-                                assertEqual "testReplaceDefVar: Should have gotten 127.0.0.1" (Right (Just "127.0.0.1")) ret_get+                                ret_get2 <- aug_get aug_ptr (Data.ByteString.Char8.pack "$var")+                                assertEqual "testReplaceDefVar: Should have gotten 127.0.0.1" (Right (Just "127.0.0.1")) ret_get2                              ) @@ -94,11 +105,11 @@                                 ret_get <- aug_get aug_ptr (Data.ByteString.Char8.pack "$var")                                 assertEqual "testNullDefVar: Should have gotten localhost (1)" (Right (Just "localhost")) ret_get -                                ret_defvar <- aug_defvar aug_ptr (Data.ByteString.Char8.pack "var") Nothing-                                assertEqual "testNullDefVar (2)" success ret_defvar+                                ret_defvar2 <- aug_defvar aug_ptr (Data.ByteString.Char8.pack "var") Nothing+                                assertEqual "testNullDefVar (2)" success ret_defvar2 -                                ret_get <- aug_get aug_ptr (Data.ByteString.Char8.pack "$var")-                                assertEqual "testNullDefVar: Should have gotten localhost (2)" (Left invalid_match) ret_get+                                ret_get2 <- aug_get aug_ptr (Data.ByteString.Char8.pack "$var")+                                assertEqual "testNullDefVar: Should have gotten localhost (2)" (Left invalid_match) ret_get2                              ) @@ -108,11 +119,12 @@                                 assertEqual "testGoodDefVar (1)" (AugRet 12) ret_defvar                              )+#endif  -- ----------------- -- aug_defnode tests -- ------------------+#ifdef HAS_AUGEAS_DEFNODE testBadDefNode :: Test testBadDefNode = TestCase ( with_augptr $ \aug_ptr -> do                             ret_defnode <- aug_defnode aug_ptr (Data.ByteString.Char8.pack "var") (Data.ByteString.Char8.pack "$undefined") (Data.ByteString.Char8.pack "haskell-augeas.org")@@ -131,10 +143,10 @@                            assertEqual "defnode (2)" (Right (Just "haskell-augeas.org")) ret_get                             -- The node already exists, so it should not be set to the new value-                           ret_defvar <- aug_defnode aug_ptr (Data.ByteString.Char8.pack "bar") (Data.ByteString.Char8.pack "/files/etc/hosts/1000/canonical") (Data.ByteString.Char8.pack "haskell-augeas2.org")-                           assertEqual "defnode (3)" ((AugRet 1),(Just False)) ret_defvar-                           ret_get <- aug_get aug_ptr (Data.ByteString.Char8.pack "$bar")-                           assertEqual "defnode(4)" (Right (Just "haskell-augeas.org")) ret_get+                           ret_defvar2 <- aug_defnode aug_ptr (Data.ByteString.Char8.pack "bar") (Data.ByteString.Char8.pack "/files/etc/hosts/1000/canonical") (Data.ByteString.Char8.pack "haskell-augeas2.org")+                           assertEqual "defnode (3)" ((AugRet 1),(Just False)) ret_defvar2+                           ret_get2 <- aug_get aug_ptr (Data.ByteString.Char8.pack "$bar")+                           assertEqual "defnode(4)" (Right (Just "haskell-augeas.org")) ret_get2                         )  --testNonZeroDefNode :: Test@@ -142,11 +154,12 @@ --                                ret_defnode <- aug_defnode aug_ptr (Data.ByteString.Char8.pack "var") (Data.ByteString.Char8.pack "/files/etc/hosts") (Data.ByteString.Char8.pack "unset") --                                assertEqual "testNonZeroDefVar (1)" ((AugRet 12),(Just False)) ret_defnode --                            )+#endif  -- ------------- -- aug_get tests -- --------------+#ifdef HAS_AUGEAS_GET testGetBadPath :: Test testGetBadPath = TestCase ( with_augptr $ \aug_ptr -> do                                ret_get <- aug_get aug_ptr bs_BadPath@@ -188,11 +201,12 @@                                   ret_get <- aug_get aug_ptr (Data.ByteString.Char8.pack "/files/etc/hosts/*/invalid")                                   assertEqual "Get should return a negative on multiple matches (2)" (Left no_match) ret_get                               )+#endif  -- ------------- -- aug_set tests -- --------------+#ifdef HAS_AUGEAS_SET testSetLabel :: Test testSetLabel = TestCase ( with_augptr $ \aug_ptr -> do                               ret_set <- aug_set aug_ptr (Data.ByteString.Char8.pack "/files/etc/hosts/1000/canonical") (Data.ByteString.Char8.pack "haskell-augeas.org")@@ -210,10 +224,12 @@                               assertEqual "testSetMultiMatch error" no_error ret_error                               )+#endif  -- ---------------- -- aug_insert tests -- ----------------+#ifdef HAS_AUGEAS_INSERT testInsertBadPath :: Test testInsertBadPath = TestCase ( with_augptr $ \aug_ptr -> do                                ret_insert <- aug_insert aug_ptr bs_BadPath (Data.ByteString.Char8.pack "label") just_after@@ -242,17 +258,19 @@                             ret_insert <- aug_insert aug_ptr (Data.ByteString.Char8.pack "/files/etc/hosts/1000/canonical") (Data.ByteString.Char8.pack "after") just_after                             assertEqual "Insert after success" success ret_insert -                            ret_insert <- aug_insert aug_ptr (Data.ByteString.Char8.pack "/files/etc/hosts/1000/canonical") (Data.ByteString.Char8.pack "before") just_before-                            assertEqual "Insert before success" success ret_insert+                            ret_insert2 <- aug_insert aug_ptr (Data.ByteString.Char8.pack "/files/etc/hosts/1000/canonical") (Data.ByteString.Char8.pack "before") just_before+                            assertEqual "Insert before success" success ret_insert2                              (match_count, (Just matches)) <- aug_match aug_ptr (Data.ByteString.Char8.pack "/files/etc/hosts/1000/*")                             assertEqual "Should be 3 matches" 3 match_count                             assertEqual "insert matches" ["/files/etc/hosts/1000/before","/files/etc/hosts/1000/canonical","/files/etc/hosts/1000/after"] matches                         )+#endif  -- ------------ -- aug_rm tests -- ------------+#ifdef HAS_AUGEAS_RM testRmBadPath :: Test testRmBadPath = TestCase ( with_augptr $ \aug_ptr -> do                                ret_rm <- aug_rm aug_ptr bs_BadPath@@ -279,10 +297,12 @@                          ret_rm <- aug_rm aug_ptr (Data.ByteString.Char8.pack "/files/etc/hosts/1000/*")                          assertEqual "rm 2" 2 ret_rm                      )+#endif  -- ------------ -- aug_mv tests -- ------------+#ifdef HAS_AUGEAS_MV testMvBadSrc :: Test testMvBadSrc = TestCase ( with_augptr $ \aug_ptr -> do                             ret_mv <- aug_mv aug_ptr bs_BadPath (Data.ByteString.Char8.pack "/files/etc/hosts/1/badpath")@@ -304,13 +324,15 @@                              ret_get <- aug_get aug_ptr (Data.ByteString.Char8.pack "/files/etc/hosts/1001/canonical")                              assertEqual "get 1001 OK" (Right (Just "haskell-augeas.org")) ret_get -                             ret_get <- aug_get aug_ptr (Data.ByteString.Char8.pack "/files/etc/hosts/1000/canonical")-                             assertEqual "get 1000 OK" (Left no_match) ret_get+                             ret_get2 <- aug_get aug_ptr (Data.ByteString.Char8.pack "/files/etc/hosts/1000/canonical")+                             assertEqual "get 1000 OK" (Left no_match) ret_get2                         )+#endif  -- --------------- -- aug_match tests -- ---------------+#ifdef HAS_AUGEAS_MATCH testMatchBadSrc :: Test testMatchBadSrc = TestCase ( with_augptr $ \aug_ptr -> do                             (match_count, matches) <- aug_match aug_ptr bs_BadPath @@ -329,25 +351,31 @@ testMatchMultiple = TestCase ( with_augptr $ \aug_ptr -> do                                  (match_count, matches) <- aug_match aug_ptr (Data.ByteString.Char8.pack "/files/etc/hosts/*/canonical")                                  assertEqual "match count good label" 9 match_count+                                 case matches of+                                   (Just ms) ->   assertEqual "match len equals match_count" (Prelude.length(ms)) match_count+                                   Nothing   ->  fail "matches should not bbe Nothing"                              ) -- TODO:  Test that forces -1 return value from aug_match+#endif  -- -------- -- aug_save -- --------+#ifdef HAS_AUGEAS_SAVE testSave :: Test testSave = TestCase ( with_augptr $ \aug_ptr -> do                             ret_save <- aug_save aug_ptr                              assertEqual "save good" success ret_save                           ) +testSaveNewLabel :: Test testSaveNewLabel = TestCase ( with_augptr $ \aug_ptr -> do                                ret_set <- aug_set aug_ptr (Data.ByteString.Char8.pack "/files/etc/hosts/1000/ipaddr") (Data.ByteString.Char8.pack "192.168.1.234")                               assertEqual "set OK" success ret_set -                              ret_set <- aug_set aug_ptr (Data.ByteString.Char8.pack "/files/etc/hosts/1000/canonical") (Data.ByteString.Char8.pack "haskell-augeas.org")-                              assertEqual "set OK" success ret_set+                              ret_set2 <- aug_set aug_ptr (Data.ByteString.Char8.pack "/files/etc/hosts/1000/canonical") (Data.ByteString.Char8.pack "haskell-augeas.org")+                              assertEqual "set OK" success ret_set2                                ret_save <- aug_save aug_ptr                                assertEqual "save good" success ret_save@@ -361,8 +389,8 @@                               ret_rm <- aug_rm aug_ptr (Data.ByteString.Char8.pack "/files/etc/hosts/1000")                               assertEqual "Bad path in rm 2" 3 ret_rm -                              ret_save <- aug_save aug_ptr -                              assertEqual "save good" success ret_save+                              ret_save2 <- aug_save aug_ptr +                              assertEqual "save good" success ret_save2                                -- removing the /file/etc/hosts/10 entry will put /etc/hosts  back to its original state, so nothing will be written out                               -- so the augnew file shouldn't  exist@@ -370,10 +398,12 @@                               assertEqual "No augnew" b_AugnewExists False                                                            )+#endif  -- -------------- -- aug_load tests -- --------------+#ifdef HAS_AUGEAS_LOAD testLoad :: Test testLoad = TestCase ( with_augptr $ \aug_ptr -> do @@ -393,16 +423,19 @@                         renameFile (cwd++"/testroot/etc/hosts.orig") (cwd++"/testroot/etc/hosts")                      )+#endif  -- --------------- -- aug_print tests -- ---------------+#ifdef HAS_AUGEAS_PRINT testPrint :: Test testPrint = TestCase ( with_augptr $ \aug_ptr -> do                                                   cwd <- getCurrentDirectory                           fptr_Output <- openFile (cwd++"/HUnitAug.txt") WriteMode                          ret_print <- aug_print aug_ptr fptr_Output (Data.ByteString.Char8.pack "/files/etc/hosts")+                         assertEqual "testPrint ret_print" success ret_print                           IO.hPutStr fptr_Output "That's all folks"                          hFlush fptr_Output                          hClose fptr_Output@@ -413,10 +446,12 @@                          removeFile (cwd++"/HUnitAug.txt")                       )+#endif  -- --------------- -- aug_error tests -- ---------------+#ifndef HAS_AUGEAS_ERROR testError ::  Test testError = TestCase ( with_augptr $ \aug_ptr -> do                          @@ -425,14 +460,16 @@                                                 )+#endif  -- ---------------- -- aug_error* tests -- ----------------+#ifdef HAS_AUGEAS_ERROR_MESSAGE testErrMessage :: Test testErrMessage = TestCase ( with_augptr $ \aug_ptr -> do                             ret_defvar <- aug_defvar aug_ptr (Data.ByteString.Char8.pack "var") (Just (Data.ByteString.Char8.pack "$undefined"))-                            assertEqual "testErrMessage (1) " System.Augeas.error ret_defvar+                            assertEqual "testErrMessage (1)" System.Augeas.error ret_defvar                              ret_error <- aug_error aug_ptr                             assertEqual "testErrMessage (2)" err_bad_path ret_error@@ -440,93 +477,166 @@                             err_message <- aug_error_message aug_ptr                             assertEqual "testErrMessage (3)" (Data.ByteString.Char8.pack "Invalid path expression") err_message +#ifdef HAS_AUGEAS_ERROR_MINOR_MESSAGE                             err_minor_message <- aug_error_minor_message aug_ptr                             assertEqual "testErrMessage (4)" (Data.ByteString.Char8.pack "undefined variable") err_minor_message+#endif +#ifdef HAS_AUGEAS_ERROR_DETAILS                             err_details <- aug_error_details aug_ptr                             assertEqual "testErrMessage (4)" (Data.ByteString.Char8.pack "$undefined|=|") err_details+#endif                               )+#endif --- -------------------------- aug_error_message tests--- ----------------------- --- -------------------------------- aug_error_minor_message tests--- -----------------------------+-- --------------+-- aug_setm tests+-- --------------+#ifdef HAS_AUGEAS_SETM+testBadBaseSetm :: Test+testBadBaseSetm = TestCase ( with_augptr $ \aug_ptr -> do --- -------------------- aug_error_details--- -----------------+                        ret_setm <- aug_setm aug_ptr (Data.ByteString.Char8.pack "badbase") (Just (Data.ByteString.Char8.pack "sub")) (Data.ByteString.Char8.pack "value")+                        assertEqual "testBadBaseSetm (1)" (AugRet 0) ret_setm +                    )++testBadPathSetm :: Test+testBadPathSetm = TestCase ( with_augptr $ \aug_ptr -> do++                        ret_setm <- aug_setm aug_ptr (Data.ByteString.Char8.pack "/") (Just (Data.ByteString.Char8.pack "/blah/*/blah/**")) (Data.ByteString.Char8.pack "value")+                        assertEqual "testBadPathSetm (1)" (AugRet (-1)) ret_setm++                    )++testSetm :: Test+testSetm = TestCase ( with_augptr $ \aug_ptr -> do++                        ret_set <- aug_set aug_ptr (Data.ByteString.Char8.pack "/files/etc/hosts/1000/canonical") (Data.ByteString.Char8.pack "haskell-augeas.org")+                        assertEqual "set OK" success ret_set++                        ret_setm <- aug_setm aug_ptr (Data.ByteString.Char8.pack "/files/etc/hosts/1000/canonical") (Just (Data.ByteString.Char8.pack "sub/1")) (Data.ByteString.Char8.pack "value")+                        assertEqual "testSetm (1)" (AugRet 1) ret_setm++                        ret_get <- aug_get aug_ptr (Data.ByteString.Char8.pack "/files/etc/hosts/1000/canonical/sub/1")+                        assertEqual "set OK" (Right (Just "value")) ret_get++                        ret_setm2 <- aug_setm aug_ptr (Data.ByteString.Char8.pack "/files/etc/hosts/1000/canonical/sub/1") Nothing (Data.ByteString.Char8.pack "value2")+                        assertEqual "testSetm (2)" (AugRet 1) ret_setm2++                        ret_get2 <- aug_get aug_ptr (Data.ByteString.Char8.pack "/files/etc/hosts/1000/canonical/sub/1")+                        assertEqual "set OK" (Right (Just "value2")) ret_get2++                        ret_setm3 <- aug_setm aug_ptr (Data.ByteString.Char8.pack "/files/etc/hosts/1000/canonical") (Just (Data.ByteString.Char8.pack "sub/2")) (Data.ByteString.Char8.pack "value3")+                        assertEqual "testSetm (3)" (AugRet 1) ret_setm3++                        ret_get3 <- aug_get aug_ptr (Data.ByteString.Char8.pack "/files/etc/hosts/1000/canonical/sub/2")+                        assertEqual "set OK" (Right (Just "value3")) ret_get3++                        ret_setm4 <- aug_setm aug_ptr (Data.ByteString.Char8.pack "/files/etc/hosts/1000/canonical/sub/*") Nothing (Data.ByteString.Char8.pack "value4")+                        assertEqual "testSetm (4)" (AugRet 2) ret_setm4++                        ret_get4 <- aug_get aug_ptr (Data.ByteString.Char8.pack "/files/etc/hosts/1000/canonical/sub/1")+                        assertEqual "set OK" (Right (Just "value4")) ret_get4++                        ret_get5 <- aug_get aug_ptr (Data.ByteString.Char8.pack "/files/etc/hosts/1000/canonical/sub/2")+                        assertEqual "set OK" (Right (Just "value4")) ret_get5+++                    )+#endif+++ main :: IO Counts main = runTestTT $ TestList [         -- testBadRoot,+        testFirst -        -- aug_defvar-        testBadDefVar,-        testGoodDefVar,-        testReplaceDefVar,-        testNullValueDefVar,-        testNonZeroDefVar,+#ifdef HAS_AUGEAS_DEFVAR+        ,testBadDefVar+        ,testGoodDefVar+        ,testReplaceDefVar+        ,testNullValueDefVar+        ,testNonZeroDefVar+#endif         -        -- auf_defnode-        testBadDefNode,-        testDefNode,---        testNonZeroDefNode,+#ifdef HAS_AUGEAS_DEFNODE+        ,testBadDefNode+        ,testDefNode+--        ,testNonZeroDefNode+#endif -        -- aug_get tests-        testGetBadPath,-        testGetPartialPath,-        testGetStillPartialPath,-        testGetBadLabel,-        testGetGoodLabel,-        testGetMultipleLabel,-        testGetBadMultipleLabel,+#ifdef HAS_AUGEAS_GET+        ,testGetBadPath+        ,testGetPartialPath+        ,testGetStillPartialPath+        ,testGetBadLabel+        ,testGetGoodLabel+        ,testGetMultipleLabel+        ,testGetBadMultipleLabel+#endif -        -- aug_set tests-        testSetLabel,-        testSetMultiMatch,+#ifdef HAS_AUGEAS_SET+        ,testSetLabel+        ,testSetMultiMatch+#endif -        -- aug_insert tests-        testInsertBadPath,-        testInsertMultiMatch,-        testInsertBeforeAfter,+#ifdef HAS_AUGEAS_INSERT+        ,testInsertBadPath+        ,testInsertMultiMatch+        ,testInsertBeforeAfter+#endif -        -- aug_rm tests-        testRmBadPath,-        testRmOne,-        testRmTwo,+#ifdef HAS_AUGEAS_RM+        ,testRmBadPath+        ,testRmOne+        ,testRmTwo+#endif -        -- aug_mv tests-        testMvBadSrc,-        testMvNewDest,+#ifdef HAS_AUGEAS_MV+        ,testMvBadSrc+        ,testMvNewDest+#endif -        -- aug_match tests-        testMatchBadSrc,-        testMatchOne,-        testMatchMultiple,+#ifdef HAS_AUGEAS_MATCH+        ,testMatchBadSrc+        ,testMatchOne+        ,testMatchMultiple+#endif -        -- aug_save tests-        testSave,-        testSaveNewLabel,+#ifdef HAS_AUGEAS_SAVE+        ,testSave+        ,testSaveNewLabel+#endif -        -- aug_load-        testLoad,+#ifdef HAS_AUGEAS_LOAD+        ,testLoad+#endif -        -- aug_print tests-        testPrint,+#ifdef HAS_AUGEAS_PRINT+        ,testPrint+#endif -        -- aug_error-        -- aug_error_message++#ifndef HAS_AUGEAS_ERROR+        ,testError+#endif+#ifdef HAS_AUGEAS_ERROR_MESSAGE         -- aug_error_minor_message         -- aug_error_details-        testError,-        testErrMessage+        ,testErrMessage+#endif -        -- aug_close already handled in ForeignPtr, so there's no need to surface it to Haskell users at all.+#ifdef HAS_AUGEAS_SETM+        ,testBadBaseSetm+        ,testBadPathSetm+        ,testSetm+#endif +        -- aug_close already handled in ForeignPtr, so there's no need to surface it to Haskell users at all.         ]
Setup.hs view
@@ -3,7 +3,7 @@ -- file: Setup.hs  -- Haskell bindings for the Augeas library--- Copyright (c) 2009, Jude Nagurney+-- Copyright (c) 2009-2010, Jude Nagurney -- -- This program is free software; you can redistribute it and/or modify it  -- under the terms of the GNU General Public License as published by the Free @@ -29,7 +29,7 @@ -- main = defaultMain  -- Thanks http://mechablue.livejournal.com/11055.html-main = defaultMainWithHooks simpleUserHooks { runTests = _runTests, instHook = _instHook }+main = defaultMainWithHooks autoconfUserHooks { runTests = _runTests, instHook = _instHook }     where         -- Run all executables with names that end in -tests         _runTests _ _ pd _ = do@@ -45,11 +45,7 @@             let execs = filter (\e -> not $ isInfixOf "test-" (exeName e)) (executables pd)             (instHook simpleUserHooks) (pd {executables = execs}) lbi uhs ifs  ---tests _ _ _ _ = do----- setCurrentDirectory "src"--- h <- runCommand "/usr/bin/env runghc -laugeas HUnitAug"--- waitForProcess h--- return ()+   
System/Augeas.hs view
@@ -1,7 +1,7 @@--- file: Setup.hs+-- file: System/Augeas.hs  -- Haskell bindings for the Augeas library--- Copyright (c) 2009, Jude Nagurney+-- Copyright (c) 2009-2010, Jude Nagurney -- -- This program is free software; you can redistribute it and/or modify it  -- under the terms of the GNU General Public License as published by the Free @@ -21,6 +21,11 @@  {-# LANGUAGE CPP, ForeignFunctionInterface #-} +#ifndef _config_h+#include "../Config.h"+#define _config_h+#endif+ {-|   This module provides FFI bindings for the Augeas API (<http://augeas.net/docs/api.html>).   @@ -59,6 +64,7 @@     , aug_error_message             , aug_error_minor_message     , aug_error_details+    , aug_setm     ) where  import System.IO@@ -67,8 +73,8 @@ import Foreign import Foreign.C.Types import Foreign.C.String-import GHC.Handle-import Data.ByteString+import GHC.IO.Handle+import Data.ByteString.Char8  import System.AugeasHsc @@ -166,7 +172,7 @@ -- --------  -- TODO:  Replace loadpath string with a dedicated loadpath type ?-foreign import ccall unsafe "augeas.h aug_init"+foreign import ccall safe "augeas.h aug_init"    c_aug_init :: CString -> CString -> AugFlag -> IO (Ptr Augeas)              {-|@@ -190,11 +196,12 @@  /Therefore, there is no need to surface aug_close in the library./   -}-aug_init :: ByteString                   -- ^ ROOT-         -> ByteString                   -- ^ LOADPATH-         -> [AugFlag]                    -- ^ FLAGS-         -> IO (Maybe (ForeignPtr Augeas)) -- ^ Augeas pointer-aug_init bstr1 bstr2 flags =++aug_init :: ByteString            -- ^ ROOT+          -> ByteString           -- ^ LOADPATH+          -> [AugFlag]            -- ^ FLAGS+          -> IO (Maybe (ForeignPtr Augeas)) -- ^ Augeas pointer+aug_init bstr1 bstr2 flags  =      useAsCString bstr1 $ \root -> do        useAsCString bstr2 $ \loadpath -> do          aug_ptr <- c_aug_init root loadpath (combineFlags flags)@@ -209,7 +216,7 @@ -- aug_close -- --------- -foreign import ccall unsafe "augeas.h &aug_close"+foreign import ccall safe "augeas.h &aug_close"         c_aug_close :: FinalizerPtr Augeas  --{-|@@ -224,11 +231,14 @@ -- ---------- -- aug_defvar -- -----------foreign import ccall unsafe "augeas.h aug_defvar"+#ifdef HAS_AUGEAS_DEFVAR+foreign import ccall safe "augeas.h aug_defvar"         c_aug_defvar :: Ptr Augeas                  -- aug                      -> CString                     -- name                      -> CString                     -- expr                      -> IO (AugRet)                 -- return_value+#endif+ {-|     Function: aug_defvar   @@ -249,27 +259,31 @@            -> ByteString  -- ^ NAME            -> (Maybe ByteString)  -- ^ Maybe EXPR            -> IO (AugRet) -- ^ AugRet-aug_defvar aug_ptr bstr1 (Just bstr2) = -           useAsCString bstr1 $ \name -> do-             useAsCString bstr2 $ \expr -> do-                ret <- c_aug_defvar aug_ptr name expr-                return ret -aug_defvar aug_ptr bstr1 Nothing = -           useAsCString bstr1 $ \name -> do-             ret <- c_aug_defvar aug_ptr name nullPtr-             return ret+aug_defvar aug_ptr bstr1 maybe_bstr2 = +#ifndef HAS_AUGEAS_DEFVAR+               Prelude.error "aug_defvar requires at least augeas version 0.5.0"+#else+               useAsCString bstr1 $ \name -> do+                 ret <- (case maybe_bstr2 of+                           (Just bstr2) ->  useAsCString bstr2 $ \expr -> do c_aug_defvar aug_ptr name expr+                           (Nothing) ->     c_aug_defvar aug_ptr name nullPtr)                   +                 return ret+#endif  -- ----------- -- aug_defnode -- ------------foreign import ccall unsafe "augeas.h aug_defnode"+#ifdef HAS_AUGEAS_DEFNODE+foreign import ccall safe "augeas.h aug_defnode"         c_aug_defnode :: Ptr Augeas                  -- aug                       -> CString                     -- name                       -> CString                     -- expr                       -> CString                     -- value                       -> Ptr CInt                    -- created                       -> IO (CInt)               -- return_value+#endif+ {-|    Function: aug_defnode @@ -288,36 +302,45 @@  Returns -1 on error; on success, returns the number of nodes in the  nodeset  -}+++ aug_defnode :: Ptr Augeas  -- ^ Augeas pointer             -> ByteString  -- ^ NAME             -> ByteString  -- ^ EXPR             -> ByteString  -- ^ VALUE-        -> IO (AugRet,Maybe Bool) -- ^ (AugMatch,b_NodeCreated)+            -> IO (AugRet,Maybe Bool) -- ^ (AugMatch,b_NodeCreated) aug_defnode aug_ptr bstr1 bstr2 bstr3 = -           useAsCString bstr1 $ \name -> do-             useAsCString bstr2 $ \expr -> do-               useAsCString bstr3 $ \value -> do-                 alloca $ \created -> do-                   ret <- c_aug_defnode aug_ptr name expr value created-                   if ret /= -1 +#ifndef HAS_AUGEAS_DEFNODE+        Prelude.error "aug_defnode requires at least augeas version 0.5.0"+#else+        useAsCString bstr1 $ \name -> do+          useAsCString bstr2 $ \expr -> do+            useAsCString bstr3 $ \value -> do+              alloca $ \created -> do+                ret <- c_aug_defnode aug_ptr name expr value created+                if ret /= -1 +                  then do+                    i_created <- peek created+                    if i_created == 0                        then do-                        i_created <- peek created-                        if i_created == 0 -                           then do-                             return ((AugRet ret), Just False)-                           else do-                             return ((AugRet ret), Just True)+                        return ((AugRet ret), Just False)                       else do-                        return ((AugRet ret), Nothing)+                        return ((AugRet ret), Just True)+                  else do+                    return ((AugRet ret), Nothing)+#endif  -- ------- -- aug_get  -- --------foreign import ccall unsafe "augeas.h aug_get"-        c_aug_get :: Ptr Augeas                  -- aug-                  -> CString                     -- path-                  -> Ptr CString                 -- value-                  -> IO (CInt)               -- return_value+#ifdef HAS_AUGEAS_GET+foreign import ccall safe "augeas.h aug_get"+        c_aug_get :: Ptr Augeas     -- aug+                  -> CString        -- path+                  -> Ptr CString    -- value+                  -> IO (CInt)      -- return_value+#endif  {-|     Lookup the value associated with PATH. VALUE can be NULL, in which case@@ -336,33 +359,40 @@         -> ByteString  -- ^ PATH         -> IO (Either AugMatch (Maybe String)) -- ^ Either AugMatch or VALUE aug_get aug_ptr bstr1 = -        useAsCString bstr1 $ \path -> do-          alloca $ \value -> do-            ret <- c_aug_get aug_ptr path value-            if ret == 1-               then do -                 if value == nullPtr -                    then do-                      return (Left (AugMatch ret))-                    else do-                      peeked <- peek value-                      if peeked == nullPtr-                         then do-                             return (Right Nothing)-                         else do-                             str_peeked <- peekCString peeked-                             return (Right (Just str_peeked))-               else do                   -                 return (Left (AugMatch ret))+#ifndef HAS_AUGEAS_GET+    Prelude.error "aug_get requires at least augeas version 0.0.1"+#else+    useAsCString bstr1 $ \path -> do+      alloca $ \value -> do+        ret <- c_aug_get aug_ptr path value+        if ret == 1+           then do +             if value == nullPtr +                then do+                  return (Left (AugMatch ret))+                else do+                  peeked <- peek value+                  if peeked == nullPtr+                     then do+                         return (Right Nothing)+                     else do+                         str_peeked <- peekCString peeked+                         return (Right (Just str_peeked))+           else do                   +             return (Left (AugMatch ret)) +#endif+ -- ------- -- aug_set -- --------foreign import ccall unsafe "augeas.h aug_set"+#ifdef HAS_AUGEAS_SET+foreign import ccall safe "augeas.h aug_set"         c_aug_set :: Ptr Augeas                  -- aug                   -> CString                     -- path                   -> CString                     -- value                   -> IO (AugRet)                   -- return value+#endif  {-| @@ -379,20 +409,26 @@         -> ByteString  -- ^ VALUE         -> IO (AugRet) -- ^ return value aug_set aug_ptr bs1 bs2 = -         useAsCString bs1 $ \path -> do-           useAsCString bs2 $ \value -> do-              ret <- c_aug_set aug_ptr path value-              return ret+#ifndef HAS_AUGEAS_SET+    Prelude.error "aug_insert requires at least augeas version 0.0.1"+#else+    useAsCString bs1 $ \path -> do+      useAsCString bs2 $ \value -> do+         ret <- c_aug_set aug_ptr path value+         return ret+#endif  -- ---------- -- aug_insert -- -----------foreign import ccall unsafe "augeas.h aug_insert"+#ifdef HAS_AUGEAS_INSERT+foreign import ccall safe "augeas.h aug_insert"         c_aug_insert :: Ptr Augeas               -- aug                      -> CString                  -- path                      -> CString                  -- label                      -> AugBefore                -- before                      -> IO (AugRet)              -- return value+#endif  {-| @@ -412,18 +448,24 @@            -> AugBefore    -- ^ BEFORE            -> IO (AugRet)  -- ^ return value aug_insert aug_ptr bs1 bs2 before = -         useAsCString bs1 $ \path -> do-           useAsCString bs2 $ \label -> do-              ret <- c_aug_insert aug_ptr path label before-              return ret+#ifndef HAS_AUGEAS_INSERT+    Prelude.error "aug_insert requires at least augeas version 0.0.1"+#else+    useAsCString bs1 $ \path -> do+      useAsCString bs2 $ \label -> do+         ret <- c_aug_insert aug_ptr path label before+         return ret+#endif  -- ------ -- aug_rm -- -------foreign import ccall unsafe "augeas.h aug_rm"+#ifdef HAS_AUGEAS_RM+foreign import ccall safe "augeas.h aug_rm"         c_aug_rm :: Ptr Augeas                   -- aug                  -> CString                      -- path                  -> IO (CInt)                    -- return value+#endif  {-| @@ -435,18 +477,24 @@        -> ByteString  -- ^ PATH        -> IO (CInt)   -- ^ number of entries removed aug_rm aug_ptr bs_path = +#ifndef HAS_AUGEAS_RM+    Prelude.error "aug_mv requires at least augeas version 0.0.1"+#else     useAsCString bs_path $ \path -> do           ret <- c_aug_rm aug_ptr path       return ret+#endif  -- ------ -- aug_mv -- -------foreign import ccall unsafe "augeas.h aug_mv"+#ifdef HAS_AUGEAS_MV+foreign import ccall safe "augeas.h aug_mv"         c_aug_mv :: Ptr Augeas                   -- aug                  -> CString                      -- src                  -> CString                      -- dst                  -> IO (AugRet)                    -- return value+#endif  {- |  Move the node SRC to DST. SRC must match exactly one node in the@@ -466,19 +514,25 @@        -> ByteString  -- ^ DEST        -> IO (AugRet) -- ^ return value aug_mv aug_ptr bs_src bs_dst = -    useAsCString bs_src $ \src -> do-      useAsCString bs_dst $ \dst -> do-         ret <- c_aug_mv aug_ptr src dst-         return ret+#ifndef HAS_AUGEAS_MV+        Prelude.error "aug_mv requires at least augeas version 0.3.0"+#else+        useAsCString bs_src $ \src -> do+          useAsCString bs_dst $ \dst -> do+             ret <- c_aug_mv aug_ptr src dst+             return ret+#endif  -- --------- -- aug_match -- ----------foreign import ccall unsafe "augeas.h aug_match"+#ifdef HAS_AUGEAS_MATCH+foreign import ccall safe "augeas.h aug_match"         c_aug_match :: Ptr Augeas                -- aug                     -> CString                   -- path                     -> Ptr (Ptr CString)         -- matches                     -> IO (CInt)                 -- return value+#endif  {-|  Return the number of matches of the path expression PATH in AUG. If@@ -510,6 +564,9 @@           -> ByteString    -- ^ PATH           -> IO (Int, Maybe [String]) -- ^ (match count, MATCHES) aug_match aug_ptr bs_path = +#ifndef HAS_AUGEAS_MATCH+   Prelude.error "aug_match requires at least augeas version 0.0.1"  +#else     useAsCString bs_path $ \path -> do       alloca $ \matches -> do         ret <- c_aug_match aug_ptr path matches@@ -523,13 +580,16 @@              matches_strs <- Prelude.foldr (\t io_l -> do s <- peekCString t; l <- io_l; return (s:l)) (return []) matches_cstrs               return (fromIntegral ret, Just matches_strs)+#endif  -- -------- -- aug_save -- ---------foreign import ccall unsafe "augeas.h aug_save"+#ifdef HAS_AUGEAS_SAVE+foreign import ccall safe "augeas.h aug_save"         c_aug_save :: Ptr Augeas                 -- aug                    -> IO (AugRet)                  -- return value+#endif  {-| @@ -551,16 +611,23 @@ aug_save :: Ptr Augeas    -- ^ Augeas pointer          -> IO (AugRet)   -- ^ return value aug_save aug_ptr = -                   do -                     ret <- c_aug_save aug_ptr-                     return ret+#ifndef HAS_AUGEAS_SAVE+    Prelude.error "aug_save requires at least augeas version 0.0.1"+#else+    do +      ret <- c_aug_save aug_ptr+      return ret+#endif  -- -------- -- aug_load -- ---------foreign import ccall unsafe "augeas.h aug_load"+#ifdef HAS_AUGEAS_LOAD+foreign import ccall safe "augeas.h aug_load"         c_aug_load :: Ptr Augeas                -- aug                     -> IO (CInt)                 -- return value+#endif+ {-|  Function: aug_load  @@ -595,9 +662,13 @@ aug_load :: Ptr Augeas    -- ^ Augeas pointer          -> IO (AugRet)   -- ^ return value aug_load aug_ptr = -                   do -                     ret <- c_aug_load aug_ptr-                     return (AugRet ret)+#ifndef HAS_AUGEAS_LOAD+    Prelude.error "aug_load requires at least augeas version 0.5.0"+#else+    do+      ret <- c_aug_load aug_ptr+      return (AugRet ret)+#endif  -- --------- -- aug_print@@ -619,11 +690,13 @@     fdopen fd iomode  -- surface aug_print-foreign import ccall unsafe "augeas.h aug_print"+#ifdef HAS_AUGEAS_PRINT+foreign import ccall safe "augeas.h aug_print"         c_aug_print :: Ptr Augeas               -- aug                     -> Ptr CFile                -- out                     -> CString                  -- path                     -> IO (AugRet)              -- return value+#endif  {-|  Print each node matching PATH and its descendants to OUT.@@ -636,75 +709,101 @@           -> ByteString  -- ^ PATH           -> IO (AugRet) -- ^ return value aug_print aug_ptr fptr_out bs_path = -    do -      useAsCString bs_path $ \path -> do-        out <- handleToCFile fptr_out "w"-        ret <- c_aug_print aug_ptr out path-        fflush out-        fclose out-        return(ret)+#ifndef HAS_AUGEAS_PRINT+   Prelude.error "aug_print requires at least augeas version 0.0.1"+#else+   useAsCString bs_path $ \path -> do+     out <- handleToCFile fptr_out "w"+     ret <- c_aug_print aug_ptr out path+     _ <- fflush out+     _ <- fclose out+     return(ret)+#endif   -- --------- -- aug_error -- ----------foreign import ccall unsafe "augeas.h aug_error"+#ifdef HAS_AUGEAS_ERROR+foreign import ccall safe "augeas.h aug_error"         c_aug_error :: Ptr Augeas               -- aug                     -> IO (AugErrCode)          -- error code+#endif  {-|  Return a human-readable message for the error code */ -}  aug_error :: Ptr Augeas  -- ^ Augeas pointer-          -> IO (AugErrCode) -- ^ return value+           -> IO (AugErrCode) -- ^ return value aug_error aug_ptr = -    do -        ret <- c_aug_error aug_ptr-        return(ret)+#ifndef HAS_AUGEAS_ERROR+        Prelude.error "aug_error requires at least augeas version 0.6.0"+#else+        do +          ret <- c_aug_error aug_ptr+          return(ret)+#endif  -- ----------------- -- aug_error_message -- ------------------foreign import ccall unsafe "augeas.h aug_error_message"+#ifdef HAS_AUGEAS_ERROR_MESSAGE+foreign import ccall safe "augeas.h aug_error_message"         c_aug_error_message :: Ptr Augeas               -- aug                             -> IO (CString)             -- return value+#endif+ {-|  Return a human-readable message for the error code */ -} aug_error_message :: Ptr Augeas  -- ^ Augeas pointer                   -> IO (ByteString) -- ^ return value aug_error_message aug_ptr = -    do -        cstr <- c_aug_error_message aug_ptr-        ret <- packCString cstr-        return(ret)+#ifndef HAS_AUGEAS_ERROR_MESSAGE+    Prelude.error "aug_error_message requires at least augeas version 0.6.0"+#else+    do+      cstr <- c_aug_error_message aug_ptr+      ret <- packCString cstr+      return(ret)+#endif  -- ----------------------- -- aug_error_minor_message -- ------------------------foreign import ccall unsafe "augeas.h aug_error_minor_message"+#ifdef HAS_AUGEAS_ERROR_MINOR_MESSAGE+foreign import ccall safe "augeas.h aug_error_minor_message"         c_aug_error_minor_message :: Ptr Augeas               -- aug                                   -> IO (CString)             -- return value+#endif+ {-|  Return a human-readable message elaborating the error code; might be  NULL. For example, when the error code is AUG_EPATHX, this will explain  how the path expression is invalid */ -}-aug_error_minor_message :: Ptr Augeas  -- ^ Augeas pointer+aug_error_minor_message :: Ptr Augeas      -- ^ Augeas pointer                         -> IO (ByteString) -- ^ return value aug_error_minor_message aug_ptr = -    do -        cstr <- c_aug_error_minor_message aug_ptr-        ret <- packCString cstr-        return(ret)+#ifndef HAS_AUGEAS_ERROR_MINOR_MESSAGE+    Prelude.error "aug_error_minor_message requires at least augeas version 0.6.0"+#else+    do+      cstr <- c_aug_error_minor_message aug_ptr+      ret <- packCString cstr+      return(ret)+#endif  -- ----------------- -- aug_error_details -- ------------------foreign import ccall unsafe "augeas.h aug_error_details"+#ifdef HAS_AUGEAS_ERROR_DETAILS+foreign import ccall safe "augeas.h aug_error_details"         c_aug_error_details :: Ptr Augeas               -- aug                            -> IO (CString)             -- return value+#endif+ {-|  Return details about the error, which might be NULL. For example, for  AUG_EPATHX, indicates where in the path expression the error@@ -713,7 +812,51 @@ aug_error_details :: Ptr Augeas  -- ^ Augeas pointer                   -> IO (ByteString) -- ^ return value aug_error_details aug_ptr = +#ifndef HAS_AUGEAS_ERROR_DETAILS+    Prelude.error "aug_error_details requires at least augeas version 0.6.0"+#else     do -        cstr <- c_aug_error_details aug_ptr-        ret <- packCString cstr-        return(ret)+      cstr <- c_aug_error_details aug_ptr+      ret <- packCString cstr+      return(ret)+#endif++-- --------+-- aug_setm+-- --------+#ifdef HAS_AUGEAS_SETM+foreign import ccall safe "augeas.h aug_setm"+        c_aug_setm :: Ptr Augeas  -- aug+                      -> CString -- base+                      -> CString -- sub+                      -> CString -- value+                      -> IO (AugRet) --return value+#endif ++{-|+ Set the value of multiple nodes in one operation. Find or create a node+ matching SUB by interpreting SUB as a path expression relative to each+ node matching BASE. SUB may be NULL, in which case all the nodes+ matching BASE will be modified.++ Returns:+ number of modified nodes on success, -1 on error+-}+aug_setm :: Ptr Augeas          -- ^Augeas pointer+         -> ByteString          -- base+         -> (Maybe ByteString)  -- sub+         -> ByteString          -- value+         -> IO (AugRet)         -- retval+aug_setm aug_ptr bstr1 maybe_bstr2 bstr3  =+#ifndef HAS_AUGEAS_SETM+    Prelude.error "aug_setm requires at least augeas version 0.7.2"+#else+    useAsCString bstr1 $ \base -> do+      useAsCString bstr3 $ \value -> do+         ret <- (case maybe_bstr2 of+                   (Just bstr2) -> useAsCString bstr2 $ \sub -> do c_aug_setm aug_ptr base sub value+                   (Nothing) ->  c_aug_setm aug_ptr base nullPtr value+                ) +         return ret++#endif
System/AugeasHsc.hsc view
@@ -1,7 +1,7 @@ -- file: Augeas.hsc  -- Haskell bindings for the Augeas library--- Copyright (c) 2009, Jude Nagurney+-- Copyright (c) 2009-2010, Jude Nagurney -- -- This program is free software; you can redistribute it and/or modify it  -- under the terms of the GNU General Public License as published by the Free 
augeas.cabal view
@@ -1,5 +1,5 @@ Name: augeas-Version: 0.2.0+Version: 0.3.0 Synopsis:  A Haskell FFI wrapper for the Augeas API Description: A Haskell FFI wrapper for the Augeas API Author: Jude Nagurney@@ -16,7 +16,7 @@ library          Exposed-Modules: System.Augeas         Other-Modules: System.AugeasHsc-        Build-Depends: base >= 2.0 && <4, directory, unix >=2.3.0.0, bytestring >= 0.9.0.1+        Build-Depends: base >= 4.0 && <5, directory, unix >=2.3.0.0, bytestring >= 0.9.0.1         GHC-options: -Wall -fwarn-dodgy-imports  executable "test-haskell-augeas"@@ -24,5 +24,6 @@         Build-Depends: HUnit         Other-Modules: System.Augeas, System.AugeasHsc         extra-libraries: augeas+        GHC-options: -Wall -fwarn-dodgy-imports