Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration test to showcase failure with detailed-0.9 test type #4498

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 14 additions & 11 deletions src/Stack/Build/Execute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
74 changes: 74 additions & 0 deletions subs/http-download/http-download.cabal
Original file line number Diff line number Diff line change
@@ -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
48 changes: 48 additions & 0 deletions subs/rio-prettyprint/rio-prettyprint.cabal
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions test/integration/tests/4453-detailed/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import StackTest
import System.Directory

main :: IO ()
main = do
removeDirIgnore ".stack-work"
stack [defaultResolverArg, "test"]
6 changes: 6 additions & 0 deletions test/integration/tests/4453-detailed/files/src/Lib.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Lib
( someFunc
) where

someFunc :: IO ()
someFunc = putStrLn "someFunc"
3 changes: 3 additions & 0 deletions test/integration/tests/4453-detailed/files/stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resolver: lts-11.22
packages:
- '.'
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions test/integration/tests/4453-detailed/files/test/Spec.hs
Original file line number Diff line number Diff line change
@@ -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
}