From 524b07224ff8466416716e72d5ff9afa483464cb Mon Sep 17 00:00:00 2001 From: Oleg Grenrus Date: Thu, 9 Jan 2020 22:19:24 +0200 Subject: [PATCH] Change build-type: Simple; run doctests on CI via haskell-ci Don't use hspec-discover in tutorial, so doctests work on CI --- .travis.yml | 53 ++++++++++++++--------------- Makefile | 10 ++++++ cabal.haskell-ci | 3 ++ cabal.project | 3 ++ changelog.d/pr1249 | 3 +- changelog.d/pr1263 | 11 ++++++ doc/tutorial/test/Spec.hs | 12 ++++++- doc/tutorial/tutorial.cabal | 2 -- servant-server/Setup.hs | 33 +----------------- servant-server/servant-server.cabal | 21 +----------- servant-server/test/doctests.hs | 27 --------------- servant/Setup.hs | 33 +----------------- servant/servant.cabal | 31 +---------------- servant/test/Servant/LinksSpec.hs | 3 ++ servant/test/doctests.hs | 27 --------------- 15 files changed, 72 insertions(+), 200 deletions(-) create mode 100644 changelog.d/pr1263 delete mode 100644 servant-server/test/doctests.hs delete mode 100644 servant/test/doctests.hs diff --git a/.travis.yml b/.travis.yml index 0fafe196..272e8f08 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ # # For more information, see https://github.com/haskell-CI/haskell-ci # -# version: 0.9.20191209 +# version: 0.9.20200110 # version: ~> 1.0 language: c @@ -73,26 +73,8 @@ before_install: - TOP=$(pwd) - "HCNUMVER=$(${HC} --numeric-version|perl -ne '/^(\\d+)\\.(\\d+)\\.(\\d+)(\\.(\\d+))?$/; print(10000 * $1 + 100 * $2 + ($3 == 0 ? $5 != 1 : $3))')" - echo $HCNUMVER - - CABAL="$CABAL -vnormal+nowrap+markoutput" + - CABAL="$CABAL -vnormal+nowrap" - set -o pipefail - - | - echo 'function blue(s) { printf "\033[0;34m" s "\033[0m " }' >> .colorful.awk - echo 'BEGIN { state = "output"; }' >> .colorful.awk - echo '/^-----BEGIN CABAL OUTPUT-----$/ { state = "cabal" }' >> .colorful.awk - echo '/^-----END CABAL OUTPUT-----$/ { state = "output" }' >> .colorful.awk - echo '!/^(-----BEGIN CABAL OUTPUT-----|-----END CABAL OUTPUT-----)/ {' >> .colorful.awk - echo ' if (state == "cabal") {' >> .colorful.awk - echo ' print blue($0)' >> .colorful.awk - echo ' } else {' >> .colorful.awk - echo ' print $0' >> .colorful.awk - echo ' }' >> .colorful.awk - echo '}' >> .colorful.awk - - cat .colorful.awk - - | - color_cabal_output () { - awk -f $TOP/.colorful.awk - } - - echo text | color_cabal_output install: - ${CABAL} --version - echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]" @@ -133,8 +115,9 @@ install: - cat $CABALHOME/config - rm -fv cabal.project cabal.project.local cabal.project.freeze - travis_retry ${CABAL} v2-update -v - - 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 - - if $GHCJS ; then (cd /tmp && ${CABAL} v2-install -w ghc-8.4.4 hspec-discover | color_cabal_output) ; fi + - if ! $GHCJS ; then (cd /tmp && ${CABAL} v2-install $WITHCOMPILER -j2 doctest --constraint='doctest ==0.16.2.*') ; fi + - 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 + - if $GHCJS ; then (cd /tmp && ${CABAL} v2-install -w ghc-8.4.4 hspec-discover) ; fi # Generate cabal.project - rm -rf cabal.project cabal.project.local cabal.project.freeze - touch cabal.project @@ -212,14 +195,14 @@ install: - if [ -f "doc/cookbook/structuring-apis/configure.ac" ]; then (cd "doc/cookbook/structuring-apis" && autoreconf -i); fi - if [ -f "doc/cookbook/using-custom-monad/configure.ac" ]; then (cd "doc/cookbook/using-custom-monad" && autoreconf -i); fi - if [ -f "doc/cookbook/using-free-client/configure.ac" ]; then (cd "doc/cookbook/using-free-client" && autoreconf -i); fi - - ${CABAL} v2-freeze $WITHCOMPILER ${TEST} ${BENCH} | color_cabal_output + - ${CABAL} v2-freeze $WITHCOMPILER ${TEST} ${BENCH} - "cat cabal.project.freeze | sed -E 's/^(constraints: *| *)//' | sed 's/any.//'" - rm cabal.project.freeze script: - DISTDIR=$(mktemp -d /tmp/dist-test.XXXX) # Packaging... - echo 'Packaging...' && echo -en 'travis_fold:start:sdist\\r' - - ${CABAL} v2-sdist all | color_cabal_output + - ${CABAL} v2-sdist all - echo -en 'travis_fold:end:sdist\\r' # Unpacking... - echo 'Unpacking...' && echo -en 'travis_fold:start:unpack\\r' @@ -335,15 +318,29 @@ script: # Building with tests and benchmarks... - echo 'Building with tests and benchmarks...' && echo -en 'travis_fold:start:build-everything\\r' # build & run tests, build benchmarks - - ${CABAL} v2-build $WITHCOMPILER ${TEST} ${BENCH} all | color_cabal_output + - ${CABAL} v2-build $WITHCOMPILER ${TEST} ${BENCH} all - echo -en 'travis_fold:end:build-everything\\r' # Testing... - - if ! $GHCJS ; then ${CABAL} v2-test $WITHCOMPILER ${TEST} ${BENCH} all | color_cabal_output ; fi + - if ! $GHCJS ; then ${CABAL} v2-test $WITHCOMPILER ${TEST} ${BENCH} all ; fi - 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 + # Doctest... + - echo 'Doctest...' && echo -en 'travis_fold:start:doctest\\r' + - perl -i -e 'while () { print unless /package-id\s+(base-compat-batteries)-\d+(\.\d+)*/; }' .ghc.environment.* + - if ! $GHCJS ; then (cd ${PKGDIR_servant} && doctest src) ; fi + - if ! $GHCJS ; then (cd ${PKGDIR_servant_client} && doctest src) ; fi + - if ! $GHCJS ; then (cd ${PKGDIR_servant_client_core} && doctest src) ; fi + - if ! $GHCJS ; then (cd ${PKGDIR_servant_http_streams} && doctest src) ; fi + - if ! $GHCJS ; then (cd ${PKGDIR_servant_docs} && doctest src) ; fi + - if ! $GHCJS ; then (cd ${PKGDIR_servant_foreign} && doctest src) ; fi + - if ! $GHCJS ; then (cd ${PKGDIR_servant_server} && doctest src) ; fi + - if ! $GHCJS ; then (cd ${PKGDIR_servant_machines} && doctest src) ; fi + - if ! $GHCJS ; then (cd ${PKGDIR_servant_conduit} && doctest src) ; fi + - if ! $GHCJS ; then (cd ${PKGDIR_servant_pipes} && doctest src) ; fi + - echo -en 'travis_fold:end:doctest\\r' # haddock... - echo 'haddock...' && echo -en 'travis_fold:start:haddock\\r' - - if ! $GHCJS ; then ${CABAL} v2-haddock $WITHCOMPILER --with-haddock $HADDOCK ${TEST} ${BENCH} all | color_cabal_output ; fi + - if ! $GHCJS ; then ${CABAL} v2-haddock $WITHCOMPILER --with-haddock $HADDOCK ${TEST} ${BENCH} all ; fi - echo -en 'travis_fold:end:haddock\\r' -# REGENDATA ("0.9.20191209",["--config=cabal.haskell-ci","--output=.travis.yml","cabal.project"]) +# REGENDATA ("0.9.20200110",["--config=cabal.haskell-ci","--output=.travis.yml","cabal.project"]) # EOF diff --git a/Makefile b/Makefile index 34180491..2caf4c05 100644 --- a/Makefile +++ b/Makefile @@ -20,3 +20,13 @@ build-ghcjs : packdeps : packdeps */*.cabal + +doctest : doctest-servant doctest-servant-server + perl -i -e 'while () { print unless /package-id\s+base-compat-\d+(\.\d+)*/; }' .ghc.environment.* + +doctest-servant : + (cd servant && doctest src) + (cd servant && doctest test/Servant/LinksSpec.hs) + +doctest-servant-server : + (cd servant-server && doctest src) diff --git a/cabal.haskell-ci b/cabal.haskell-ci index 85c02cf6..ac041d53 100644 --- a/cabal.haskell-ci +++ b/cabal.haskell-ci @@ -4,6 +4,9 @@ branches: master jobs-selection: any google-chrome: True ghcjs-tests: True +doctest: True +doctest-filter-packages: base-compat-batteries +doctest-skip: tutorial -- https://github.com/haskell/cabal/issues/6176 ghcjs-tools: hspec-discover diff --git a/cabal.project b/cabal.project index d926827c..11c22cb4 100644 --- a/cabal.project +++ b/cabal.project @@ -76,3 +76,6 @@ allow-newer: jsaddle-dom-0.9.3.2:lens allow-newer: jsaddle-warp-0.9.6.0:time constraints: base-compat ^>=0.11 + +-- needed for doctests +write-ghc-environment-files: always diff --git a/changelog.d/pr1249 b/changelog.d/pr1249 index ff15673a..3a5c772a 100644 --- a/changelog.d/pr1249 +++ b/changelog.d/pr1249 @@ -1,6 +1,7 @@ synopsis: use queryString to parse QueryParam, QueryParams and QueryFlag packages: servant-server -prs: #1249 +prs: #1249 #1262 +significance: significant description: { Some APIs need query parameters rewriting, e.g. in order to support diff --git a/changelog.d/pr1263 b/changelog.d/pr1263 new file mode 100644 index 00000000..593bcd1b --- /dev/null +++ b/changelog.d/pr1263 @@ -0,0 +1,11 @@ +synopsis: Make packages `build-type: Simple` +packages: servant servant-server +prs: #1263 +significance: significant +description: { + +We used `build-type: Custom`, but it's problematic e.g. +for cross-compiling. The benefit is small, as the doctests +can be run other ways too (though not so conviniently). + +} diff --git a/doc/tutorial/test/Spec.hs b/doc/tutorial/test/Spec.hs index a824f8c3..4808302a 100644 --- a/doc/tutorial/test/Spec.hs +++ b/doc/tutorial/test/Spec.hs @@ -1 +1,11 @@ -{-# OPTIONS_GHC -F -pgmF hspec-discover #-} +module Main where + +import qualified JavascriptSpec + +import Test.Hspec (Spec, hspec, describe) + +main :: IO () +main = hspec spec + +spec :: Spec +spec = describe "Javascript" JavascriptSpec.spec diff --git a/doc/tutorial/tutorial.cabal b/doc/tutorial/tutorial.cabal index 296b6476..ce245b65 100644 --- a/doc/tutorial/tutorial.cabal +++ b/doc/tutorial/tutorial.cabal @@ -83,8 +83,6 @@ test-suite spec hs-source-dirs: test main-is: Spec.hs other-modules: JavascriptSpec - build-tool-depends: - hspec-discover:hspec-discover build-depends: base , tutorial , hspec diff --git a/servant-server/Setup.hs b/servant-server/Setup.hs index 8ec54a08..44671092 100644 --- a/servant-server/Setup.hs +++ b/servant-server/Setup.hs @@ -1,33 +1,2 @@ -{-# LANGUAGE CPP #-} -{-# OPTIONS_GHC -Wall #-} -module Main (main) where - -#ifndef MIN_VERSION_cabal_doctest -#define MIN_VERSION_cabal_doctest(x,y,z) 0 -#endif - -#if MIN_VERSION_cabal_doctest(1,0,0) - -import Distribution.Extra.Doctest ( defaultMainWithDoctests ) -main :: IO () -main = defaultMainWithDoctests "doctests" - -#else - -#ifdef MIN_VERSION_Cabal --- If the macro is defined, we have new cabal-install, --- but for some reason we don't have cabal-doctest in package-db --- --- Probably we are running cabal sdist, when otherwise using new-build --- workflow -#warning You are configuring this package without cabal-doctest installed. \ - The doctests test-suite will not work as a result. \ - To fix this, install cabal-doctest before configuring. -#endif - -import Distribution.Simple - -main :: IO () +import Distribution.Simple main = defaultMain - -#endif diff --git a/servant-server/servant-server.cabal b/servant-server/servant-server.cabal index 0372ac16..a3cadcaf 100644 --- a/servant-server/servant-server.cabal +++ b/servant-server/servant-server.cabal @@ -22,7 +22,7 @@ license-file: LICENSE author: Servant Contributors maintainer: haskell-servant-maintainers@googlegroups.com copyright: 2014-2016 Zalora South East Asia Pte Ltd, 2016-2019 Servant Contributors -build-type: Custom +build-type: Simple tested-with: GHC ==8.0.2 || ==8.2.2 @@ -38,12 +38,6 @@ source-repository head type: git location: http://github.com/haskell-servant/servant.git -custom-setup - setup-depends: - base >= 4 && <5, - Cabal, - cabal-doctest >= 1.0.6 && <1.1 - library exposed-modules: Servant @@ -173,16 +167,3 @@ test-suite spec build-tool-depends: hspec-discover:hspec-discover >= 2.6.0 && <2.8 - -test-suite doctests - build-depends: - base - , servant-server - , doctest >= 0.16.0 && <0.17 - type: exitcode-stdio-1.0 - main-is: test/doctests.hs - buildable: True - default-language: Haskell2010 - ghc-options: -Wall -threaded - if impl(ghc >= 8.2) - x-doctest-options: -fdiagnostics-color=never diff --git a/servant-server/test/doctests.hs b/servant-server/test/doctests.hs deleted file mode 100644 index c27aa580..00000000 --- a/servant-server/test/doctests.hs +++ /dev/null @@ -1,27 +0,0 @@ ------------------------------------------------------------------------------ --- | --- Module : Main (doctests) --- Copyright : (C) 2012-14 Edward Kmett --- License : BSD-style (see the file LICENSE) --- Maintainer : Edward Kmett --- Stability : provisional --- Portability : portable --- --- This module provides doctests for a project based on the actual versions --- of the packages it was built with. It requires a corresponding Setup.lhs --- to be added to the project ------------------------------------------------------------------------------ -module Main where - -import Build_doctests - (flags, module_sources, pkgs) -import Data.Foldable - (traverse_) -import Test.DocTest - -main :: IO () -main = do - traverse_ putStrLn args - doctest args - where - args = flags ++ pkgs ++ module_sources diff --git a/servant/Setup.hs b/servant/Setup.hs index 8ec54a08..44671092 100644 --- a/servant/Setup.hs +++ b/servant/Setup.hs @@ -1,33 +1,2 @@ -{-# LANGUAGE CPP #-} -{-# OPTIONS_GHC -Wall #-} -module Main (main) where - -#ifndef MIN_VERSION_cabal_doctest -#define MIN_VERSION_cabal_doctest(x,y,z) 0 -#endif - -#if MIN_VERSION_cabal_doctest(1,0,0) - -import Distribution.Extra.Doctest ( defaultMainWithDoctests ) -main :: IO () -main = defaultMainWithDoctests "doctests" - -#else - -#ifdef MIN_VERSION_Cabal --- If the macro is defined, we have new cabal-install, --- but for some reason we don't have cabal-doctest in package-db --- --- Probably we are running cabal sdist, when otherwise using new-build --- workflow -#warning You are configuring this package without cabal-doctest installed. \ - The doctests test-suite will not work as a result. \ - To fix this, install cabal-doctest before configuring. -#endif - -import Distribution.Simple - -main :: IO () +import Distribution.Simple main = defaultMain - -#endif diff --git a/servant/servant.cabal b/servant/servant.cabal index b44f9f48..aef26744 100644 --- a/servant/servant.cabal +++ b/servant/servant.cabal @@ -18,7 +18,7 @@ license-file: LICENSE author: Servant Contributors maintainer: haskell-servant-maintainers@googlegroups.com copyright: 2014-2016 Zalora South East Asia Pte Ltd, 2016-2019 Servant Contributors -build-type: Custom +build-type: Simple tested-with: GHC ==8.0.2 @@ -35,12 +35,6 @@ source-repository head type: git location: http://github.com/haskell-servant/servant.git -custom-setup - setup-depends: - base >= 4 && <5, - Cabal, - cabal-doctest >= 1.0.6 && <1.1 - library exposed-modules: Servant.API @@ -176,26 +170,3 @@ test-suite spec build-tool-depends: hspec-discover:hspec-discover >= 2.6.0 && < 2.8 - -test-suite doctests - if impl(ghcjs) - buildable: False - - build-depends: - base - , servant - , doctest >= 0.16.0 && <0.17 - - -- We test Links failure with doctest, so we need extra dependencies - build-depends: - hspec >= 2.6.0 && < 2.8 - - type: exitcode-stdio-1.0 - main-is: test/doctests.hs - buildable: True - default-language: Haskell2010 - ghc-options: -Wall -threaded - if impl(ghc >= 8.2) - x-doctest-options: -fdiagnostics-color=never - x-doctest-source-dirs: test - x-doctest-modules: Servant.LinksSpec diff --git a/servant/test/Servant/LinksSpec.hs b/servant/test/Servant/LinksSpec.hs index 1c448ba0..845f5ee7 100644 --- a/servant/test/Servant/LinksSpec.hs +++ b/servant/test/Servant/LinksSpec.hs @@ -92,6 +92,9 @@ spec = describe "Servant.Links" $ do let firstLink :<|> _ = allLinks comprehensiveAPIWithoutRaw firstLink `shouldBeLink` "" +-- The doctests below aren't run on CI, setting that up is tricky. +-- They are run by makefile rule, however. + -- | -- Before https://github.com/CRogers/should-not-typecheck/issues/5 is fixed, -- we'll just use doctest diff --git a/servant/test/doctests.hs b/servant/test/doctests.hs deleted file mode 100644 index c27aa580..00000000 --- a/servant/test/doctests.hs +++ /dev/null @@ -1,27 +0,0 @@ ------------------------------------------------------------------------------ --- | --- Module : Main (doctests) --- Copyright : (C) 2012-14 Edward Kmett --- License : BSD-style (see the file LICENSE) --- Maintainer : Edward Kmett --- Stability : provisional --- Portability : portable --- --- This module provides doctests for a project based on the actual versions --- of the packages it was built with. It requires a corresponding Setup.lhs --- to be added to the project ------------------------------------------------------------------------------ -module Main where - -import Build_doctests - (flags, module_sources, pkgs) -import Data.Foldable - (traverse_) -import Test.DocTest - -main :: IO () -main = do - traverse_ putStrLn args - doctest args - where - args = flags ++ pkgs ++ module_sources