on 11bcbbb help sign in
rel8/Doctest.hs
53 lines 1.9 kB history raw
1{-# language BlockArguments #-}
2{-# language OverloadedStrings #-}
4module Main where
6-- base
7import Control.Exception ( bracket, throwIO )
8import Data.Foldable ( traverse_ )
9import System.Environment ( lookupEnv, setEnv )
11-- base-compat
12import System.Environment.Compat ( unsetEnv )
14-- bytestring
15import Data.ByteString.Char8 ( unpack )
17-- doctest
18import Test.DocTest ( doctest )
20-- hasql
21import Hasql.Connection ( acquire, release )
22import Hasql.Session ( run, sql )
24-- rel8
25import Build_doctests ( flags, module_sources, pkgs )
27-- tmp-postgres
28import Database.Postgres.Temp ( toConnectionString, verboseConfig, with, withConfig )
31main :: IO ()
32main = do
33 nixGhcLibdir <- lookupEnv "NIX_GHC_LIBDIR"
34 unsetEnv "GHC_ENVIRONMENT"
35 either throwIO return =<< with \db -> do
36 setEnv "TEST_DATABASE_URL" (unpack (toConnectionString db))
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 )"
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' )"
49 doctest (args nixGhcLibdir)
51 where
52 args nixGhcLibdir =
53 flags ++ pkgs ++ foldMap (\x -> ["-package-db" <> x <> "/package.conf.d"]) nixGhcLibdir ++ module_sources