Add testsuite for the library interface

pull/35/head
Lennart Spitzner 2017-05-23 00:01:50 +02:00
parent 1adf02dabe
commit 72b8817f32
2 changed files with 69 additions and 0 deletions

View File

@ -359,3 +359,40 @@ test-suite littests
if flag(brittany-dev) {
ghc-options: -O0 -Werror -fobject-code
}
test-suite libinterfacetests
if flag(brittany-dev-lib) {
buildable: False
} else {
buildable: True
}
type: exitcode-stdio-1.0
default-language: Haskell2010
build-depends:
{ brittany
, base
, text
, transformers
, hspec >=2.4.1 && <2.5
}
ghc-options: -Wall
main-is: Main.hs
other-modules:
hs-source-dirs: src-libinterfacetests
default-extensions: {
FlexibleContexts
FlexibleInstances
ScopedTypeVariables
MonadComprehensions
LambdaCase
MultiWayIf
KindSignatures
}
ghc-options: {
-Wall
-j
-fno-warn-unused-imports
-fno-warn-orphans
-rtsopts
-with-rtsopts "-M2G"
}

View File

@ -0,0 +1,32 @@
module Main where
import Test.Hspec
import Language.Haskell.Brittany
import qualified Data.Text as Text
import qualified System.Exit as Exit
import Control.Monad.IO.Class
main :: IO ()
main = hspec $ do
describe "library interface basic functionality" $ do
it "gives properly formatted result for valid input" $ do
let
input = Text.pack $ unlines
["func = [00000000000000000000000, 00000000000000000000000, 00000000000000000000000, 00000000000000000000000]"]
let expected = Text.pack $ unlines
[ "func ="
, " [ 00000000000000000000000"
, " , 00000000000000000000000"
, " , 00000000000000000000000"
, " , 00000000000000000000000"
, " ]"
]
output <- liftIO $ pureModuleTransform mempty input
input `shouldSatisfy` \_ -> case output of
Right x | x == expected -> True
_ -> False