2021-05-26 19:19:26 +03:00
|
|
|
{-# LANGUAGE UndecidableInstances #-}
|
2019-10-21 19:01:05 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
module Main (main) where
|
2020-12-28 15:56:00 +03:00
|
|
|
|
2022-03-09 05:26:38 +03:00
|
|
|
import Control.Concurrent.ExtendedSpec qualified as ConcurrentExtended
|
2021-09-24 01:56:37 +03:00
|
|
|
import Control.Concurrent.MVar
|
|
|
|
import Control.Natural ((:~>) (..))
|
|
|
|
import Data.Aeson qualified as A
|
|
|
|
import Data.ByteString.Lazy.Char8 qualified as BL
|
2021-11-09 17:21:48 +03:00
|
|
|
import Data.ByteString.Lazy.UTF8 qualified as LBS
|
2021-09-24 01:56:37 +03:00
|
|
|
import Data.Environment qualified as Env
|
2022-02-03 19:13:50 +03:00
|
|
|
import Data.HashMap.Strict.ExtendedSpec qualified as HashMapExtendedSpec
|
2022-04-05 21:14:25 +03:00
|
|
|
import Data.NonNegativeIntSpec qualified as NonNegativeIntSpec
|
2021-09-24 01:56:37 +03:00
|
|
|
import Data.Parser.CacheControlSpec qualified as CacheControlParser
|
|
|
|
import Data.Parser.JSONPathSpec qualified as JsonPath
|
2022-04-22 14:33:36 +03:00
|
|
|
import Data.Parser.RemoteRelationshipSpec qualified as RemoteRelationship
|
2022-04-05 21:14:25 +03:00
|
|
|
import Data.Parser.URLTemplateSpec qualified as URLTemplate
|
2021-09-24 01:56:37 +03:00
|
|
|
import Data.Time.Clock (getCurrentTime)
|
|
|
|
import Data.TimeSpec qualified as TimeSpec
|
2022-03-01 19:03:23 +03:00
|
|
|
import Data.TrieSpec qualified as TrieSpec
|
2021-09-24 01:56:37 +03:00
|
|
|
import Data.URL.Template
|
|
|
|
import Database.MSSQL.TransactionSpec qualified as TransactionSpec
|
|
|
|
import Database.PG.Query qualified as Q
|
|
|
|
import Hasura.App
|
|
|
|
( PGMetadataStorageAppT (..),
|
2022-01-04 14:53:50 +03:00
|
|
|
mkMSSQLSourceResolver,
|
2021-09-24 01:56:37 +03:00
|
|
|
mkPgSourceResolver,
|
|
|
|
)
|
2022-04-06 00:06:11 +03:00
|
|
|
import Hasura.AppSpec qualified as AppSpec
|
2022-05-02 08:03:12 +03:00
|
|
|
import Hasura.Backends.DataConnector.API.V0Spec qualified as DataConnector.API.V0Spec
|
2022-02-07 17:11:49 +03:00
|
|
|
import Hasura.Backends.MSSQL.ErrorSpec qualified as MSSQLErrorSpec
|
2021-12-01 15:49:30 +03:00
|
|
|
import Hasura.Backends.MySQL.DataLoader.ExecuteTests qualified as MySQLDataLoader
|
2022-04-27 16:57:28 +03:00
|
|
|
import Hasura.Backends.Postgres.Connection.MonadTx
|
|
|
|
import Hasura.Backends.Postgres.Connection.Settings
|
|
|
|
import Hasura.Backends.Postgres.Execute.Types
|
2022-06-17 13:43:17 +03:00
|
|
|
import Hasura.Backends.Postgres.SQL.Select.IdentifierUniquenessSpec qualified as IdentifierUniqueness
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.EventingSpec qualified as EventingSpec
|
2021-10-29 17:42:07 +03:00
|
|
|
import Hasura.GraphQL.NamespaceSpec qualified as NamespaceSpec
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.GraphQL.Parser.DirectivesTest qualified as GraphQLDirectivesSpec
|
2022-06-28 13:06:55 +03:00
|
|
|
import Hasura.GraphQL.Parser.MonadParseTest qualified as MonadParseSpec
|
2022-05-26 17:05:13 +03:00
|
|
|
import Hasura.GraphQL.Schema.Build.UpdateSpec qualified as UpdateSpec
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.GraphQL.Schema.RemoteTest qualified as GraphRemoteSchemaSpec
|
|
|
|
import Hasura.IncrementalSpec qualified as IncrementalSpec
|
2021-11-09 17:21:48 +03:00
|
|
|
import Hasura.Logging
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.Metadata.Class
|
2022-06-27 19:32:25 +03:00
|
|
|
import Hasura.Metadata.DTO.MetadataDTOSpec qualified as MetadataDTOSpec
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.Prelude
|
|
|
|
import Hasura.RQL.DDL.Schema.Cache
|
|
|
|
import Hasura.RQL.DDL.Schema.Cache.Common
|
2022-03-08 11:22:20 +03:00
|
|
|
import Hasura.RQL.IR.SelectSpec qualified as SelectSpec
|
2021-12-14 09:45:13 +03:00
|
|
|
import Hasura.RQL.MetadataSpec qualified as MetadataSpec
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.RQL.PermissionSpec qualified as PermSpec
|
2022-02-08 19:53:30 +03:00
|
|
|
import Hasura.RQL.Types.AllowlistSpec qualified as AllowlistSpec
|
2022-04-27 16:57:28 +03:00
|
|
|
import Hasura.RQL.Types.Common
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.RQL.Types.CommonSpec qualified as CommonTypesSpec
|
|
|
|
import Hasura.RQL.Types.EndpointSpec qualified as EndpointSpec
|
2022-04-27 16:57:28 +03:00
|
|
|
import Hasura.RQL.Types.Function
|
|
|
|
import Hasura.RQL.Types.RemoteSchema
|
|
|
|
import Hasura.RQL.Types.SchemaCache.Build
|
2022-02-28 10:49:13 +03:00
|
|
|
import Hasura.RQL.Types.TableSpec qualified as TableSpec
|
2022-01-19 07:46:42 +03:00
|
|
|
import Hasura.RQL.WebhookTransformsSpec qualified as WebhookTransformsSpec
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.SQL.WKTSpec qualified as WKTSpec
|
2022-01-28 03:17:53 +03:00
|
|
|
import Hasura.Server.Auth.JWTSpec qualified as JWTSpec
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.Server.AuthSpec qualified as AuthSpec
|
|
|
|
import Hasura.Server.Init
|
|
|
|
import Hasura.Server.Migrate
|
|
|
|
import Hasura.Server.MigrateSpec qualified as MigrateSpec
|
|
|
|
import Hasura.Server.TelemetrySpec qualified as TelemetrySpec
|
|
|
|
import Hasura.Server.Types
|
2022-04-05 21:14:25 +03:00
|
|
|
import Hasura.SessionSpec qualified as SessionSpec
|
2022-04-07 17:41:43 +03:00
|
|
|
import Hasura.StreamingSubscriptionSpec qualified as StreamingSubSpec
|
2021-09-24 01:56:37 +03:00
|
|
|
import Network.HTTP.Client qualified as HTTP
|
|
|
|
import Network.HTTP.Client.TLS qualified as HTTP
|
|
|
|
import Network.HTTP.Client.TransformableSpec qualified as TransformableSpec
|
|
|
|
import Options.Applicative
|
|
|
|
import System.Environment (getEnvironment)
|
|
|
|
import System.Exit (exitFailure)
|
|
|
|
import Test.Hspec
|
|
|
|
import Test.Hspec.Runner qualified as Hspec
|
2019-11-18 21:45:54 +03:00
|
|
|
|
|
|
|
data TestSuites
|
2021-09-09 10:59:04 +03:00
|
|
|
= -- | Run all test suites. It probably doesn't make sense to be able to specify additional
|
|
|
|
-- hspec args here.
|
2021-12-06 18:46:52 +03:00
|
|
|
AllSuites
|
2021-09-09 10:59:04 +03:00
|
|
|
| -- | Args to pass through to hspec (as if from 'getArgs'), and the specific suite to run.
|
|
|
|
SingleSuite ![String] !TestSuite
|
2019-11-18 21:45:54 +03:00
|
|
|
|
|
|
|
data TestSuite
|
|
|
|
= UnitSuite
|
2021-12-06 18:46:52 +03:00
|
|
|
| PostgresSuite
|
|
|
|
| MSSQLSuite
|
2019-10-21 19:01:05 +03:00
|
|
|
|
2019-12-14 09:47:38 +03:00
|
|
|
main :: IO ()
|
2022-04-07 17:41:43 +03:00
|
|
|
main = do
|
2021-10-13 19:38:56 +03:00
|
|
|
parseArgs >>= \case
|
2021-12-06 18:46:52 +03:00
|
|
|
AllSuites -> do
|
2022-04-07 17:41:43 +03:00
|
|
|
streamingSubSpec <- StreamingSubSpec.buildStreamingSubscriptionsSpec
|
2021-12-06 18:46:52 +03:00
|
|
|
postgresSpecs <- buildPostgresSpecs
|
|
|
|
mssqlSpecs <- buildMSSQLSpecs
|
2022-04-07 17:41:43 +03:00
|
|
|
runHspec [] (unitSpecs *> postgresSpecs *> mssqlSpecs *> streamingSubSpec)
|
|
|
|
SingleSuite hspecArgs suite -> do
|
2021-10-13 19:38:56 +03:00
|
|
|
runHspec hspecArgs =<< case suite of
|
|
|
|
UnitSuite -> pure unitSpecs
|
2021-12-06 18:46:52 +03:00
|
|
|
PostgresSuite -> buildPostgresSpecs
|
|
|
|
MSSQLSuite -> buildMSSQLSpecs
|
2019-11-18 21:45:54 +03:00
|
|
|
|
|
|
|
unitSpecs :: Spec
|
|
|
|
unitSpecs = do
|
2022-03-09 05:26:38 +03:00
|
|
|
describe "Control.Concurrent.ExtendedSpec" ConcurrentExtended.spec
|
2022-02-03 19:13:50 +03:00
|
|
|
describe "Data.HashMap.Strict.ExtendedSpec" HashMapExtendedSpec.spec
|
2022-04-05 21:14:25 +03:00
|
|
|
describe "Data.NonNegativeInt" NonNegativeIntSpec.spec
|
2020-01-14 00:56:51 +03:00
|
|
|
describe "Data.Parser.CacheControl" CacheControlParser.spec
|
2020-08-31 19:40:01 +03:00
|
|
|
describe "Data.Parser.JSONPath" JsonPath.spec
|
2022-04-05 21:14:25 +03:00
|
|
|
describe "Data.Parser.URLTemplate" URLTemplate.spec
|
2022-04-22 14:33:36 +03:00
|
|
|
describe "Data.Parser.RemoteRelationshipSpec" RemoteRelationship.spec
|
2020-01-16 04:56:57 +03:00
|
|
|
describe "Data.Time" TimeSpec.spec
|
2022-03-01 19:03:23 +03:00
|
|
|
describe "Data.Trie" TrieSpec.spec
|
2022-04-06 00:06:11 +03:00
|
|
|
describe "Hasura.App" AppSpec.spec
|
2022-05-02 08:03:12 +03:00
|
|
|
describe "Hasura.Backends.DataConnector.API.V0" DataConnector.API.V0Spec.spec
|
2022-02-07 17:11:49 +03:00
|
|
|
describe "Hasura.Backends.MSSQL.ErrorSpec" MSSQLErrorSpec.spec
|
2022-03-10 06:05:53 +03:00
|
|
|
describe "Hasura.Backends.MySQL.DataLoader.ExecuteTests" MySQLDataLoader.spec
|
2022-06-17 13:43:17 +03:00
|
|
|
describe "Hasura.Backends.Postgres.SQL.Select.IdentifierUniqueness" IdentifierUniqueness.spec
|
2021-05-20 13:03:02 +03:00
|
|
|
describe "Hasura.Eventing" EventingSpec.spec
|
2022-03-10 06:05:53 +03:00
|
|
|
describe "Hasura.GraphQL.Namespace" NamespaceSpec.spec
|
2021-05-20 13:03:02 +03:00
|
|
|
describe "Hasura.GraphQL.Parser.Directives" GraphQLDirectivesSpec.spec
|
2022-06-28 13:06:55 +03:00
|
|
|
describe "Hasura.GraphQL.Parser.Monad" MonadParseSpec.spec
|
2021-05-24 23:12:53 +03:00
|
|
|
describe "Hasura.GraphQL.Schema.Remote" GraphRemoteSchemaSpec.spec
|
2022-05-26 17:05:13 +03:00
|
|
|
describe "Hasura.GraphQL.Schema.Build.UpdateSpec" UpdateSpec.spec
|
2021-05-20 13:03:02 +03:00
|
|
|
describe "Hasura.Incremental" IncrementalSpec.spec
|
2022-06-27 19:32:25 +03:00
|
|
|
describe "Hasura.Metadata.DTO.Metadata" MetadataDTOSpec.spec
|
2022-03-10 06:05:53 +03:00
|
|
|
describe "Hasura.RQL.IR.SelectSpec" SelectSpec.spec
|
|
|
|
describe "Hasura.RQL.MetadataSpec" MetadataSpec.spec
|
|
|
|
describe "Hasura.RQL.PermissionSpec" PermSpec.spec
|
2022-02-08 19:53:30 +03:00
|
|
|
describe "Hasura.RQL.Types.Allowlist" AllowlistSpec.spec
|
2022-03-10 06:05:53 +03:00
|
|
|
describe "Hasura.RQL.Types.Common" CommonTypesSpec.spec
|
2021-01-29 04:02:34 +03:00
|
|
|
describe "Hasura.RQL.Types.Endpoint" EndpointSpec.spec
|
2022-02-28 10:49:13 +03:00
|
|
|
describe "Hasura.RQL.Types.Table" TableSpec.spec
|
2022-03-10 06:05:53 +03:00
|
|
|
describe "Hasura.RQL.WebhookTransformsSpec" WebhookTransformsSpec.spec
|
2021-03-26 19:59:16 +03:00
|
|
|
describe "Hasura.SQL.WKT" WKTSpec.spec
|
2022-04-05 21:14:25 +03:00
|
|
|
describe "Hasura.Session" SessionSpec.spec
|
2021-05-20 13:03:02 +03:00
|
|
|
describe "Hasura.Server.Auth" AuthSpec.spec
|
2022-03-10 06:05:53 +03:00
|
|
|
describe "Hasura.Server.Auth.JWT" JWTSpec.spec
|
2021-05-20 13:03:02 +03:00
|
|
|
describe "Hasura.Server.Telemetry" TelemetrySpec.spec
|
2021-09-16 14:03:01 +03:00
|
|
|
describe "Network.HTTP.Client.TransformableSpec" TransformableSpec.spec
|
2019-11-18 21:45:54 +03:00
|
|
|
|
2021-12-06 18:46:52 +03:00
|
|
|
buildMSSQLSpecs :: IO Spec
|
|
|
|
buildMSSQLSpecs = do
|
2021-09-09 10:59:04 +03:00
|
|
|
env <- liftIO getEnvironment
|
2021-12-06 18:46:52 +03:00
|
|
|
connStr <- flip onLeft printErrExit $
|
2021-09-09 10:59:04 +03:00
|
|
|
runWithEnv env $ do
|
|
|
|
let envVar = fst mssqlConnectionString
|
2021-12-06 18:46:52 +03:00
|
|
|
maybeV <- considerEnv envVar
|
2021-09-09 10:59:04 +03:00
|
|
|
onNothing maybeV $
|
|
|
|
throwError $
|
|
|
|
"Expected: " <> envVar
|
|
|
|
pure $ describe "Database.MSSQL.TransactionSpec" $ TransactionSpec.spec connStr
|
|
|
|
|
|
|
|
mssqlConnectionString :: (String, String)
|
|
|
|
mssqlConnectionString =
|
|
|
|
( "HASURA_MSSQL_CONN_STR",
|
2021-12-06 18:46:52 +03:00
|
|
|
"SQL Server database connection string. Example DRIVER={ODBC Driver 17 for SQL Server};SERVER=localhost,1433;Uid=user;Pwd=pass;"
|
2021-09-09 10:59:04 +03:00
|
|
|
)
|
|
|
|
|
2021-12-06 18:46:52 +03:00
|
|
|
buildPostgresSpecs :: IO Spec
|
|
|
|
buildPostgresSpecs = do
|
2019-11-18 21:45:54 +03:00
|
|
|
env <- getEnvironment
|
2020-12-28 15:56:00 +03:00
|
|
|
let envMap = Env.mkEnvironment env
|
|
|
|
|
2021-12-06 18:46:52 +03:00
|
|
|
pgUrlText <- flip onLeft printErrExit $
|
2021-09-24 01:56:37 +03:00
|
|
|
runWithEnv env $ do
|
|
|
|
let envVar = fst databaseUrlEnv
|
2021-12-06 18:46:52 +03:00
|
|
|
maybeV <- considerEnv envVar
|
2021-09-24 01:56:37 +03:00
|
|
|
onNothing maybeV $
|
2021-12-06 18:46:52 +03:00
|
|
|
throwError $ "Expected: " <> envVar
|
2019-11-18 21:45:54 +03:00
|
|
|
|
2020-12-28 15:56:00 +03:00
|
|
|
let pgConnInfo = Q.ConnInfo 1 $ Q.CDDatabaseURI $ txtToBs pgUrlText
|
2021-12-06 18:46:52 +03:00
|
|
|
urlConf = UrlValue $ InputWebhook $ mkPlainURLTemplate pgUrlText
|
2021-04-28 19:49:23 +03:00
|
|
|
sourceConnInfo =
|
2021-05-21 04:49:50 +03:00
|
|
|
PostgresSourceConnInfo urlConf (Just setPostgresPoolSettings) True Q.ReadCommitted Nothing
|
2021-02-14 09:07:52 +03:00
|
|
|
sourceConfig = PostgresConnConfiguration sourceConnInfo Nothing
|
2019-11-18 21:45:54 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
pgPool <- Q.initPGPool pgConnInfo Q.defaultConnParams {Q.cpConns = 1} print
|
2020-12-28 15:56:00 +03:00
|
|
|
let pgContext = mkPGExecCtx Q.Serializable pgPool
|
|
|
|
|
2021-11-09 17:21:48 +03:00
|
|
|
logger :: Logger Hasura = Logger $ \l -> do
|
|
|
|
let (logLevel, logType :: EngineLogType Hasura, logDetail) = toEngineLog l
|
|
|
|
t <- liftIO $ getFormattedTime Nothing
|
|
|
|
liftIO $ putStrLn $ LBS.toString $ A.encode $ EngineLog t logLevel logType logDetail
|
|
|
|
|
2020-12-28 15:56:00 +03:00
|
|
|
setupCacheRef = do
|
2019-11-20 21:21:30 +03:00
|
|
|
httpManager <- HTTP.newManager HTTP.tlsManagerSettings
|
2022-02-23 23:17:58 +03:00
|
|
|
let sqlGenCtx = SQLGenCtx LeaveNumbersAlone False False
|
2021-02-18 19:46:14 +03:00
|
|
|
maintenanceMode = MaintenanceModeDisabled
|
2021-12-08 09:26:46 +03:00
|
|
|
readOnlyMode = ReadOnlyModeDisabled
|
2021-02-18 19:46:14 +03:00
|
|
|
serverConfigCtx =
|
2022-04-07 17:41:43 +03:00
|
|
|
ServerConfigCtx
|
|
|
|
FunctionPermissionsInferred
|
|
|
|
RemoteSchemaPermsDisabled
|
|
|
|
sqlGenCtx
|
|
|
|
maintenanceMode
|
|
|
|
mempty
|
|
|
|
EventingEnabled
|
|
|
|
readOnlyMode
|
2022-06-14 12:17:18 +03:00
|
|
|
Nothing -- We are not testing the naming convention here, so defaulting to hasura-default
|
2022-01-04 14:53:50 +03:00
|
|
|
cacheBuildParams = CacheBuildParams httpManager (mkPgSourceResolver print) mkMSSQLSourceResolver serverConfigCtx
|
2021-05-26 19:19:26 +03:00
|
|
|
pgLogger = print
|
2019-11-20 21:21:30 +03:00
|
|
|
|
2021-05-26 19:19:26 +03:00
|
|
|
run :: MetadataStorageT (PGMetadataStorageAppT CacheBuild) a -> IO a
|
2020-12-28 15:56:00 +03:00
|
|
|
run =
|
2021-05-26 19:19:26 +03:00
|
|
|
runMetadataStorageT
|
2021-09-24 01:56:37 +03:00
|
|
|
>>> flip runPGMetadataStorageAppT (pgPool, pgLogger)
|
|
|
|
>>> runCacheBuild cacheBuildParams
|
|
|
|
>>> runExceptT
|
|
|
|
>=> flip onLeft printErrJExit
|
|
|
|
>=> flip onLeft printErrJExit
|
2019-11-20 21:21:30 +03:00
|
|
|
|
2020-12-28 15:56:00 +03:00
|
|
|
(metadata, schemaCache) <- run do
|
2021-09-24 01:56:37 +03:00
|
|
|
metadata <-
|
|
|
|
snd
|
|
|
|
<$> (liftEitherM . runExceptT . runTx pgContext Q.ReadWrite)
|
|
|
|
(migrateCatalog (Just sourceConfig) maintenanceMode =<< liftIO getCurrentTime)
|
2021-11-09 17:21:48 +03:00
|
|
|
schemaCache <- lift $ lift $ buildRebuildableSchemaCache logger envMap metadata
|
2020-12-28 15:56:00 +03:00
|
|
|
pure (metadata, schemaCache)
|
|
|
|
|
2019-11-20 21:21:30 +03:00
|
|
|
cacheRef <- newMVar schemaCache
|
2020-12-28 15:56:00 +03:00
|
|
|
pure $ NT (run . flip MigrateSpec.runCacheRefT cacheRef . fmap fst . runMetadataT metadata)
|
2019-11-20 21:21:30 +03:00
|
|
|
|
2022-04-07 17:41:43 +03:00
|
|
|
streamingSubSpec <- StreamingSubSpec.buildStreamingSubscriptionsSpec
|
|
|
|
|
|
|
|
pure $ do
|
|
|
|
describe "Migrate spec" $
|
|
|
|
beforeAll setupCacheRef $
|
|
|
|
describe "Hasura.Server.Migrate" $ MigrateSpec.spec sourceConfig pgContext pgConnInfo
|
|
|
|
describe "Streaming subscription spec" $ streamingSubSpec
|
2019-11-18 21:45:54 +03:00
|
|
|
|
|
|
|
parseArgs :: IO TestSuites
|
2021-09-24 01:56:37 +03:00
|
|
|
parseArgs =
|
|
|
|
execParser $
|
|
|
|
info (helper <*> (parseNoCommand <|> parseSubCommand)) $
|
|
|
|
fullDesc <> header "Hasura GraphQL Engine test suite"
|
2019-10-21 19:01:05 +03:00
|
|
|
where
|
2021-12-06 18:46:52 +03:00
|
|
|
parseNoCommand = pure AllSuites
|
2020-02-13 20:38:23 +03:00
|
|
|
parseSubCommand = SingleSuite <$> parseHspecPassThroughArgs <*> subCmd
|
|
|
|
where
|
2021-09-09 10:59:04 +03:00
|
|
|
subCmd =
|
|
|
|
subparser $
|
|
|
|
mconcat
|
|
|
|
[ command "unit" $
|
|
|
|
info (pure UnitSuite) $
|
|
|
|
progDesc "Only run unit tests",
|
|
|
|
command "postgres" $
|
2021-12-06 18:46:52 +03:00
|
|
|
info (pure PostgresSuite) $
|
2021-09-09 10:59:04 +03:00
|
|
|
progDesc "Only run Postgres integration tests",
|
|
|
|
command "mssql" $
|
2021-12-06 18:46:52 +03:00
|
|
|
info (pure MSSQLSuite) $
|
2021-09-09 10:59:04 +03:00
|
|
|
progDesc "Only run SQL Server unit tests"
|
|
|
|
]
|
2020-01-21 21:12:27 +03:00
|
|
|
-- Add additional arguments and tweak as needed:
|
|
|
|
hspecArgs = ["match", "skip"]
|
|
|
|
-- parse to a list of arguments as they'd appear from 'getArgs':
|
|
|
|
parseHspecPassThroughArgs :: Parser [String]
|
2021-09-24 01:56:37 +03:00
|
|
|
parseHspecPassThroughArgs = fmap concat $
|
|
|
|
for hspecArgs $ \nm ->
|
|
|
|
fmap (maybe [] (\a -> ["--" <> nm, a])) $
|
|
|
|
optional $
|
|
|
|
strOption
|
|
|
|
( long nm
|
|
|
|
<> metavar "<PATTERN>"
|
|
|
|
<> help "Flag passed through to hspec (see hspec docs)."
|
|
|
|
)
|
2020-01-21 21:12:27 +03:00
|
|
|
|
|
|
|
runHspec :: [String] -> Spec -> IO ()
|
|
|
|
runHspec hspecArgs m = do
|
|
|
|
config <- Hspec.readConfig Hspec.defaultConfig hspecArgs
|
2019-11-18 21:45:54 +03:00
|
|
|
Hspec.evaluateSummary =<< Hspec.runSpec m config
|
|
|
|
|
|
|
|
printErrExit :: String -> IO a
|
|
|
|
printErrExit = (*> exitFailure) . putStrLn
|
2019-11-20 21:21:30 +03:00
|
|
|
|
|
|
|
printErrJExit :: (A.ToJSON a) => a -> IO b
|
|
|
|
printErrJExit = (*> exitFailure) . BL.putStrLn . A.encode
|