From 1994bd3816214f672b29539032e2f0a45748837c Mon Sep 17 00:00:00 2001 From: Tom Sydney Kerckhove Date: Wed, 9 Jan 2019 11:55:46 +0100 Subject: [PATCH 1/2] Integration test for the bug from issue 4453 --- test/integration/tests/4453-detailed/Main.hs | 7 +++++ .../tests/4453-detailed/files/.gitignore | 4 +++ .../tests/4453-detailed/files/LICENSE | 30 +++++++++++++++++++ .../tests/4453-detailed/files/src/Lib.hs | 6 ++++ .../tests/4453-detailed/files/stack.yaml | 3 ++ .../files/test-detailed-example.cabal | 18 +++++++++++ .../tests/4453-detailed/files/test/Spec.hs | 21 +++++++++++++ 7 files changed, 89 insertions(+) create mode 100644 test/integration/tests/4453-detailed/Main.hs create mode 100644 test/integration/tests/4453-detailed/files/.gitignore create mode 100644 test/integration/tests/4453-detailed/files/LICENSE create mode 100644 test/integration/tests/4453-detailed/files/src/Lib.hs create mode 100644 test/integration/tests/4453-detailed/files/stack.yaml create mode 100644 test/integration/tests/4453-detailed/files/test-detailed-example.cabal create mode 100644 test/integration/tests/4453-detailed/files/test/Spec.hs diff --git a/test/integration/tests/4453-detailed/Main.hs b/test/integration/tests/4453-detailed/Main.hs new file mode 100644 index 0000000000..b5b349a66c --- /dev/null +++ b/test/integration/tests/4453-detailed/Main.hs @@ -0,0 +1,7 @@ +import StackTest +import System.Directory + +main :: IO () +main = do + removeDirIgnore ".stack-work" + stack ["test"] diff --git a/test/integration/tests/4453-detailed/files/.gitignore b/test/integration/tests/4453-detailed/files/.gitignore new file mode 100644 index 0000000000..3d5d78b060 --- /dev/null +++ b/test/integration/tests/4453-detailed/files/.gitignore @@ -0,0 +1,4 @@ +.cabal-sandbox/ +cabal.sandbox.config +.stack-work/ +dist/ diff --git a/test/integration/tests/4453-detailed/files/LICENSE b/test/integration/tests/4453-detailed/files/LICENSE new file mode 100644 index 0000000000..8cb4fd7d1b --- /dev/null +++ b/test/integration/tests/4453-detailed/files/LICENSE @@ -0,0 +1,30 @@ +Copyright Axel Mannhardt (c) 2015 + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of Author name here nor the names of other + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/test/integration/tests/4453-detailed/files/src/Lib.hs b/test/integration/tests/4453-detailed/files/src/Lib.hs new file mode 100644 index 0000000000..d36ff2714d --- /dev/null +++ b/test/integration/tests/4453-detailed/files/src/Lib.hs @@ -0,0 +1,6 @@ +module Lib + ( someFunc + ) where + +someFunc :: IO () +someFunc = putStrLn "someFunc" diff --git a/test/integration/tests/4453-detailed/files/stack.yaml b/test/integration/tests/4453-detailed/files/stack.yaml new file mode 100644 index 0000000000..9651d88a3f --- /dev/null +++ b/test/integration/tests/4453-detailed/files/stack.yaml @@ -0,0 +1,3 @@ +resolver: lts-11.22 +packages: +- '.' diff --git a/test/integration/tests/4453-detailed/files/test-detailed-example.cabal b/test/integration/tests/4453-detailed/files/test-detailed-example.cabal new file mode 100644 index 0000000000..87a973ce4d --- /dev/null +++ b/test/integration/tests/4453-detailed/files/test-detailed-example.cabal @@ -0,0 +1,18 @@ +name: test-detailed-example +version: 0.1.0.0 +build-type: Simple +cabal-version: >=1.20 + +library + hs-source-dirs: src + exposed-modules: Lib + build-depends: base >= 4.7 && < 5 + default-language: Haskell2010 + +test-suite test-detailed-example-test + type: detailed-0.9 + hs-source-dirs: test + test-module: Spec + build-depends: base >= 4.7, + Cabal >= 1.20 + default-language: Haskell2010 diff --git a/test/integration/tests/4453-detailed/files/test/Spec.hs b/test/integration/tests/4453-detailed/files/test/Spec.hs new file mode 100644 index 0000000000..78acaf4517 --- /dev/null +++ b/test/integration/tests/4453-detailed/files/test/Spec.hs @@ -0,0 +1,21 @@ +module Spec (tests) where + +import Distribution.TestSuite + +tests :: IO [Test] +tests = do + return [ + test "foo" Pass + , test "bar" (Fail "It did not work out!") + ] + +test :: String -> Result -> Test +test name r = Test t + where + t = TestInstance { + run = return (Finished r) + , name = name + , tags = [] + , options = [] + , setOption = \_ _ -> Right t + } From ddd099d77e09e05f96da9c5974ac458f3e18e06d Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Mon, 7 Jan 2019 18:02:42 +0200 Subject: [PATCH 2/2] Detailed test support (fixes #4453) --- ChangeLog.md | 2 + src/Stack/Build/Execute.hs | 25 ++++--- subs/http-download/http-download.cabal | 74 +++++++++++++++++++ subs/rio-prettyprint/rio-prettyprint.cabal | 48 ++++++++++++ test/integration/tests/4453-detailed/Main.hs | 2 +- .../tests/4453-detailed/files/.gitignore | 4 - .../tests/4453-detailed/files/LICENSE | 30 -------- 7 files changed, 139 insertions(+), 46 deletions(-) create mode 100644 subs/http-download/http-download.cabal create mode 100644 subs/rio-prettyprint/rio-prettyprint.cabal delete mode 100644 test/integration/tests/4453-detailed/files/.gitignore delete mode 100644 test/integration/tests/4453-detailed/files/LICENSE diff --git a/ChangeLog.md b/ChangeLog.md index 6138507b8b..22acc59333 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -118,6 +118,8 @@ Bug fixes: inside docker on Mac. See [#4506](https://github.com/commercialhaskell/stack/issues/4506) * Using `--ghc-options` with `stack script --compile` now works. +* Ensure the detailed-0.9 type tests work. + See [#4453](https://github.com/commercialhaskell/stack/issues/4453). ## v1.9.3 diff --git a/src/Stack/Build/Execute.hs b/src/Stack/Build/Execute.hs index 7d84c3f39b..c342df45f1 100644 --- a/src/Stack/Build/Execute.hs +++ b/src/Stack/Build/Execute.hs @@ -28,6 +28,7 @@ import Crypto.Hash import Data.Attoparsec.Text hiding (try) import qualified Data.ByteArray as Mem (convert) import qualified Data.ByteString as S +import qualified Data.ByteString.Lazy as BL import qualified Data.ByteString.Base64.URL as B64URL import Data.Char (isSpace) import Conduit @@ -36,9 +37,8 @@ import qualified Data.Conduit.Filesystem as CF import qualified Data.Conduit.List as CL import Data.Conduit.Process.Typed (ExitCodeException (..), waitExitCode, - useHandleOpen, setStdin, setStdout, setStderr, getStdin, - createPipe, runProcess_, getStdout, - getStderr, createSource) + useHandleOpen, setStdin, setStdout, setStderr, + runProcess_, getStdout, getStderr, createSource) import qualified Data.Conduit.Text as CT import Data.List hiding (any) import qualified Data.Map.Strict as M @@ -84,7 +84,7 @@ import qualified System.Directory as D import System.Environment (getExecutablePath) import System.Exit (ExitCode (..)) import qualified System.FilePath as FP -import System.IO (hPutStr, stderr, stdout) +import System.IO (stderr, stdout) import System.PosixCompat.Files (createLink, modificationTime, getFileStatus) import System.PosixCompat.Time (epochTime) import RIO.PrettyPrint @@ -1805,16 +1805,19 @@ singleTest topts testsToRun ac ee task installedMap = do ec <- withWorkingDir (toFilePath pkgDir) $ proc (toFilePath exePath) args $ \pc0 -> do - let pc = setStdin createPipe + stdinBS <- + if isTestTypeLib + then do + logPath <- buildLogPath package (Just stestName) + ensureDir (parent logPath) + pure $ BL.fromStrict + $ encodeUtf8 $ fromString $ show (logPath, testName) + else pure mempty + let pc = setStdin (byteStringInput stdinBS) $ output setStdout $ output setStderr pc0 - withProcess pc $ \p -> do - when isTestTypeLib $ do - logPath <- buildLogPath package (Just stestName) - ensureDir (parent logPath) - liftIO $ hPutStr (getStdin p) $ show (logPath, testName) - waitExitCode p + runProcess pc -- Add a trailing newline, incase the test -- output didn't finish with a newline. case outputType of diff --git a/subs/http-download/http-download.cabal b/subs/http-download/http-download.cabal new file mode 100644 index 0000000000..8a893ab258 --- /dev/null +++ b/subs/http-download/http-download.cabal @@ -0,0 +1,74 @@ +cabal-version: 1.12 + +-- This file has been generated from package.yaml by hpack version 0.31.1. +-- +-- see: https://github.com/sol/hpack +-- +-- hash: 6a3d670e6f645b1ae099ce4d47325765448bfe194c0f497059a5fe3524388288 + +name: http-download +version: 0.1.0.0 +synopsis: Verified downloads with retries +category: Development +homepage: https://github.com/commercialhaskell/http-download#readme +bug-reports: https://github.com/commercialhaskell/http-download/issues +author: Michael Snoyman +maintainer: michael@snoyman.com +copyright: 2018-2019 FP Complete +license: MIT +build-type: Simple + +source-repository head + type: git + location: https://github.com/commercialhaskell/http-download + +library + exposed-modules: + Network.HTTP.Download + Network.HTTP.Download.Verified + other-modules: + Paths_http_download + hs-source-dirs: + src/ + build-depends: + base + , base64-bytestring + , bytestring + , conduit + , conduit-extra + , cryptonite + , cryptonite-conduit + , directory + , exceptions + , filepath + , http-client + , http-conduit + , http-types + , memory + , path + , path-io + , retry + , rio + , rio-prettyprint + default-language: Haskell2010 + +test-suite spec + type: exitcode-stdio-1.0 + main-is: Spec.hs + other-modules: + Network.HTTP.Download.VerifiedSpec + Paths_http_download + hs-source-dirs: + test + build-depends: + base + , cryptonite + , hspec + , http-client + , http-download + , path + , path-io + , retry + , rio + , rio-prettyprint + default-language: Haskell2010 diff --git a/subs/rio-prettyprint/rio-prettyprint.cabal b/subs/rio-prettyprint/rio-prettyprint.cabal new file mode 100644 index 0000000000..da3b19d3ac --- /dev/null +++ b/subs/rio-prettyprint/rio-prettyprint.cabal @@ -0,0 +1,48 @@ +cabal-version: 1.12 + +-- This file has been generated from package.yaml by hpack version 0.31.1. +-- +-- see: https://github.com/sol/hpack +-- +-- hash: 4695b863639ee3242a4625aad63f566d63d6a52a61d08e2792516e6219a12f45 + +name: rio-prettyprint +version: 0.1.0.0 +synopsis: Pretty-printing for RIO +category: Development +homepage: https://github.com/commercialhaskell/rio-prettyprint#readme +bug-reports: https://github.com/commercialhaskell/rio-prettyprint/issues +author: Michael Snoyman +maintainer: michael@snoyman.com +copyright: 2018-2019 FP Complete +license: MIT +build-type: Simple + +source-repository head + type: git + location: https://github.com/commercialhaskell/rio-prettyprint + +library + exposed-modules: + RIO.PrettyPrint + RIO.PrettyPrint.DefaultStyles + RIO.PrettyPrint.StylesUpdate + RIO.PrettyPrint.Types + Text.PrettyPrint.Leijen.Extended + other-modules: + Paths_rio_prettyprint + hs-source-dirs: + src/ + build-depends: + Cabal + , aeson + , annotated-wl-pprint + , ansi-terminal + , array + , base + , colour + , mtl + , path + , rio + , text + default-language: Haskell2010 diff --git a/test/integration/tests/4453-detailed/Main.hs b/test/integration/tests/4453-detailed/Main.hs index b5b349a66c..8f13e72bcd 100644 --- a/test/integration/tests/4453-detailed/Main.hs +++ b/test/integration/tests/4453-detailed/Main.hs @@ -4,4 +4,4 @@ import System.Directory main :: IO () main = do removeDirIgnore ".stack-work" - stack ["test"] + stack [defaultResolverArg, "test"] diff --git a/test/integration/tests/4453-detailed/files/.gitignore b/test/integration/tests/4453-detailed/files/.gitignore deleted file mode 100644 index 3d5d78b060..0000000000 --- a/test/integration/tests/4453-detailed/files/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -.cabal-sandbox/ -cabal.sandbox.config -.stack-work/ -dist/ diff --git a/test/integration/tests/4453-detailed/files/LICENSE b/test/integration/tests/4453-detailed/files/LICENSE deleted file mode 100644 index 8cb4fd7d1b..0000000000 --- a/test/integration/tests/4453-detailed/files/LICENSE +++ /dev/null @@ -1,30 +0,0 @@ -Copyright Axel Mannhardt (c) 2015 - -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials provided - with the distribution. - - * Neither the name of Author name here nor the names of other - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.