Skip to content

Commit 3214a17

Browse files
authored
Convert the test to a test-suite. (#110)
This works with `stack` and `cabal new-test`. The latter uses the `build-tool-depends` field to locate the binary. Also: - Remove the reference to the nonexistent main file on Windows. - Make the test binary return a nonzero exit code when it fails. Still TODO: test in CI.
1 parent 4e7e042 commit 3214a17

File tree

3 files changed

+25
-27
lines changed

3 files changed

+25
-27
lines changed

haskeline.cabal

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,17 @@ Library
112112

113113
ghc-options: -Wall
114114

115-
Executable haskeline-tests
115+
test-suite haskeline-tests
116+
type: exitcode-stdio-1.0
116117
hs-source-dirs: tests
117118
Default-Language: Haskell98
118119

119120
if os(windows)
120-
Main-is: NotExisting.hs
121121
buildable: False
122-
else
123-
Main-Is: Unit.hs
124-
Build-depends: base, containers, text, bytestring, HUnit, process, unix
125-
Other-Modules: RunTTY, Pty
122+
Main-Is: Unit.hs
123+
Build-depends: base, containers, text, bytestring, HUnit, process, unix
124+
Other-Modules: RunTTY, Pty
125+
build-tool-depends: haskeline:haskeline-examples-Test
126126

127127
-- The following program is used by unit tests in `tests` executable
128128
Executable haskeline-examples-Test

tests/RunTTY.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ module RunTTY (Invocation(..),
1111
setUTF8
1212
) where
1313

14-
import Data.ByteString as B
15-
import qualified Data.ByteString.Char8 as BC
16-
import System.Process
1714
import Control.Concurrent
15+
import Data.ByteString as B
1816
import System.IO
17+
import System.Process
1918
import Test.HUnit
19+
import qualified Data.ByteString.Char8 as BC
2020

2121
import Pty
2222

tests/Unit.hs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
{-# LANGUAGE OverloadedStrings #-}
2-
-- Usage:
3-
-- ghc ../examples/Test.hs
4-
-- ghc Unit.hs
5-
-- ./Unit ../examples/Test
62
-- Requirements:
73
-- - Empty ~/.haskeline (or set to defaults)
8-
-- - Assumes the dummy folder is in the current folder
9-
-- - On Mac OS X, may need to clear out /usr/lib/charset.alias
10-
-- (In particular, the line "* UTF-8" which makes locale_charset()
11-
-- always return UTF-8; otherwise we can't test latin-1.)
4+
-- - On Mac OS X, the "dumb term" test may fail.
5+
-- In particular, the line "* UTF-8" which makes locale_charset()
6+
-- always return UTF-8; otherwise we can't test latin-1.
127
-- - NB: Window size isn't provided by screen so it's picked up from
138
-- terminfo or defaults (either way: 80x24), rather than the user's
149
-- terminal.
1510
module Main where
1611

17-
import System.Environment
18-
import Test.HUnit
12+
import Control.Monad (when)
1913
import qualified Data.ByteString as B
2014
import qualified Data.ByteString.Char8 as BC
2115
import Data.Word
2216
import qualified Data.Text as T
2317
import qualified Data.Text.Encoding as E
2418
import Data.Monoid ((<>))
19+
import System.Exit (exitFailure)
20+
import System.Process (readProcess)
21+
import Test.HUnit
2522

2623
import RunTTY
2724

@@ -37,18 +34,19 @@ legacyEncoding = False
3734
whenLegacy :: BC.ByteString -> BC.ByteString
3835
whenLegacy s = if legacyEncoding then s else B.empty
3936

40-
main :: IO Counts
37+
main :: IO ()
4138
main = do
42-
[p] <- getArgs
39+
-- forkProcess needs an absolute path to the binary.
40+
p <- head . lines <$> readProcess "which" ["haskeline-examples-Test"] ""
4341
let i = setTerm "xterm"
4442
Invocation {
4543
prog = p,
4644
progArgs = [],
4745
runInTTY = True,
4846
environment = []
4947
}
50-
runTestTT $ test [interactionTests i, fileStyleTests i]
51-
48+
result <- runTestTT $ test [interactionTests i, fileStyleTests i]
49+
when (errors result > 0 || failures result > 0) exitFailure
5250

5351
interactionTests :: Invocation -> Test
5452
interactionTests i = "interaction" ~: test
@@ -113,10 +111,10 @@ unicodeMovement i = "Unicode movement" ~:
113111

114112
tabCompletion :: Invocation -> Test
115113
tabCompletion i = "tab completion" ~:
116-
[ utf8Test i [ utf8 "dummy-μ\t\t" ]
117-
[ prompt 0, utf8 "dummy-μασ/"
118-
<> nl <> utf8 "bar ςερτ" <> nl
119-
<> prompt' 0 <> utf8 "dummy-μασ/"
114+
[ utf8Test i [ utf8 "tests/dummy-μ\t\t" ]
115+
[ prompt 0, utf8 "tests/dummy-μασ/"
116+
<> nl <> utf8 "ςερτ bar" <> nl
117+
<> prompt' 0 <> utf8 "tests/dummy-μασ/"
120118
]
121119
]
122120

0 commit comments

Comments
 (0)