on master help sign in
assure VerifyTerminal can actually work as a regression test for issue #42
838dd51Corey O'Connor
test/VerifyImageOps.hs+15
@@ -7,6 +7,8 @@ import Verify.Graphics.Vty.Image
7
7
8import Verify
8import Verify
9
9
10+import Control.DeepSeq
11+
10two_sw_horiz_concat :: SingleColumnChar -> SingleColumnChar -> Bool
12two_sw_horiz_concat :: SingleColumnChar -> SingleColumnChar -> Bool
11two_sw_horiz_concat (SingleColumnChar c1) (SingleColumnChar c2) =
13two_sw_horiz_concat (SingleColumnChar c1) (SingleColumnChar c2) =
12 image_width (char def_attr c1 <|> char def_attr c2) == 2
14 image_width (char def_attr c1 <|> char def_attr c2) == 2
@@ -135,6 +137,16 @@ crop_bottom_limits_height :: Image -> Int -> Property
135crop_bottom_limits_height i v = v >= 0 ==>
137crop_bottom_limits_height i v = v >= 0 ==>
136 v >= image_height (crop_bottom v i)
138 v >= image_height (crop_bottom v i)
137
139
140+-- rediculous tests just to satisfy my desire for nice code coverage :-P
141+can_show_image :: Image -> Bool
142+can_show_image i = length (show i) > 0
143+
144+can_rnf_image :: Image -> Bool
145+can_rnf_image i = rnf i == ()
146+
147+can_pp_image :: Image -> Bool
148+can_pp_image i = length (pp_image_structure i) > 0
149+
138tests :: IO [Test]
150tests :: IO [Test]
139tests = return
151tests = return
140 [ verify "two_sw_horiz_concat" two_sw_horiz_concat
152 [ verify "two_sw_horiz_concat" two_sw_horiz_concat
@@ -156,5 +168,8 @@ tests = return
156 , verify "crop right limits width" crop_right_limits_width
168 , verify "crop right limits width" crop_right_limits_width
157 , verify "crop top limits height" crop_top_limits_height
169 , verify "crop top limits height" crop_top_limits_height
158 , verify "crop bottom limits height" crop_bottom_limits_height
170 , verify "crop bottom limits height" crop_bottom_limits_height
171+ , verify "can show image" can_show_image
172+ , verify "can rnf image" can_rnf_image
173+ , verify "can pp image" can_pp_image
159 ]
174 ]
160
175
test/VerifyTerminal.hs+51−102
@@ -1,115 +1,64 @@
1{-# LANGUAGE ScopedTypeVariables #-}
1{-# LANGUAGE ScopedTypeVariables #-}
2+{- We setup the environment to envoke certain terminals of interest.
3+ - This assumes appropriate definitions exist in the current environment for the terminals of
4+ - interest.
5+ -}
2module VerifyTerminal where
6module VerifyTerminal where
3−
4−import Verify.Graphics.Vty.DisplayRegion
5−import Verify.Graphics.Vty.Picture
6−import Verify.Graphics.Vty.Image
7−import Verify.Graphics.Vty.Span
8−import Graphics.Vty.Terminal
9−import Graphics.Vty.Terminal.Mock
10−
11−import Graphics.Vty.Debug
12−
13import Verify
7import Verify
14
8
15−import qualified Data.ByteString as BS
9+import Graphics.Vty
16−import Data.IORef
17−import qualified Data.String.UTF8 as UTF8
18
10
19−import System.IO
11+import Verify.Graphics.Vty.Image
12+import Verify.Graphics.Vty.Terminal
20
13
21−compare_bytes out_bytes expected_bytes =
14+import Control.Monad
22− if out_bytes /= expected_bytes
23− then return $ failed { reason = "bytes\n" ++ show out_bytes
24− ++ "\nare not the expected bytes\n"
25− ++ show expected_bytes
26− }
27− else return succeeded
28
15
29−unit_image_unit_bounds :: UnitImage -> Property
16+import qualified System.Console.Terminfo as Terminfo
30−unit_image_unit_bounds (UnitImage _ i) = liftIOResult $ do
17+import System.Posix.Env
31− (_,t) <- mock_terminal (DisplayRegion 1 1)
18+import System.IO
32− dc <- display_bounds t >>= display_context t
33− let pic = pic_for_image i
34− output_picture dc pic
35− return succeeded
36
19
37−unit_image_arb_bounds :: UnitImage -> MockWindow -> Property
20+tests :: IO [Test]
38−unit_image_arb_bounds (UnitImage _ i) (MockWindow w h) = liftIOResult $ do
21+tests = concat <$> forM terminals_of_interest (\term_name -> do
39− (_,t) <- mock_terminal (DisplayRegion w h)
22+ -- check if that terminfo exists
40− dc <- display_bounds t >>= display_context t
23+ putStrLn $ "testing end to end for terminal: " ++ term_name
41− let pic = pic_for_image i
24+ mti <- try $ Terminfo.setupTerm term_name
42− output_picture dc pic
25+ case mti of
43− return succeeded
26+ Left (_ :: SomeException) -> return []
27+ Right _ -> return [ verify ("verify " ++ term_name ++ " could output a picture")
28+ (smoke_test_term_non_mac term_name)
29+ -- this is excessive.
30+ , verify ("verify " ++ term_name ++ " could output a picture on a Mac.")
31+ (smoke_test_term_mac term_name)
32+ ]
33+ )
44
34
45−single_T_row :: MockWindow -> Property
35+smoke_test_term_non_mac :: String -> Image -> Property
46−single_T_row (MockWindow w h) = liftIOResult $ do
36+smoke_test_term_non_mac term_name i = liftIOResult $ do
47− (mock_data,t) <- mock_terminal (DisplayRegion w h)
37+ -- unset the TERM_PROGRAM environment variable if set.
48− dc <- display_bounds t >>= display_context t
38+ -- Required to execute regression test for #42 on a mac
49− -- create an image that contains just the character T repeated for a single row
39+ unsetEnv "TERM_PROGRAM"
50− let i = horiz_cat $ replicate (fromEnum w) (char def_attr 'T')
40+ smoke_test_term term_name i
51− pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
52− output_picture dc pic
53− out_bytes <- readIORef mock_data >>= return . UTF8.toRep
54− -- The UTF8 string that represents the output bytes a single line containing the T string:
55− let expected = "HD" ++ "MA" ++ replicate (fromEnum w) 'T'
56− -- Followed by h - 1 lines of a change to the background attribute and then the background
57− -- character
58− ++ concat (replicate (fromEnum h - 1) $ "MA" ++ replicate (fromEnum w) 'B')
59− expected_bytes :: BS.ByteString = UTF8.toRep $ UTF8.fromString expected
60− compare_bytes out_bytes expected_bytes
61−
62−many_T_rows :: MockWindow -> Property
63−many_T_rows (MockWindow w h) = liftIOResult $ do
64− (mock_data, t) <- mock_terminal (DisplayRegion w h)
65− dc <- display_bounds t >>= display_context t
66− -- create an image that contains the character 'T' repeated for all the rows
67− let i = vert_cat $ replicate (fromEnum h) $ horiz_cat $ replicate (fromEnum w) (char def_attr 'T')
68− pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
69− output_picture dc pic
70− out_bytes <- readIORef mock_data >>= return . UTF8.toRep
71− -- The UTF8 string that represents the output bytes is h repeats of a move, 'M', followed by an
72− -- attribute change. 'A', followed by w 'T's
73− let expected = "HD" ++ concat (replicate (fromEnum h) $ "MA" ++ replicate (fromEnum w) 'T')
74− expected_bytes :: BS.ByteString = UTF8.toRep $ UTF8.fromString expected
75− compare_bytes out_bytes expected_bytes
76
41
77−many_T_rows_cropped_width :: MockWindow -> Property
42+smoke_test_term_mac :: String -> Image -> Property
78−many_T_rows_cropped_width (MockWindow w h) = liftIOResult $ do
43+smoke_test_term_mac term_name i = liftIOResult $ do
79− (mock_data,t) <- mock_terminal (DisplayRegion w h)
44+ setEnv "TERM_PROGRAM" "Apple_Terminal" True
80− dc <- display_bounds t >>= display_context t
45+ smoke_test_term term_name i
81− -- create an image that contains the character 'T' repeated for all the rows
82− let i = vert_cat $ replicate (fromEnum h) $ horiz_cat $ replicate (fromEnum w * 2) (char def_attr 'T')
83− pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
84− output_picture dc pic
85− out_bytes <- readIORef mock_data >>= return . UTF8.toRep
86− -- The UTF8 string that represents the output bytes is h repeats of a move, 'M', followed by an
87− -- attribute change. 'A', followed by w 'T's
88− let expected = "HD" ++ concat (replicate (fromEnum h) $ "MA" ++ replicate (fromEnum w) 'T')
89− expected_bytes :: BS.ByteString = UTF8.toRep $ UTF8.fromString expected
90− compare_bytes out_bytes expected_bytes
91
46
92−many_T_rows_cropped_height :: MockWindow -> Property
47+smoke_test_term :: String -> Image -> IO Result
93−many_T_rows_cropped_height (MockWindow w h) = liftIOResult $ do
48+smoke_test_term term_name i = do
94− (mock_data,t) <- mock_terminal (DisplayRegion w h)
49+ null_out <- openFile "/dev/null" WriteMode
50+ t <- terminal_with_name_and_io term_name null_out
51+ putStrLn $ "context color count: " ++ show (context_color_count t)
52+ reserve_display t
95− dc <- display_bounds t >>= display_context t
53+ dc <- display_context t (DisplayRegion 100 100)
96− -- create an image that contains the character 'T' repeated for all the rows
54+ -- always show the cursor to produce tests for terminals with no cursor support.
97− let i = vert_cat $ replicate (fromEnum h * 2) $ horiz_cat $ replicate (fromEnum w) (char def_attr 'T')
55+ let pic = (pic_for_image i) { pic_cursor = Cursor 0 0 }
98− pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
99 output_picture dc pic
56 output_picture dc pic
100− out_bytes <- readIORef mock_data >>= return . UTF8.toRep
57+ set_cursor_pos t 0 0
101− -- The UTF8 string that represents the output bytes is h repeats of a move, 'M', followed by an
58+ when (supports_cursor_visibility t) $ do
102− -- attribute change. 'A', followed by w count 'T's
59+ hide_cursor t
103− let expected = "HD" ++ concat (replicate (fromEnum h) $ "MA" ++ replicate (fromEnum w) 'T')
60+ show_cursor t
104− expected_bytes :: BS.ByteString = UTF8.toRep $ UTF8.fromString expected
61+ release_display t
105− compare_bytes out_bytes expected_bytes
62+ release_terminal t
106−
63+ return succeeded
107−tests :: IO [Test]
108−tests = return [ verify "unit_image_unit_bounds" unit_image_unit_bounds
109− , verify "unit_image_arb_bounds" unit_image_arb_bounds
110− , verify "single_T_row" single_T_row
111− , verify "many_T_rows" many_T_rows
112− , verify "many_T_rows_cropped_width" many_T_rows_cropped_width
113− , verify "many_T_rows_cropped_height" many_T_rows_cropped_height
114− ]
115
64
test/VerifyTerminfoBased.hsdeleted−43
@@ -1,43 +0,0 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
2−{- We setup the environment to envoke certain terminals of interest.
3− - This assumes appropriate definitions exist in the current environment for the terminals of
4− - interest.
5− -}
6−module VerifyTerminfoBased where
7−import Verify
8−
9−import Graphics.Vty
10−import Graphics.Vty.Terminal.TerminfoBased as TerminfoBased
11−
12−import Verify.Graphics.Vty.Image
13−import Verify.Graphics.Vty.Terminal
14−
15−import qualified System.Console.Terminfo as Terminfo
16−import System.IO
17−
18−tests :: IO [Test]
19−tests = concat <$> forM terminals_of_interest (\term_name -> do
20− -- check if that terminfo exists
21− putStrLn $ "testing end to end for terminal: " ++ term_name
22− mti <- try $ Terminfo.setupTerm term_name
23− case mti of
24− Left (_ :: SomeException) -> return []
25− Right _ -> return [ verify ("verify " ++ term_name ++ " could output a picture")
26− (smoke_test_term term_name)
27− ]
28− )
29−
30−smoke_test_term :: String -> Image -> Property
31−smoke_test_term term_name i = liftIOResult $ do
32− null_out <- openFile "/dev/null" WriteMode
33− t <- TerminfoBased.reserve_terminal term_name null_out
34− putStrLn $ "context color count: " ++ show (context_color_count t)
35− reserve_display t
36− dc <- display_context t (DisplayRegion 100 100)
37− -- always show the cursor to produce tests for terminals with no cursor support.
38− let pic = (pic_for_image i) { pic_cursor = Cursor 0 0 }
39− output_picture dc pic
40− release_display t
41− release_terminal t
42− return succeeded
43−
test/VerifyUsingMockTerminal.hsnew file+115
@@ -0,0 +1,115 @@
1+{-# LANGUAGE ScopedTypeVariables #-}
2+module VerifyUsingMockTerminal where
3+
4+import Verify.Graphics.Vty.DisplayRegion
5+import Verify.Graphics.Vty.Picture
6+import Verify.Graphics.Vty.Image
7+import Verify.Graphics.Vty.Span
8+import Graphics.Vty.Terminal
9+import Graphics.Vty.Terminal.Mock
10+
11+import Graphics.Vty.Debug
12+
13+import Verify
14+
15+import qualified Data.ByteString as BS
16+import Data.IORef
17+import qualified Data.String.UTF8 as UTF8
18+
19+import System.IO
20+
21+compare_bytes out_bytes expected_bytes =
22+ if out_bytes /= expected_bytes
23+ then return $ failed { reason = "bytes\n" ++ show out_bytes
24+ ++ "\nare not the expected bytes\n"
25+ ++ show expected_bytes
26+ }
27+ else return succeeded
28+
29+unit_image_unit_bounds :: UnitImage -> Property
30+unit_image_unit_bounds (UnitImage _ i) = liftIOResult $ do
31+ (_,t) <- mock_terminal (DisplayRegion 1 1)
32+ dc <- display_bounds t >>= display_context t
33+ let pic = pic_for_image i
34+ output_picture dc pic
35+ return succeeded
36+
37+unit_image_arb_bounds :: UnitImage -> MockWindow -> Property
38+unit_image_arb_bounds (UnitImage _ i) (MockWindow w h) = liftIOResult $ do
39+ (_,t) <- mock_terminal (DisplayRegion w h)
40+ dc <- display_bounds t >>= display_context t
41+ let pic = pic_for_image i
42+ output_picture dc pic
43+ return succeeded
44+
45+single_T_row :: MockWindow -> Property
46+single_T_row (MockWindow w h) = liftIOResult $ do
47+ (mock_data,t) <- mock_terminal (DisplayRegion w h)
48+ dc <- display_bounds t >>= display_context t
49+ -- create an image that contains just the character T repeated for a single row
50+ let i = horiz_cat $ replicate (fromEnum w) (char def_attr 'T')
51+ pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
52+ output_picture dc pic
53+ out_bytes <- readIORef mock_data >>= return . UTF8.toRep
54+ -- The UTF8 string that represents the output bytes a single line containing the T string:
55+ let expected = "HD" ++ "MA" ++ replicate (fromEnum w) 'T'
56+ -- Followed by h - 1 lines of a change to the background attribute and then the background
57+ -- character
58+ ++ concat (replicate (fromEnum h - 1) $ "MA" ++ replicate (fromEnum w) 'B')
59+ expected_bytes :: BS.ByteString = UTF8.toRep $ UTF8.fromString expected
60+ compare_bytes out_bytes expected_bytes
61+
62+many_T_rows :: MockWindow -> Property
63+many_T_rows (MockWindow w h) = liftIOResult $ do
64+ (mock_data, t) <- mock_terminal (DisplayRegion w h)
65+ dc <- display_bounds t >>= display_context t
66+ -- create an image that contains the character 'T' repeated for all the rows
67+ let i = vert_cat $ replicate (fromEnum h) $ horiz_cat $ replicate (fromEnum w) (char def_attr 'T')
68+ pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
69+ output_picture dc pic
70+ out_bytes <- readIORef mock_data >>= return . UTF8.toRep
71+ -- The UTF8 string that represents the output bytes is h repeats of a move, 'M', followed by an
72+ -- attribute change. 'A', followed by w 'T's
73+ let expected = "HD" ++ concat (replicate (fromEnum h) $ "MA" ++ replicate (fromEnum w) 'T')
74+ expected_bytes :: BS.ByteString = UTF8.toRep $ UTF8.fromString expected
75+ compare_bytes out_bytes expected_bytes
76+
77+many_T_rows_cropped_width :: MockWindow -> Property
78+many_T_rows_cropped_width (MockWindow w h) = liftIOResult $ do
79+ (mock_data,t) <- mock_terminal (DisplayRegion w h)
80+ dc <- display_bounds t >>= display_context t
81+ -- create an image that contains the character 'T' repeated for all the rows
82+ let i = vert_cat $ replicate (fromEnum h) $ horiz_cat $ replicate (fromEnum w * 2) (char def_attr 'T')
83+ pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
84+ output_picture dc pic
85+ out_bytes <- readIORef mock_data >>= return . UTF8.toRep
86+ -- The UTF8 string that represents the output bytes is h repeats of a move, 'M', followed by an
87+ -- attribute change. 'A', followed by w 'T's
88+ let expected = "HD" ++ concat (replicate (fromEnum h) $ "MA" ++ replicate (fromEnum w) 'T')
89+ expected_bytes :: BS.ByteString = UTF8.toRep $ UTF8.fromString expected
90+ compare_bytes out_bytes expected_bytes
91+
92+many_T_rows_cropped_height :: MockWindow -> Property
93+many_T_rows_cropped_height (MockWindow w h) = liftIOResult $ do
94+ (mock_data,t) <- mock_terminal (DisplayRegion w h)
95+ dc <- display_bounds t >>= display_context t
96+ -- create an image that contains the character 'T' repeated for all the rows
97+ let i = vert_cat $ replicate (fromEnum h * 2) $ horiz_cat $ replicate (fromEnum w) (char def_attr 'T')
98+ pic = (pic_for_image i) { pic_background = Background 'B' def_attr }
99+ output_picture dc pic
100+ out_bytes <- readIORef mock_data >>= return . UTF8.toRep
101+ -- The UTF8 string that represents the output bytes is h repeats of a move, 'M', followed by an
102+ -- attribute change. 'A', followed by w count 'T's
103+ let expected = "HD" ++ concat (replicate (fromEnum h) $ "MA" ++ replicate (fromEnum w) 'T')
104+ expected_bytes :: BS.ByteString = UTF8.toRep $ UTF8.fromString expected
105+ compare_bytes out_bytes expected_bytes
106+
107+tests :: IO [Test]
108+tests = return [ verify "unit_image_unit_bounds" unit_image_unit_bounds
109+ , verify "unit_image_arb_bounds" unit_image_arb_bounds
110+ , verify "single_T_row" single_T_row
111+ , verify "many_T_rows" many_T_rows
112+ , verify "many_T_rows_cropped_width" many_T_rows_cropped_width
113+ , verify "many_T_rows_cropped_height" many_T_rows_cropped_height
114+ ]
115+
vty.cabal+4−4
@@ -120,14 +120,14 @@ test-suite verify-attribute-ops
120 vector >= 0.7
120 vector >= 0.7
121
121
122
122
123−test-suite verify-terminal
123+test-suite verify-using-mock-terminal
124 default-language: Haskell2010
124 default-language: Haskell2010
125
125
126 type: detailed-0.9
126 type: detailed-0.9
127
127
128 hs-source-dirs: test
128 hs-source-dirs: test
129
129
130− test-module: VerifyTerminal
130+ test-module: VerifyUsingMockTerminal
131
131
132 other-modules: Verify
132 other-modules: Verify
133 Verify.Graphics.Vty.Attributes
133 Verify.Graphics.Vty.Attributes
@@ -155,14 +155,14 @@ test-suite verify-terminal
155 utf8-string >= 0.3 && < 0.4,
155 utf8-string >= 0.3 && < 0.4,
156 vector >= 0.7
156 vector >= 0.7
157
157
158−test-suite verify-terminfo-based
158+test-suite verify-terminal
159 default-language: Haskell2010
159 default-language: Haskell2010
160
160
161 type: detailed-0.9
161 type: detailed-0.9
162
162
163 hs-source-dirs: test
163 hs-source-dirs: test
164
164
165− test-module: VerifyTerminfoBased
165+ test-module: VerifyTerminal
166
166
167 other-modules: Verify
167 other-modules: Verify
168 Verify.Graphics.Vty.Attributes
168 Verify.Graphics.Vty.Attributes