chiasma-test 0.12.0.0 → 0.12.1.0
raw patch · 3 files changed
+70/−2 lines, 3 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Chiasma.Test.Data.TmuxTestConfig: instance GHC.Internal.Generics.Generic Chiasma.Test.Data.TmuxTestConfig.TmuxTestConfig
- Chiasma.Test.Data.TmuxTestConfig: instance GHC.Internal.Show.Show Chiasma.Test.Data.TmuxTestConfig.TmuxTestConfig
+ Chiasma.Test.Data.TmuxTestConfig: instance GHC.Generics.Generic Chiasma.Test.Data.TmuxTestConfig.TmuxTestConfig
+ Chiasma.Test.Data.TmuxTestConfig: instance GHC.Show.Show Chiasma.Test.Data.TmuxTestConfig.TmuxTestConfig
Files
- chiasma-test.cabal +3/−1
- test/Chiasma/Test/ProcessOutputTest.hs +61/−0
- test/Main.hs +6/−1
chiasma-test.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: chiasma-test-version: 0.12.0.0+version: 0.12.1.0 synopsis: Testing tools for chiasma description: See https://hackage.haskell.org/package/chiasma-test/docs/Chiasma-Test.html category: Terminal@@ -104,6 +104,7 @@ Chiasma.Test.LensTest Chiasma.Test.OutputParseTest Chiasma.Test.PinTest+ Chiasma.Test.ProcessOutputTest Chiasma.Test.PureTest Chiasma.Test.Util hs-source-dirs:@@ -153,6 +154,7 @@ , lens >=4 , polysemy , polysemy-plugin+ , polysemy-process , polysemy-test >=0.6 , prelate ==0.9.* , tasty
+ test/Chiasma/Test/ProcessOutputTest.hs view
@@ -0,0 +1,61 @@+module Chiasma.Test.ProcessOutputTest where++import qualified Data.ByteString as ByteString+import Hedgehog ((===))+import Polysemy.Process.Effect.ProcessOutput (OutputPipe (Stdout), ProcessOutput (Chunk))++import qualified Chiasma.Data.TmuxEvent as TmuxEvent+import Chiasma.Data.TmuxNotification (TmuxNotification (..))+import Chiasma.Data.TmuxOutputBlock (TmuxOutputBlock (..))+import Chiasma.Interpreter.ProcessOutput (interpretProcessOutputTmuxEvent)+import Chiasma.Test.Util (UnitTest)++-- | Simulate a 'Chunk' call via the interpreter, returning parsed events.+runChunk ::+ ByteString ->+ ByteString ->+ IO ([Either Text TmuxEvent.TmuxEvent], ByteString)+runChunk buffer new =+ runM $+ interpretProcessOutputTmuxEvent @'Stdout do+ send (Chunk buffer new)++-- | Two notifications concatenated in a single chunk.+-- The bug causes only the first to be parsed, the second is lost.+test_multiNotificationChunk :: UnitTest+test_multiNotificationChunk = do+ let+ chunk = ByteString.intercalate "" [+ "%window-add @1\n",+ "%session-changed $0 main\n"+ ]+ (events, _leftover) <- liftIO (runChunk "" chunk)+ [Right (TmuxEvent.Notification (TmuxNotification "window-add" ["@1"])),+ Right (TmuxEvent.Notification (TmuxNotification "session-changed" ["$0", "main"]))]+ === events++-- | A response block followed by a notification in one chunk.+test_responseAndNotificationChunk :: UnitTest+test_responseAndNotificationChunk = do+ let+ chunk = ByteString.intercalate "" [+ "%begin 123\n",+ "some data\n",+ "%end 123\n",+ "%window-add @5\n"+ ]+ (events, _leftover) <- liftIO (runChunk "" chunk)+ [Right (TmuxEvent.Response (Success ["some data"])),+ Right (TmuxEvent.Notification (TmuxNotification "window-add" ["@5"]))]+ === events++-- | Leftovers from a previous chunk are passed as the buffer argument.+-- The bug causes the buffer to be discarded.+test_bufferContinuation :: UnitTest+test_bufferContinuation = do+ let+ buffer = "%window-add"+ new = " @3\n"+ (events, _leftover) <- liftIO (runChunk buffer new)+ [Right (TmuxEvent.Notification (TmuxNotification "window-add" ["@3"]))]+ === events
test/Main.hs view
@@ -4,6 +4,8 @@ import Chiasma.Test.LensTest (test_lenses) import Chiasma.Test.OutputParseTest (test_outputParse) import Chiasma.Test.PinTest (test_pin)+import Chiasma.Test.ProcessOutputTest (test_bufferContinuation, test_multiNotificationChunk,+ test_responseAndNotificationChunk) import Chiasma.Test.Util (unitTest) import Test.Tasty (TestTree, defaultMain, testGroup) @@ -14,7 +16,10 @@ unitTest "tmux-encode a query" test_query, test_lenses, unitTest "parse tmux output" test_outputParse,- test_pin+ test_pin,+ unitTest "multiple notifications in one chunk" test_multiNotificationChunk,+ unitTest "response and notification in one chunk" test_responseAndNotificationChunk,+ unitTest "buffer continuation across chunks" test_bufferContinuation ] main :: IO ()