From c88b23e119e78bc268097f6dc1c837562d443d16 Mon Sep 17 00:00:00 2001 From: Pranay Sashank Date: Thu, 4 Feb 2021 20:50:05 +0530 Subject: [PATCH] Add doctests test suite. --- .gitignore | 1 + Setup.hs | 4 ++-- doctests.hs | 14 ++++++++++++++ streamly.cabal | 28 +++++++++++++++++++++++++++- 4 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 doctests.hs diff --git a/.gitignore b/.gitignore index 7bea6233..a0b039ee 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ cabal.project.local # Other .log +_doctests/ diff --git a/Setup.hs b/Setup.hs index 54f57d6f..26210cdb 100644 --- a/Setup.hs +++ b/Setup.hs @@ -1,6 +1,6 @@ module Main (main) where -import Distribution.Simple +import Distribution.Extra.Doctest (defaultMainAutoconfWithDoctests) main :: IO () -main = defaultMainWithHooks autoconfUserHooks +main = defaultMainAutoconfWithDoctests "doctests" diff --git a/doctests.hs b/doctests.hs new file mode 100644 index 00000000..300898f6 --- /dev/null +++ b/doctests.hs @@ -0,0 +1,14 @@ +module Main where + +import Build_doctests (flags, pkgs, module_sources) +import Data.Foldable (traverse_) +import System.Environment.Compat (unsetEnv) +import Test.DocTest (doctest) + +main :: IO () +main = do + traverse_ putStrLn args + unsetEnv "GHC_ENVIRONMENT" + doctest args + where + args = flags ++ ["-outputdir=./_doctests/", "-fobject-code"] ++ pkgs ++ module_sources diff --git a/streamly.cabal b/streamly.cabal index 0ca26938..1f78601d 100644 --- a/streamly.cabal +++ b/streamly.cabal @@ -91,7 +91,7 @@ maintainer: streamly@composewell.com copyright: 2017 Composewell Technologies category: Control, Concurrency, Streaming, Reactivity stability: Experimental -build-type: Configure +build-type: Custom extra-source-files: .circleci/config.yml @@ -238,6 +238,16 @@ flag opt manual: True default: True +flag doctests + description: Build doctests test suite + manual: True + default: False + +custom-setup + setup-depends: + base >= 4 && <5, + cabal-doctest >= 1 && <1.1 + ------------------------------------------------------------------------------- -- Common stanzas ------------------------------------------------------------------------------- @@ -570,3 +580,19 @@ library -- tests fail if flag(dev) && flag(inspection) build-depends: inspection-and-dev-flags-cannot-be-used-together + +test-suite doctests + type: exitcode-stdio-1.0 + main-is: doctests.hs + if flag(doctests) + build-depends: + base + , base-compat >=0.10.5 && <0.12 + , doctest >=0.15 && <0.18 + , streamly + else + buildable: False + + ghc-options: -Wall -threaded + hs-source-dirs: . + default-language: Haskell2010