on master help sign in
start converting verify-using-mock-input to test-framework + smallcheck
commit560c5d673b2b79b20cbad6a8c9412cc2db71619c authorCorey O'Connor <corey@ooyala.com> dateSat 19 Oct 2013, 23:20 (13 years ago) parent424e6a8
2 files changed+38−24
test/VerifyUsingMockInput.hs+32−19 vty.cabal+6−5
test/VerifyUsingMockInput.hs+32−19
@@ -2,8 +2,7 @@
22 - This assumes appropriate definitions exist in the current environment for the terminals of
33 - interest.
44 -}
5−module VerifyUsingMockInput where
6−import Verify hiding (classify)
5+module Main where
76
87import Verify.Graphics.Vty.Terminal
98
@@ -12,6 +11,7 @@ import Graphics.Vty.Input
1211import Graphics.Vty.Input.Data
1312import Graphics.Vty.Input.Internal
1413
14+import Control.Applicative
1515import Control.Concurrent
1616import Control.Exception
1717import Control.Monad
@@ -19,8 +19,9 @@ import Control.Monad
1919import System.Posix.Env
2020import System.IO
2121
22−import Test.QuickCheck.Assertions
23−import Test.QuickCheck.Property ( morallyDubiousIOProperty )
22+import Test.Framework.Providers.SmallCheck
23+import Test.Framework
24+import Test.SmallCheck
2425
2526-- processing a block of 16 chars is the largest I can do without taking too long to run the test.
2627max_bytes_size = 16
@@ -39,10 +40,7 @@ exec_input_spec input out_handle = forM_ input f
3940 f (Bytes str) = hPutStr out_handle str >> hFlush out_handle
4041 f (Delay t) = threadDelay (t*1000)
4142
42−assert_events_from_IO_reads :: InputSpec -> ExpectedSpec -> IO Result
43−assert_events_from_IO_reads input events = undefined
44−
45−assert_events_from_input_block :: ClassifyTable -> InputSpec -> ExpectedSpec -> IO Result
43+assert_events_from_input_block :: ClassifyTable -> InputSpec -> ExpectedSpec -> IO Bool
4644assert_events_from_input_block table input_spec expected_events = do
4745 let classifier = classify table
4846 input <- newChan
@@ -56,7 +54,7 @@ assert_events_from_input_block table input_spec expected_events = do
5654 let collect_events = handle (\(e :: BlockedIndefinitelyOnMVar) -> return [])
5755 ((:) <$> readChan output <*> collect_events)
5856 out_events <- collect_events
59− return $ out_events ?== expected_events
57+ return $ out_events == expected_events
6058
6159write_input_spec_to_chan :: Chan Char -> InputSpec -> IO ()
6260write_input_spec_to_chan chan [] = writeChan chan '\xFFFD'
@@ -65,7 +63,26 @@ write_input_spec_to_chan chan (Bytes str : input_spec')
6563write_input_spec_to_chan chan (Delay t : input_spec')
6664 = writeChan chan '\xFFFE' >> write_input_spec_to_chan chan input_spec'
6765
68−verify_simple_input_block_to_event :: Property
66+{-
67+
68+verify_keys_from_caps_table :: String -> Property
69+verify_keys_from_caps_table = do
70+ term_name <- elements terminals_of_interest
71+ cap <- elements keys_from_caps_table
72+
73+
74+tests :: IO [Test]
75+tests = do
76+ mappend
77+ <$> pure [ verify "basic block generated from single ansi chars to event translation" ]
78+ <*> mapM terminals_of_interest
79+ verify_simple_input_block_to_event
80+ , verify "keys from caps table are parsed to the same key"
81+ verify_keys_from_caps_table
82+ ]
83+
84+
85+verify_simple_input_block_to_event :: Int -> IO (Property IO)
6986verify_simple_input_block_to_event = do
7087 -- Ouch! 16 is as high as this can go without taking far too long. :-\
7188 Positive block_length <- resize 16 $ arbitrary
@@ -74,14 +91,10 @@ verify_simple_input_block_to_event = do
7491 events = map (\(k,ms) -> EvKey k ms) $ map snd block_event_pairs
7592 morallyDubiousIOProperty $ assert_events_from_input_block simple_chars input events
7693
77−verify_keys_from_caps_table :: String -> Result
78−verify_keys_from_caps_table term_name = succeeded
79−
80−tests :: IO [Test]
81−tests = return
82− [ verify "basic block generated from single ansi chars to event translation"
83− verify_simple_input_block_to_event
84− , verify "keys from caps table are parsed to the same key"
85− verify_keys_from_caps_table
94+main = defaultMain
95+ [ testProperty "basic block generated from a single ansi chars to event translation"
96+ verify_simple_input_block_to_event
8697 ]
98+-}
99+main = defaultMain []
87100
vty.cabal+6−5
@@ -506,20 +506,21 @@ test-suite verify-utf8-width
506506
507507test-suite verify-using-mock-input
508508 default-language: Haskell2010
509− default-extensions: ScopedTypeVariables
509+ default-extensions: ScopedTypeVariables
510510
511− type: detailed-0.9
511+ type: exitcode-stdio-1.0
512512
513513 hs-source-dirs: test
514514
515− test-module: VerifyUsingMockInput
516−
517− other-modules: Verify
515+ main-is: VerifyUsingMockInput.hs
518516
519517 build-depends: vty,
520518 Cabal == 1.18.*,
521519 QuickCheck >= 2.4,
520+ smallcheck == 1.*,
522521 quickcheck-assertions >= 0.1.1,
522+ test-framework == 0.8.*,
523+ test-framework-smallcheck == 0.2.*,
523524 random == 1.0.*,
524525 base >= 4 && < 5,
525526 bytestring,