on master help sign in
Restore the ability to run doctests
commit88e6ea542a44d15e3cd7d9212e7981cbd895050e authorOliver Charles <ollie@ocharles.org.uk> dateTue 23 Mar 2021, 21:07 (6 years ago) parentbb078d2
1 file changed+36−16
Doctest.hs+36−16
Doctest.hs+36−16
@@ -3,31 +3,51 @@
33
44module Main where
55
6−import Build_doctests ( flags, pkgs, module_sources )
6+-- base
77import Control.Exception ( bracket, throwIO )
8−import Data.ByteString.Char8 ( unpack )
98import Data.Foldable ( traverse_ )
10−import Database.PostgreSQL.Simple ( connectPostgreSQL, close, execute_ )
11−import Database.Postgres.Temp ( toConnectionString, with, withConfig, verboseConfig )
12−import System.Environment ( setEnv )
9+import System.Environment ( lookupEnv, setEnv )
10+
11+-- base-compat
1312import System.Environment.Compat ( unsetEnv )
13+
14+-- bytestring
15+import Data.ByteString.Char8 ( unpack )
16+
17+-- doctest
1418import Test.DocTest ( doctest )
1519
20+-- hasql
21+import Hasql.Connection ( acquire, release )
22+import Hasql.Session ( run, sql )
23+
24+-- rel8
25+import Build_doctests ( flags, module_sources, pkgs )
26+
27+-- tmp-postgres
28+import Database.Postgres.Temp ( toConnectionString, verboseConfig, with, withConfig )
29+
30+
1631main :: IO ()
1732main = do
18− unsetEnv "GHC_ENVIRONMENT" -- see 'Notes'; you may not need this
33+ nixGhcLibdir <- lookupEnv "NIX_GHC_LIBDIR"
34+ unsetEnv "GHC_ENVIRONMENT"
1935 either throwIO return =<< with \db -> do
2036 setEnv "TEST_DATABASE_URL" (unpack (toConnectionString db))
21− bracket (connectPostgreSQL (toConnectionString db)) close \conn -> do
22− execute_ conn "create table author ( author_id serial primary key, name text not null, url text )"
23− execute_ conn "create table project ( author_id int not null references author (author_id), name text not null )"
37+ bracket (either (error . show) return =<< acquire (toConnectionString db)) release \conn -> do
38+ flip run conn do
39+ sql "create table author ( author_id serial primary key, name text not null, url text )"
40+ sql "create table project ( author_id int not null references author (author_id), name text not null )"
41+
42+ sql "insert into author ( name, url ) values ( 'Ollie', 'https://ocharles.org.uk' )"
43+ sql "insert into author ( name, url ) values ( 'Bryan O''Sullivan', null )"
44+ sql "insert into author ( name, url ) values ( 'Emily Pillmore', 'https://cohomolo.gy' )"
45+ sql "insert into project ( author_id, name ) values ( 1, 'rel8' )"
46+ sql "insert into project ( author_id, name ) values ( 2, 'aeson' )"
47+ sql "insert into project ( author_id, name ) values ( 2, 'text' )"
2448
25− execute_ conn "insert into author ( name, url ) values ( 'Ollie', 'https://ocharles.org.uk' )"
26− execute_ conn "insert into author ( name, url ) values ( 'Bryan O''Sullivan', null )"
27− execute_ conn "insert into project ( author_id, name ) values ( 1, 'rel8' )"
28− execute_ conn "insert into project ( author_id, name ) values ( 2, 'aeson' )"
49+ doctest (args nixGhcLibdir)
2950
30− doctest args
31−
3251 where
33− args = flags ++ pkgs ++ module_sources
52+ args nixGhcLibdir =
53+ flags ++ pkgs ++ foldMap (\x -> ["-package-db" <> x <> "/package.conf.d"]) nixGhcLibdir ++ module_sources