libmpd 0.3.0 → 0.3.1
raw patch · 6 files changed
+29/−26 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- ChangeLog +4/−1
- Network/MPD/Commands.hs +1/−1
- Network/MPD/SocketConn.hs +11/−5
- libmpd.cabal +1/−1
- tests/Properties.hs +10/−16
- tests/coverage +2/−2
ChangeLog view
@@ -1,4 +1,7 @@-* v0.2.2, 2008-05-06+* v0.3.1, 2008-09-14+ - Now reconnects if MPD closes the connection.++* v0.3.0, 2008-05-06 - UTF-8 support (now depends on utf8-string package). - Fixed corruption by `show' of command parameters. - Tidied up `Query' interface.
Network/MPD/Commands.hs view
@@ -529,7 +529,7 @@ -- ensure that no songs are deleted twice with 'max'. ys = case y of Just (Pos p) -> drop (max (fromInteger p) x') pl Just (ID i) -> maybe [] (flip drop pl . max x' . (+1))- (findByID i pl)+ (findByID i pl) Nothing -> [] deleteMany "" . mapMaybe sgIndex $ take x' pl ++ ys where findByID i = findIndex ((==) i . (\(ID j) -> j) . fromJust . sgIndex)
Network/MPD/SocketConn.hs view
@@ -30,8 +30,12 @@ let open' = open host port hR close' = close hR send' = send hR+ cautiousSend' x =+ send' x >>= either (\e -> case e of TimedOut -> open' >> send' x+ _ -> return $ Left e)+ (return . Right) open'- runMPD m (Conn open' close' send' getpw) `finally` close'+ runMPD m (Conn open' close' cautiousSend' getpw) `finally` close' open :: String -> Integer -> IORef (Maybe Handle) -> IO () open host port hR = withSocketsDo $ do@@ -42,7 +46,8 @@ close :: IORef (Maybe Handle) -> IO () close hR = readIORef hR >>= maybe (return ()) sendClose >> writeIORef hR Nothing- where sendClose h = hPutStrLn h "close" >> hClose h `catch` whenEOF ()+ where sendClose h = catch (hPutStrLn h "close" >> hReady h >> hClose h)+ (whenEOF $ writeIORef hR Nothing) send :: IORef (Maybe Handle) -> String -> IO (Response String) send hR str = do@@ -51,7 +56,8 @@ Nothing -> return $ Left NoMPD Just h -> do unless (null str) (U.hPutStrLn h str >> hFlush h)- getLines h [] `catch` whenEOF (Left TimedOut)+ catch (getLines h [])+ (whenEOF $ writeIORef hR Nothing >> return (Left TimedOut)) where getLines handle acc = do l <- U.hGetLine handle@@ -64,8 +70,8 @@ -- -- Return a value if the error is an EOFError, otherwise throw the error again.-whenEOF :: a -> IOError -> IO a-whenEOF result err = if isEOFError err then return result else ioError err+whenEOF :: IO a -> IOError -> IO a+whenEOF result err = if isEOFError err then result else ioError err safeConnectTo :: String -> Integer -> IO (Maybe Handle) safeConnectTo host port =
libmpd.cabal view
@@ -1,5 +1,5 @@ Name: libmpd-Version: 0.3.0+Version: 0.3.1 License: LGPL License-file: LICENSE Copyright: Ben Sinclair 2005-2008
tests/Properties.hs view
@@ -67,7 +67,7 @@ deriving Show instance Arbitrary BoolString where- arbitrary = fmap BS $ oneof [return "1", return "0"]+ arbitrary = fmap BS $ elements ["1", "0"] -- Positive integers. newtype PosInt = PI Integer@@ -148,20 +148,13 @@ field = (filter (/= '\n') . dropWhile isSpace) `fmap` arbitrary instance Arbitrary Count where- arbitrary = do- songs <- arbitrary- time <- arbitrary- return $ Count { cSongs = songs, cPlaytime = time }+ arbitrary = liftM2 Count arbitrary arbitrary prop_parseCount :: Count -> Bool prop_parseCount c = Right c == (parseCount . lines $ display c) instance Arbitrary Device where- arbitrary = do- did <- arbitrary- name <- field- enabled <- arbitrary- return $ Device did name enabled+ arbitrary = liftM3 Device arbitrary field arbitrary prop_parseOutputs :: [Device] -> Bool prop_parseOutputs ds =@@ -170,12 +163,13 @@ instance Arbitrary Song where arbitrary = do [file,artist,album,title,genre,name,cmpsr,prfmr] <- replicateM 8 field- date <- abs `fmap` arbitrary- len <- arbitrary- (track,disc) <- arbitrary- idx <- oneof [return Nothing- ,liftM (Just . Pos) arbitrary- ,liftM (Just . ID) arbitrary]+ date <- abs `fmap` arbitrary+ len <- abs `fmap` arbitrary+ track <- two $ abs `fmap` arbitrary+ disc <- two $ abs `fmap` arbitrary+ idx <- oneof [return Nothing+ ,liftM (Just . Pos) $ abs `fmap` arbitrary+ ,liftM (Just . ID) $ abs `fmap` arbitrary] return $ Song { sgArtist = artist, sgAlbum = album, sgTitle = title , sgFilePath = file, sgGenre = genre, sgName = name , sgComposer = cmpsr, sgPerformer = prfmr, sgLength = len
tests/coverage view
@@ -11,6 +11,6 @@ ./Main && \ hpc markup Main --destdir=report --exclude=Main --exclude=Properties \ --exclude=Displayable --exclude=Commands \- --exclude=Network.MPD.StringConn && \+ --exclude=StringConn && \ hpc report Main --exclude=Main --exclude=Properties --exclude=Commands \- --exclude=Displayable --exclude=Network.MPD.StringConn+ --exclude=Displayable --exclude=StringConn