-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #71
- Loading branch information
1 parent
6dd8cb6
commit b793f25
Showing
9 changed files
with
110 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module ProjectsSpec where | ||
|
||
import qualified Test.Hspec | ||
import Test.Hspec hiding (it) | ||
import Test.HUnit | ||
|
||
import Data.List (isInfixOf) | ||
import Data.Maybe | ||
import System.Environment | ||
import System.Exit | ||
import System.FilePath | ||
import System.IO.Unsafe | ||
import System.Process | ||
import Text.Printf | ||
|
||
main :: IO () | ||
main = hspec spec | ||
|
||
type LibName = String | ||
type NumberOfTestsExpected = Word | ||
|
||
-- | Run 'cabal run doctests' in a project in projects/, expect a number of | ||
-- succeeded tests. | ||
runProject :: LibName -> NumberOfTestsExpected -> Assertion | ||
runProject libName nTests = do | ||
(exitCode, _stdout, stderr) <- readCreateProcessWithExitCode process "" | ||
assertEqual ("'cabal run doctests' succeeded for " <> libName) exitCode ExitSuccess | ||
assertBool ("expected\n\n" <> expect <> "\n\nin\n\n" <> stderr) (expect `isInfixOf` stderr) | ||
where | ||
expect = printf "Examples: %d Tried: %d Errors: 0 Unexpected output: 0" nTests nTests | ||
process = (proc "cabal" ["run", "doctests"]) | ||
{ cwd = Just ("test" </> "projects" </> "cpp-options") | ||
} | ||
|
||
-- | 'it' or 'xit', depending on whether we run in a Nix/Stack context. Nix | ||
-- doesn't have Cabal available, so the tests will fail. This is mostly a | ||
-- workaround for CI. | ||
ignoreIfNixOrStack :: Example a => String -> a -> SpecWith (Arg a) | ||
ignoreIfNixOrStack = unsafePerformIO $ do | ||
stack <- fmap isJust (lookupEnv "STACK_EXE") | ||
nix <- fmap isJust (lookupEnv "NIX_BUILD_TOP") | ||
if stack || nix | ||
then pure Test.Hspec.xit | ||
else pure Test.Hspec.it | ||
|
||
|
||
spec :: Spec | ||
spec = do | ||
ignoreIfNixOrStack "cpp-projects" (runProject "cpp-options" 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
packages: | ||
. | ||
../../.. | ||
|
||
write-ghc-environment-files: always | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
cabal-version: 2.0 | ||
name: cpp-options | ||
version: 0.1.0.0 | ||
license: MIT | ||
author: Martijn Bastiaan | ||
maintainer: [email protected] | ||
build-type: Simple | ||
|
||
library | ||
exposed-modules: MyLib | ||
ghc-options: -Wall | ||
cpp-options: -DADD=add | ||
build-depends: base | ||
hs-source-dirs: src | ||
default-language: Haskell2010 | ||
|
||
test-suite doctests | ||
type: exitcode-stdio-1.0 | ||
hs-source-dirs: test | ||
main-is: doctests.hs | ||
ghc-options: -threaded | ||
build-depends: base, cpp-options, doctest-parallel >= 0.1 | ||
default-language: Haskell2010 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{-# LANGUAGE CPP #-} | ||
|
||
module MyLib (add, main) where | ||
|
||
-- | Adds two 'Int's | ||
-- | ||
-- >>> ADD 3 5 | ||
-- 8 | ||
add :: Int -> Int -> Int | ||
add = (+) | ||
|
||
main :: IO () | ||
main = print (ADD 3 5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Main where | ||
|
||
import Test.DocTest (mainFromCabal) | ||
import System.Environment (getArgs) | ||
|
||
main :: IO () | ||
main = mainFromCabal "cpp-options" =<< getArgs |