on master help sign in
start converting verify-using-mock-input to test-framework + smallcheck
560c5d6Corey O'Connor
test/VerifyUsingMockInput.hs+32−19
@@ -2,8 +2,7 @@
2 - This assumes appropriate definitions exist in the current environment for the terminals of
2 - This assumes appropriate definitions exist in the current environment for the terminals of
3 - interest.
3 - interest.
4 -}
4 -}
5−module VerifyUsingMockInput where
5+module Main where
6−import Verify hiding (classify)
7
6
8import Verify.Graphics.Vty.Terminal
7import Verify.Graphics.Vty.Terminal
9
8
@@ -12,6 +11,7 @@ import Graphics.Vty.Input
12import Graphics.Vty.Input.Data
11import Graphics.Vty.Input.Data
13import Graphics.Vty.Input.Internal
12import Graphics.Vty.Input.Internal
14
13
14+import Control.Applicative
15import Control.Concurrent
15import Control.Concurrent
16import Control.Exception
16import Control.Exception
17import Control.Monad
17import Control.Monad
@@ -19,8 +19,9 @@ import Control.Monad
19import System.Posix.Env
19import System.Posix.Env
20import System.IO
20import System.IO
21
21
22−import Test.QuickCheck.Assertions
22+import Test.Framework.Providers.SmallCheck
23−import Test.QuickCheck.Property ( morallyDubiousIOProperty )
23+import Test.Framework
24+import Test.SmallCheck
24
25
25-- processing a block of 16 chars is the largest I can do without taking too long to run the test.
26-- processing a block of 16 chars is the largest I can do without taking too long to run the test.
26max_bytes_size = 16
27max_bytes_size = 16
@@ -39,10 +40,7 @@ exec_input_spec input out_handle = forM_ input f
39 f (Bytes str) = hPutStr out_handle str >> hFlush out_handle
40 f (Bytes str) = hPutStr out_handle str >> hFlush out_handle
40 f (Delay t) = threadDelay (t*1000)
41 f (Delay t) = threadDelay (t*1000)
41
42
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
46assert_events_from_input_block table input_spec expected_events = do
44assert_events_from_input_block table input_spec expected_events = do
47 let classifier = classify table
45 let classifier = classify table
48 input <- newChan
46 input <- newChan
@@ -56,7 +54,7 @@ assert_events_from_input_block table input_spec expected_events = do
56 let collect_events = handle (\(e :: BlockedIndefinitelyOnMVar) -> return [])
54 let collect_events = handle (\(e :: BlockedIndefinitelyOnMVar) -> return [])
57 ((:) <$> readChan output <*> collect_events)
55 ((:) <$> readChan output <*> collect_events)
58 out_events <- collect_events
56 out_events <- collect_events
59− return $ out_events ?== expected_events
57+ return $ out_events == expected_events
60
58
61write_input_spec_to_chan :: Chan Char -> InputSpec -> IO ()
59write_input_spec_to_chan :: Chan Char -> InputSpec -> IO ()
62write_input_spec_to_chan chan [] = writeChan chan '\xFFFD'
60write_input_spec_to_chan chan [] = writeChan chan '\xFFFD'
@@ -65,7 +63,26 @@ write_input_spec_to_chan chan (Bytes str : input_spec')
65write_input_spec_to_chan chan (Delay t : input_spec')
63write_input_spec_to_chan chan (Delay t : input_spec')
66 = writeChan chan '\xFFFE' >> write_input_spec_to_chan chan input_spec'
64 = writeChan chan '\xFFFE' >> write_input_spec_to_chan chan input_spec'
67
65
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
68−verify_simple_input_block_to_event :: Property
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)
69verify_simple_input_block_to_event = do
86verify_simple_input_block_to_event = do
70 -- Ouch! 16 is as high as this can go without taking far too long. :-\
87 -- Ouch! 16 is as high as this can go without taking far too long. :-\
71 Positive block_length <- resize 16 $ arbitrary
88 Positive block_length <- resize 16 $ arbitrary
@@ -74,14 +91,10 @@ verify_simple_input_block_to_event = do
74 events = map (\(k,ms) -> EvKey k ms) $ map snd block_event_pairs
91 events = map (\(k,ms) -> EvKey k ms) $ map snd block_event_pairs
75 morallyDubiousIOProperty $ assert_events_from_input_block simple_chars input events
92 morallyDubiousIOProperty $ assert_events_from_input_block simple_chars input events
76
93
77−verify_keys_from_caps_table :: String -> Result
94+main = defaultMain
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"
95+ [ testProperty "basic block generated from a single ansi chars to event translation"
83− verify_simple_input_block_to_event
96+ verify_simple_input_block_to_event
84− , verify "keys from caps table are parsed to the same key"
85− verify_keys_from_caps_table
86 ]
97 ]
98+-}
99+main = defaultMain []
87
100
vty.cabal+6−5
@@ -506,20 +506,21 @@ test-suite verify-utf8-width
506
506
507test-suite verify-using-mock-input
507test-suite verify-using-mock-input
508 default-language: Haskell2010
508 default-language: Haskell2010
509− default-extensions: ScopedTypeVariables
509+ default-extensions: ScopedTypeVariables
510
510
511− type: detailed-0.9
511+ type: exitcode-stdio-1.0
512
512
513 hs-source-dirs: test
513 hs-source-dirs: test
514
514
515− test-module: VerifyUsingMockInput
515+ main-is: VerifyUsingMockInput.hs
516−
517− other-modules: Verify
518
516
519 build-depends: vty,
517 build-depends: vty,
520 Cabal == 1.18.*,
518 Cabal == 1.18.*,
521 QuickCheck >= 2.4,
519 QuickCheck >= 2.4,
520+ smallcheck == 1.*,
522 quickcheck-assertions >= 0.1.1,
521 quickcheck-assertions >= 0.1.1,
522+ test-framework == 0.8.*,
523+ test-framework-smallcheck == 0.2.*,
523 random == 1.0.*,
524 random == 1.0.*,
524 base >= 4 && < 5,
525 base >= 4 && < 5,
525 bytestring,
526 bytestring,