-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
136 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
cardano-cli/test/cardano-cli-test-lib/Test/Cardano/CLI/Polysemy.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
{-# LANGUAGE TypeOperators #-} | ||
|
||
module Test.Cardano.CLI.Polysemy | ||
( cardanoCliPath | ||
, execCardanoCli | ||
, execCardanoCli_ | ||
, localWorkspace | ||
) where | ||
|
||
import HaskellWorks.Polysemy | ||
import HaskellWorks.Polysemy.Error.Types | ||
import HaskellWorks.Polysemy.Hedgehog | ||
import HaskellWorks.Polysemy.Hedgehog.Assert | ||
import HaskellWorks.Polysemy.Hedgehog.Process | ||
import HaskellWorks.Polysemy.Prelude | ||
|
||
cardanoCliPath :: FilePath | ||
cardanoCliPath = "cardano-cli" | ||
|
||
-- | Execute cardano-cli via the command line. | ||
-- | ||
-- Waits for the process to finish and returns the stdout. | ||
execCardanoCli :: () | ||
=> HasCallStack | ||
=> Member (Embed IO) r | ||
=> Member Hedgehog r | ||
=> Member Log r | ||
=> [String] | ||
-- ^ Arguments to the CLI command | ||
-> Sem r String | ||
-- ^ Captured stdout | ||
execCardanoCli args = withFrozenCallStack $ | ||
execFlexOk "cardano-cli" "CARDANO_CLI" args | ||
& trapFail @GenericError | ||
& trapFail @IOException | ||
|
||
execCardanoCli_ :: () | ||
=> HasCallStack | ||
=> Member (Embed IO) r | ||
=> Member Hedgehog r | ||
=> Member Log r | ||
=> [String] | ||
-- ^ Arguments to the CLI command | ||
-> Sem r () | ||
execCardanoCli_ args = withFrozenCallStack $ | ||
void $ execCardanoCli args | ||
|
||
localWorkspace :: () | ||
=> Member Hedgehog r | ||
=> Member Log r | ||
=> Member (Embed IO) r | ||
=> Sem | ||
( Reader Workspace | ||
: Reader ProjectRoot | ||
: Reader PackagePath | ||
: Resource | ||
: r) | ||
() | ||
-> Sem r () | ||
localWorkspace f = do | ||
cabalProjectDir <- findCabalProjectDir "." | ||
|
||
f & moduleWorkspace "cardano-cli" | ||
& runReader (ProjectRoot cabalProjectDir) | ||
& runReader (PackagePath "cardano-cli") | ||
& runResource |