From 72b8817f3266b255ffc7a7b22396576bc0af22dc Mon Sep 17 00:00:00 2001 From: Lennart Spitzner Date: Tue, 23 May 2017 00:01:50 +0200 Subject: [PATCH] Add testsuite for the library interface --- brittany.cabal | 37 +++++++++++++++++++++++++++++++++++ src-libinterfacetests/Main.hs | 32 ++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 src-libinterfacetests/Main.hs diff --git a/brittany.cabal b/brittany.cabal index 6c9f52b..f9fdd3e 100644 --- a/brittany.cabal +++ b/brittany.cabal @@ -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" + } diff --git a/src-libinterfacetests/Main.hs b/src-libinterfacetests/Main.hs new file mode 100644 index 0000000..457a689 --- /dev/null +++ b/src-libinterfacetests/Main.hs @@ -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 +