From e5412b8cfd3f96eb5e84909dfdd8f53e161b37df Mon Sep 17 00:00:00 2001 From: waddlaw Date: Sat, 18 Jan 2020 12:45:40 +0900 Subject: [PATCH] Add integration test --- haskell-stack-trace-plugin.cabal | 22 ++++++++++++++++++++++ test/Spec.hs | 1 + test/StackTrace/PluginSpec.hs | 21 +++++++++++++++++++++ test/resource/ghc86.output | 13 +++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 test/Spec.hs create mode 100644 test/StackTrace/PluginSpec.hs create mode 100644 test/resource/ghc86.output diff --git a/haskell-stack-trace-plugin.cabal b/haskell-stack-trace-plugin.cabal index da19e03..aa3760d 100644 --- a/haskell-stack-trace-plugin.cabal +++ b/haskell-stack-trace-plugin.cabal @@ -44,6 +44,28 @@ library ghc-options: -O2 -Wall default-language: Haskell2010 +test-suite test + main-is: Spec.hs + hs-source-dirs: test + type: exitcode-stdio-1.0 + build-depends: + base >=4.12 && <4.13, + bytestring >= 0.10.8 && <0.11, + hspec >= 2.7 && <2.8, + typed-process >= 0.2.6 && <0.2.9 + + build-tool-depends: + hspec-discover:hspec-discover >= 2.7 && <2.8 + + other-modules: StackTrace.PluginSpec + + if flag(dev) + ghc-options: -Wall -Werror + else + ghc-options: -O2 -Wall + + default-language: Haskell2010 + executable example main-is: Main.hs hs-source-dirs: example diff --git a/test/Spec.hs b/test/Spec.hs new file mode 100644 index 0000000..52ef578 --- /dev/null +++ b/test/Spec.hs @@ -0,0 +1 @@ +{-# OPTIONS_GHC -F -pgmF hspec-discover #-} \ No newline at end of file diff --git a/test/StackTrace/PluginSpec.hs b/test/StackTrace/PluginSpec.hs new file mode 100644 index 0000000..e2a4352 --- /dev/null +++ b/test/StackTrace/PluginSpec.hs @@ -0,0 +1,21 @@ +{-# LANGUAGE OverloadedStrings #-} +module StackTrace.PluginSpec (spec) where + +import Data.ByteString.Lazy (ByteString) +import qualified Data.ByteString.Lazy as BL +import Test.Hspec +import System.Process.Typed + +spec :: Spec +spec = do + output <- runIO exe + expected <- runIO $ BL.readFile "test/resource/ghc86.output" + it "integration test" $ output `shouldBe` expected + + +exe :: IO ByteString +exe = do + runProcess_ $ shell "cabal install exe:example --installdir=./dist" + err <- readProcessStderr_ $ shell "./dist/example || true" + runProcess_ $ shell "rm -rf ./dist" + return err \ No newline at end of file diff --git a/test/resource/ghc86.output b/test/resource/ghc86.output new file mode 100644 index 0000000..8d58505 --- /dev/null +++ b/test/resource/ghc86.output @@ -0,0 +1,13 @@ +example: fError +CallStack (from HasCallStack): + error, called at example/Main.hs:41:10 in main:Main + fError, called at example/Main.hs:37:11 in main:Main + f8, called at example/Main.hs:33:16 in main:Main + f7, called at example/Main.hs:29:11 in main:Main + f6, called at example/Main.hs:25:15 in main:Main + f5, called at example/Main.hs:21:8 in main:Main + f4, called at example/Main.hs:17:6 in main:Main + f3, called at example/Main.hs:13:6 in main:Main + f2, called at example/Main.hs:10:6 in main:Main + f1, called at example/Main.hs:7:14 in main:Main + main, called at example/Main.hs:7:1 in main:Main