on master help sign in
Change build-type: Simple; run doctests on CI via haskell-ci

Don't use hspec-discover in tutorial, so doctests work on CI

commit524b07224ff8466416716e72d5ff9afa483464cb authorOleg Grenrus <oleg.grenrus@iki.fi> dateThu 9 Jan 2020, 22:19 (7 years ago) parentec0cd8a
15 files changed+72−200
.travis.yml+25−28 Makefile+10 cabal.haskell-ci+3 cabal.project+3 changelog.d/pr1249+2−1 changelog.d/pr1263+11 doc/tutorial/test/Spec.hs+11−1 doc/tutorial/tutorial.cabal−2 servant-server/Setup.hs+1−32 servant-server/servant-server.cabal+1−20 servant-server/test/doctests.hs−27 servant/Setup.hs+1−32 servant/servant.cabal+1−30 servant/test/Servant/LinksSpec.hs+3 servant/test/doctests.hs−27
.travis.yml+25−28
@@ -4,7 +4,7 @@
44#
55# For more information, see https://github.com/haskell-CI/haskell-ci
66#
7−# version: 0.9.20191209
7+# version: 0.9.20200110
88#
99version: ~> 1.0
1010language: c
@@ -73,26 +73,8 @@ before_install:
7373 - TOP=$(pwd)
7474 - "HCNUMVER=$(${HC} --numeric-version|perl -ne '/^(\\d+)\\.(\\d+)\\.(\\d+)(\\.(\\d+))?$/; print(10000 * $1 + 100 * $2 + ($3 == 0 ? $5 != 1 : $3))')"
7575 - echo $HCNUMVER
76− - CABAL="$CABAL -vnormal+nowrap+markoutput"
76+ - CABAL="$CABAL -vnormal+nowrap"
7777 - set -o pipefail
78− - |
79− echo 'function blue(s) { printf "\033[0;34m" s "\033[0m " }' >> .colorful.awk
80− echo 'BEGIN { state = "output"; }' >> .colorful.awk
81− echo '/^-----BEGIN CABAL OUTPUT-----$/ { state = "cabal" }' >> .colorful.awk
82− echo '/^-----END CABAL OUTPUT-----$/ { state = "output" }' >> .colorful.awk
83− echo '!/^(-----BEGIN CABAL OUTPUT-----|-----END CABAL OUTPUT-----)/ {' >> .colorful.awk
84− echo ' if (state == "cabal") {' >> .colorful.awk
85− echo ' print blue($0)' >> .colorful.awk
86− echo ' } else {' >> .colorful.awk
87− echo ' print $0' >> .colorful.awk
88− echo ' }' >> .colorful.awk
89− echo '}' >> .colorful.awk
90− - cat .colorful.awk
91− - |
92− color_cabal_output () {
93− awk -f $TOP/.colorful.awk
94− }
95− - echo text | color_cabal_output
9678install:
9779 - ${CABAL} --version
9880 - echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]"
@@ -133,8 +115,9 @@ install:
133115 - cat $CABALHOME/config
134116 - rm -fv cabal.project cabal.project.local cabal.project.freeze
135117 - travis_retry ${CABAL} v2-update -v
136− - if $GHCJS ; then (cd /tmp && ${CABAL} v2-install -w ghc-8.4.4 cabal-plan --constraint='cabal-plan ^>=0.6.0.0' --constraint='cabal-plan +exe' | color_cabal_output) ; fi
137− - if $GHCJS ; then (cd /tmp && ${CABAL} v2-install -w ghc-8.4.4 hspec-discover | color_cabal_output) ; fi
118+ - if ! $GHCJS ; then (cd /tmp && ${CABAL} v2-install $WITHCOMPILER -j2 doctest --constraint='doctest ==0.16.2.*') ; fi
119+ - if $GHCJS ; then (cd /tmp && ${CABAL} v2-install -w ghc-8.4.4 cabal-plan --constraint='cabal-plan ^>=0.6.0.0' --constraint='cabal-plan +exe') ; fi
120+ - if $GHCJS ; then (cd /tmp && ${CABAL} v2-install -w ghc-8.4.4 hspec-discover) ; fi
138121 # Generate cabal.project
139122 - rm -rf cabal.project cabal.project.local cabal.project.freeze
140123 - touch cabal.project
@@ -212,14 +195,14 @@ install:
212195 - if [ -f "doc/cookbook/structuring-apis/configure.ac" ]; then (cd "doc/cookbook/structuring-apis" && autoreconf -i); fi
213196 - if [ -f "doc/cookbook/using-custom-monad/configure.ac" ]; then (cd "doc/cookbook/using-custom-monad" && autoreconf -i); fi
214197 - if [ -f "doc/cookbook/using-free-client/configure.ac" ]; then (cd "doc/cookbook/using-free-client" && autoreconf -i); fi
215− - ${CABAL} v2-freeze $WITHCOMPILER ${TEST} ${BENCH} | color_cabal_output
198+ - ${CABAL} v2-freeze $WITHCOMPILER ${TEST} ${BENCH}
216199 - "cat cabal.project.freeze | sed -E 's/^(constraints: *| *)//' | sed 's/any.//'"
217200 - rm cabal.project.freeze
218201script:
219202 - DISTDIR=$(mktemp -d /tmp/dist-test.XXXX)
220203 # Packaging...
221204 - echo 'Packaging...' && echo -en 'travis_fold:start:sdist\\r'
222− - ${CABAL} v2-sdist all | color_cabal_output
205+ - ${CABAL} v2-sdist all
223206 - echo -en 'travis_fold:end:sdist\\r'
224207 # Unpacking...
225208 - echo 'Unpacking...' && echo -en 'travis_fold:start:unpack\\r'
@@ -335,15 +318,29 @@ script:
335318 # Building with tests and benchmarks...
336319 - echo 'Building with tests and benchmarks...' && echo -en 'travis_fold:start:build-everything\\r'
337320 # build & run tests, build benchmarks
338− - ${CABAL} v2-build $WITHCOMPILER ${TEST} ${BENCH} all | color_cabal_output
321+ - ${CABAL} v2-build $WITHCOMPILER ${TEST} ${BENCH} all
339322 - echo -en 'travis_fold:end:build-everything\\r'
340323 # Testing...
341− - if ! $GHCJS ; then ${CABAL} v2-test $WITHCOMPILER ${TEST} ${BENCH} all | color_cabal_output ; fi
324+ - if ! $GHCJS ; then ${CABAL} v2-test $WITHCOMPILER ${TEST} ${BENCH} all ; fi
342325 - if $GHCJS ; then cabal-plan list-bins '*:test:*' | while read -r line; do testpkg=$(echo "$line" | perl -pe 's/:.*//'); testexe=$(echo "$line" | awk '{ print $2 }'); echo "testing $textexe in package $textpkg"; (cd "$(pkgdir $testpkg)" && nodejs "$testexe".jsexe/all.js); done ; fi
326+ # Doctest...
327+ - echo 'Doctest...' && echo -en 'travis_fold:start:doctest\\r'
328+ - perl -i -e 'while (<ARGV>) { print unless /package-id\s+(base-compat-batteries)-\d+(\.\d+)*/; }' .ghc.environment.*
329+ - if ! $GHCJS ; then (cd ${PKGDIR_servant} && doctest src) ; fi
330+ - if ! $GHCJS ; then (cd ${PKGDIR_servant_client} && doctest src) ; fi
331+ - if ! $GHCJS ; then (cd ${PKGDIR_servant_client_core} && doctest src) ; fi
332+ - if ! $GHCJS ; then (cd ${PKGDIR_servant_http_streams} && doctest src) ; fi
333+ - if ! $GHCJS ; then (cd ${PKGDIR_servant_docs} && doctest src) ; fi
334+ - if ! $GHCJS ; then (cd ${PKGDIR_servant_foreign} && doctest src) ; fi
335+ - if ! $GHCJS ; then (cd ${PKGDIR_servant_server} && doctest src) ; fi
336+ - if ! $GHCJS ; then (cd ${PKGDIR_servant_machines} && doctest src) ; fi
337+ - if ! $GHCJS ; then (cd ${PKGDIR_servant_conduit} && doctest src) ; fi
338+ - if ! $GHCJS ; then (cd ${PKGDIR_servant_pipes} && doctest src) ; fi
339+ - echo -en 'travis_fold:end:doctest\\r'
343340 # haddock...
344341 - echo 'haddock...' && echo -en 'travis_fold:start:haddock\\r'
345− - if ! $GHCJS ; then ${CABAL} v2-haddock $WITHCOMPILER --with-haddock $HADDOCK ${TEST} ${BENCH} all | color_cabal_output ; fi
342+ - if ! $GHCJS ; then ${CABAL} v2-haddock $WITHCOMPILER --with-haddock $HADDOCK ${TEST} ${BENCH} all ; fi
346343 - echo -en 'travis_fold:end:haddock\\r'
347344
348−# REGENDATA ("0.9.20191209",["--config=cabal.haskell-ci","--output=.travis.yml","cabal.project"])
345+# REGENDATA ("0.9.20200110",["--config=cabal.haskell-ci","--output=.travis.yml","cabal.project"])
349346# EOF
Makefile+10
@@ -20,3 +20,13 @@ build-ghcjs :
2020
2121packdeps :
2222 packdeps */*.cabal
23+
24+doctest : doctest-servant doctest-servant-server
25+ perl -i -e 'while (<ARGV>) { print unless /package-id\s+base-compat-\d+(\.\d+)*/; }' .ghc.environment.*
26+
27+doctest-servant :
28+ (cd servant && doctest src)
29+ (cd servant && doctest test/Servant/LinksSpec.hs)
30+
31+doctest-servant-server :
32+ (cd servant-server && doctest src)
cabal.haskell-ci+3
@@ -4,6 +4,9 @@ branches: master
44jobs-selection: any
55google-chrome: True
66ghcjs-tests: True
7+doctest: True
8+doctest-filter-packages: base-compat-batteries
9+doctest-skip: tutorial
710
811-- https://github.com/haskell/cabal/issues/6176
912ghcjs-tools: hspec-discover
cabal.project+3
@@ -76,3 +76,6 @@ allow-newer: jsaddle-dom-0.9.3.2:lens
7676allow-newer: jsaddle-warp-0.9.6.0:time
7777
7878constraints: base-compat ^>=0.11
79+
80+-- needed for doctests
81+write-ghc-environment-files: always
changelog.d/pr1249+2−1
@@ -1,6 +1,7 @@
11synopsis: use queryString to parse QueryParam, QueryParams and QueryFlag
22packages: servant-server
3−prs: #1249
3+prs: #1249 #1262
4+significance: significant
45description: {
56
67Some APIs need query parameters rewriting, e.g. in order to support
changelog.d/pr1263new file+11
@@ -0,0 +1,11 @@
1+synopsis: Make packages `build-type: Simple`
2+packages: servant servant-server
3+prs: #1263
4+significance: significant
5+description: {
6+
7+We used `build-type: Custom`, but it's problematic e.g.
8+for cross-compiling. The benefit is small, as the doctests
9+can be run other ways too (though not so conviniently).
10+
11+}
doc/tutorial/test/Spec.hs+11−1
@@ -1 +1,11 @@
1−{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
1+module Main where
2+
3+import qualified JavascriptSpec
4+
5+import Test.Hspec (Spec, hspec, describe)
6+
7+main :: IO ()
8+main = hspec spec
9+
10+spec :: Spec
11+spec = describe "Javascript" JavascriptSpec.spec
doc/tutorial/tutorial.cabal−2
@@ -83,8 +83,6 @@ test-suite spec
8383 hs-source-dirs: test
8484 main-is: Spec.hs
8585 other-modules: JavascriptSpec
86− build-tool-depends:
87− hspec-discover:hspec-discover
8886 build-depends: base
8987 , tutorial
9088 , hspec
servant-server/Setup.hs+1−32
@@ -1,33 +1,2 @@
1−{-# LANGUAGE CPP #-}
2−{-# OPTIONS_GHC -Wall #-}
3−module Main (main) where
4−
5−#ifndef MIN_VERSION_cabal_doctest
6−#define MIN_VERSION_cabal_doctest(x,y,z) 0
7−#endif
8−
9−#if MIN_VERSION_cabal_doctest(1,0,0)
10−
11−import Distribution.Extra.Doctest ( defaultMainWithDoctests )
12−main :: IO ()
13−main = defaultMainWithDoctests "doctests"
14−
15−#else
16−
17−#ifdef MIN_VERSION_Cabal
18−-- If the macro is defined, we have new cabal-install,
19−-- but for some reason we don't have cabal-doctest in package-db
20−--
21−-- Probably we are running cabal sdist, when otherwise using new-build
22−-- workflow
23−#warning You are configuring this package without cabal-doctest installed. \
24− The doctests test-suite will not work as a result. \
25− To fix this, install cabal-doctest before configuring.
26−#endif
27−
28−import Distribution.Simple
29−
30−main :: IO ()
1+import Distribution.Simple
312main = defaultMain
32−
33−#endif
servant-server/servant-server.cabal+1−20
@@ -22,7 +22,7 @@ license-file: LICENSE
2222author: Servant Contributors
2323maintainer: haskell-servant-maintainers@googlegroups.com
2424copyright: 2014-2016 Zalora South East Asia Pte Ltd, 2016-2019 Servant Contributors
25−build-type: Custom
25+build-type: Simple
2626tested-with:
2727 GHC ==8.0.2
2828 || ==8.2.2
@@ -38,12 +38,6 @@ source-repository head
3838 type: git
3939 location: http://github.com/haskell-servant/servant.git
4040
41−custom-setup
42− setup-depends:
43− base >= 4 && <5,
44− Cabal,
45− cabal-doctest >= 1.0.6 && <1.1
46−
4741library
4842 exposed-modules:
4943 Servant
@@ -173,16 +167,3 @@ test-suite spec
173167
174168 build-tool-depends:
175169 hspec-discover:hspec-discover >= 2.6.0 && <2.8
176−
177−test-suite doctests
178− build-depends:
179− base
180− , servant-server
181− , doctest >= 0.16.0 && <0.17
182− type: exitcode-stdio-1.0
183− main-is: test/doctests.hs
184− buildable: True
185− default-language: Haskell2010
186− ghc-options: -Wall -threaded
187− if impl(ghc >= 8.2)
188− x-doctest-options: -fdiagnostics-color=never
servant-server/test/doctests.hsdeleted−27
@@ -1,27 +0,0 @@
1−-----------------------------------------------------------------------------
2−-- |
3−-- Module : Main (doctests)
4−-- Copyright : (C) 2012-14 Edward Kmett
5−-- License : BSD-style (see the file LICENSE)
6−-- Maintainer : Edward Kmett <ekmett@gmail.com>
7−-- Stability : provisional
8−-- Portability : portable
9−--
10−-- This module provides doctests for a project based on the actual versions
11−-- of the packages it was built with. It requires a corresponding Setup.lhs
12−-- to be added to the project
13−-----------------------------------------------------------------------------
14−module Main where
15−
16−import Build_doctests
17− (flags, module_sources, pkgs)
18−import Data.Foldable
19− (traverse_)
20−import Test.DocTest
21−
22−main :: IO ()
23−main = do
24− traverse_ putStrLn args
25− doctest args
26− where
27− args = flags ++ pkgs ++ module_sources
servant/Setup.hs+1−32
@@ -1,33 +1,2 @@
1−{-# LANGUAGE CPP #-}
2−{-# OPTIONS_GHC -Wall #-}
3−module Main (main) where
4−
5−#ifndef MIN_VERSION_cabal_doctest
6−#define MIN_VERSION_cabal_doctest(x,y,z) 0
7−#endif
8−
9−#if MIN_VERSION_cabal_doctest(1,0,0)
10−
11−import Distribution.Extra.Doctest ( defaultMainWithDoctests )
12−main :: IO ()
13−main = defaultMainWithDoctests "doctests"
14−
15−#else
16−
17−#ifdef MIN_VERSION_Cabal
18−-- If the macro is defined, we have new cabal-install,
19−-- but for some reason we don't have cabal-doctest in package-db
20−--
21−-- Probably we are running cabal sdist, when otherwise using new-build
22−-- workflow
23−#warning You are configuring this package without cabal-doctest installed. \
24− The doctests test-suite will not work as a result. \
25− To fix this, install cabal-doctest before configuring.
26−#endif
27−
28−import Distribution.Simple
29−
30−main :: IO ()
1+import Distribution.Simple
312main = defaultMain
32−
33−#endif
servant/servant.cabal+1−30
@@ -18,7 +18,7 @@ license-file: LICENSE
1818author: Servant Contributors
1919maintainer: haskell-servant-maintainers@googlegroups.com
2020copyright: 2014-2016 Zalora South East Asia Pte Ltd, 2016-2019 Servant Contributors
21−build-type: Custom
21+build-type: Simple
2222
2323tested-with:
2424 GHC ==8.0.2
@@ -35,12 +35,6 @@ source-repository head
3535 type: git
3636 location: http://github.com/haskell-servant/servant.git
3737
38−custom-setup
39− setup-depends:
40− base >= 4 && <5,
41− Cabal,
42− cabal-doctest >= 1.0.6 && <1.1
43−
4438library
4539 exposed-modules:
4640 Servant.API
@@ -176,26 +170,3 @@ test-suite spec
176170
177171 build-tool-depends:
178172 hspec-discover:hspec-discover >= 2.6.0 && < 2.8
179−
180−test-suite doctests
181− if impl(ghcjs)
182− buildable: False
183−
184− build-depends:
185− base
186− , servant
187− , doctest >= 0.16.0 && <0.17
188−
189− -- We test Links failure with doctest, so we need extra dependencies
190− build-depends:
191− hspec >= 2.6.0 && < 2.8
192−
193− type: exitcode-stdio-1.0
194− main-is: test/doctests.hs
195− buildable: True
196− default-language: Haskell2010
197− ghc-options: -Wall -threaded
198− if impl(ghc >= 8.2)
199− x-doctest-options: -fdiagnostics-color=never
200− x-doctest-source-dirs: test
201− x-doctest-modules: Servant.LinksSpec
servant/test/Servant/LinksSpec.hs+3
@@ -92,6 +92,9 @@ spec = describe "Servant.Links" $ do
9292 let firstLink :<|> _ = allLinks comprehensiveAPIWithoutRaw
9393 firstLink `shouldBeLink` ""
9494
95+-- The doctests below aren't run on CI, setting that up is tricky.
96+-- They are run by makefile rule, however.
97+
9598-- |
9699-- Before https://github.com/CRogers/should-not-typecheck/issues/5 is fixed,
97100-- we'll just use doctest
servant/test/doctests.hsdeleted−27
@@ -1,27 +0,0 @@
1−-----------------------------------------------------------------------------
2−-- |
3−-- Module : Main (doctests)
4−-- Copyright : (C) 2012-14 Edward Kmett
5−-- License : BSD-style (see the file LICENSE)
6−-- Maintainer : Edward Kmett <ekmett@gmail.com>
7−-- Stability : provisional
8−-- Portability : portable
9−--
10−-- This module provides doctests for a project based on the actual versions
11−-- of the packages it was built with. It requires a corresponding Setup.lhs
12−-- to be added to the project
13−-----------------------------------------------------------------------------
14−module Main where
15−
16−import Build_doctests
17− (flags, module_sources, pkgs)
18−import Data.Foldable
19− (traverse_)
20−import Test.DocTest
21−
22−main :: IO ()
23−main = do
24− traverse_ putStrLn args
25− doctest args
26− where
27− args = flags ++ pkgs ++ module_sources