Skip to content

Commit 920cdcc

Browse files
chore: run doctests in parallel
Runs the doctests much faster, which is potentially useful in combination with postgrest-watch for local development. This implies that doctests run on compiled code, not in a GHCi session, which has some implications: - Only exported functions can be tested. - Imports need to be made explicit in doctests themselves. On the flipside, this would allow us to potentially include doctest results in code coverage, I believe. This change is a requirement to vendor hasql, which otherwise breaks the existing doctests: hasql contains a .hsc file, which *needs* to be compiled - not interpreted - to make the tests work.
1 parent babc447 commit 920cdcc

11 files changed

Lines changed: 54 additions & 28 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ gen_private.json
3030
.pytest_cache
3131
.ruff_cache
3232
postgrest-module-graph.png
33+
.ghc.environment.*

cabal.project

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ packages: postgrest.cabal
22
tests: true
33
allow-newer:
44
hasql:postgresql-libpq
5+
6+
-- https://github.com/martijnbastiaan/doctest-parallel/blob/main/example/README.md#cabalproject
7+
write-ghc-environment-files: always

postgrest.cabal

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,14 +352,11 @@ test-suite observability
352352
test-suite doctests
353353
type: exitcode-stdio-1.0
354354
default-language: Haskell2010
355-
default-extensions: OverloadedStrings
356-
NoImplicitPrelude
357355
hs-source-dirs: test/doc
358356
main-is: Main.hs
359357
build-depends: base >= 4.9 && < 4.22
360-
, doctest >= 0.8
358+
, doctest-parallel >= 0.4
361359
, postgrest
362360
, pretty-simple
363-
, protolude >= 0.3.1 && < 0.4
364361
ghc-options: -threaded -O0 -Werror -Wall -fwarn-identities
365362
-fno-spec-constr -optP-Wno-nonportable-include-path

src/PostgREST/ApiRequest/Preferences.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module PostgREST.ApiRequest.Preferences
2121
, shouldCount
2222
, shouldExplainCount
2323
, prefAppliedHeader
24+
, toHeaderValue
2425
) where
2526

2627
import qualified Data.ByteString.Char8 as BS
@@ -34,7 +35,10 @@ import Protolude
3435

3536
-- $setup
3637
-- Setup for doctests
38+
-- >>> :set -XStandaloneDeriving
3739
-- >>> import Text.Pretty.Simple (pPrint)
40+
-- >>> import qualified Data.Set as S
41+
-- >>> import Protolude
3842
-- >>> deriving instance Show PreferResolution
3943
-- >>> deriving instance Show PreferRepresentation
4044
-- >>> deriving instance Show PreferCount

src/PostgREST/ApiRequest/QueryParams.hs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,18 @@
99
module PostgREST.ApiRequest.QueryParams
1010
( parse
1111
, QueryParams(..)
12+
, pFieldForest
13+
, pFieldName
14+
, pFieldSelect
15+
, pJsonPath
16+
, pLogicTree
17+
, pOpExpr
18+
, pOrder
19+
, pRelationSelect
20+
, pRequestFilter
1221
, pRequestRange
22+
, pSingleVal
23+
, pSpreadRelationSelect
1324
) where
1425

1526
import qualified Data.ByteString.Char8 as BS
@@ -62,6 +73,10 @@ import PostgREST.Error (QPError (..))
6273

6374
import Protolude hiding (Sum, try)
6475

76+
-- $setup
77+
-- >>> import qualified Text.ParserCombinators.Parsec as P
78+
-- >>> import Protolude hiding (Sum, try)
79+
6580
data QueryParams =
6681
QueryParams
6782
{ qsCanonical :: ByteString

src/PostgREST/Config.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ pgConnString conn | uriDesignator `T.isPrefixOf` conn || shortUriDesignator `T.i
597597

598598
-- | Adds a `fallback_application_name` value to the connection string. This allows querying the PostgREST version on pg_stat_activity.
599599
--
600+
-- >>> import Protolude
600601
-- >>> let ver = "11.1.0 (5a04ec7)"::ByteString
601602
-- >>> let strangeVer = "11'1&0@#$%,.:\"[]{}?+^()=asdfqwer"::ByteString
602603
--

src/PostgREST/Error.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ module PostgREST.Error
1919
, JwtClaimsError(..)
2020
, errorPayload
2121
, status
22+
, noRelBetweenHint
23+
, noRpcHint
2224
) where
2325

2426
import qualified Data.Aeson as JSON
@@ -57,6 +59,12 @@ import PostgREST.Error.Types
5759

5860
import Protolude
5961

62+
-- $setup
63+
-- >>> import qualified Data.HashMap.Strict as HM
64+
-- >>> import PostgREST.SchemaCache.Identifiers (QualifiedIdentifier (..))
65+
-- >>> import PostgREST.SchemaCache.Relationship (Relationship (..))
66+
-- >>> import PostgREST.SchemaCache.Routine (Routine (..), RoutineParam (..))
67+
6068
-- | Encode Error to ByteString
6169
errorPayload :: (ErrorBody a, ErrorHeaders a) => Verbosity -> a -> LByteString
6270
errorPayload verb = JSON.encode . toJsonPgrstError verb

src/PostgREST/MediaType.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module PostgREST.MediaType
99
, toContentType
1010
, toMime
1111
, decodeMediaType
12+
, tokenizeMediaType
1213
) where
1314

1415
import qualified Data.Aeson as JSON
@@ -22,6 +23,9 @@ import Network.HTTP.Types.Header (Header, hContentType)
2223

2324
import Protolude
2425

26+
-- $setup
27+
-- >>> import qualified Text.ParserCombinators.Parsec as P
28+
2529
-- | Enumeration of currently supported media types
2630
data MediaType
2731
= MTApplicationJSON

src/PostgREST/Plan.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module PostgREST.Plan
2424
, InfoPlan(..)
2525
, CrudPlan(..)
2626
, legacyWarnings
27+
, addNullEmbedFilters
2728
) where
2829

2930
import qualified Data.HashMap.Strict as HM
@@ -87,7 +88,16 @@ import Protolude hiding (from)
8788

8889
-- $setup
8990
-- Setup for doctests
91+
-- >>> :set -XDuplicateRecordFields
9092
-- >>> import Data.Ranged.Ranges (fullRange)
93+
-- >>> import Data.Tree (Tree (..))
94+
-- >>> import PostgREST.SchemaCache.Identifiers (QualifiedIdentifier (..))
95+
-- >>> import PostgREST.ApiRequest.Types
96+
-- >>> import PostgREST.Plan.CallPlan
97+
-- >>> import PostgREST.Plan.MutatePlan
98+
-- >>> import PostgREST.Plan.ReadPlan as ReadPlan
99+
-- >>> import PostgREST.Plan.Types
100+
-- >>> import Protolude
91101

92102
-- Plan for reading or writing to the db
93103
data CrudPlan

src/PostgREST/Response/Performance.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import qualified Network.HTTP.Types as HTTP
88
import Numeric (showFFloat)
99
import Protolude
1010

11+
-- $setup
12+
-- >>> import Protolude
13+
1114
-- | ServerTiming represents the timing data for a request, in seconds.
1215
data ServerTiming =
1316
ServerTiming

0 commit comments

Comments
 (0)