Skip to content

Commit

Permalink
Pact cli now reports failures and exits on repl test failure
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcardon committed Feb 13, 2025
1 parent ab4ffa3 commit 97e3e67
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion pact-repl/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import Pact.Core.Command.Crypto
import Pact.Core.Command.Server
import Pact.Core.Command.Util
import Pact.Core.Repl.Compile
import Pact.Core.Environment
import Pact.Core.Pretty
import System.IO
import qualified Pact.Core.Version as PI
import System.Directory
Expand Down Expand Up @@ -129,7 +131,13 @@ main = O.execParser argParser >>= \case
(Left pe, state) -> do
let renderedError = renderLocatedPactErrorFromState state pe
exitFailureWithMessage ((T.unpack renderedError) <> "\nLoad failed")
(Right _, _) -> exitSuccessWithMessage "Load successful"
(Right _, state) -> do
let testResults = filter (\rs -> _trResult rs /= ReplTestPassed) $ reverse (_replTestResults state)
case testResults of
[] -> exitSuccessWithMessage "Load successful"
(vsep . fmap pretty -> results) -> do
T.putStrLn $ renderCompactText' results
exitFailureWithMessage "Load failed"
printVersion = putStrLn ("pact version " <> showVersion PI.version)
printBuiltins = traverse_ (\bi -> T.putStrLn $ "\"" <> bi <> "\"") replCoreBuiltinNames

Expand Down
8 changes: 8 additions & 0 deletions pact/Pact/Core/Environment/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,21 @@ data ReplTestStatus
| ReplTestFailed Text
deriving (Show, Eq)

instance Pretty ReplTestStatus where
pretty ReplTestPassed = "Test passed"
pretty (ReplTestFailed failureMsg) = pretty failureMsg

data ReplTestResult
= ReplTestResult
{ _trName :: Text
, _trLoc :: FileLocSpanInfo
, _trResult :: ReplTestStatus
} deriving (Show, Eq)

instance Pretty ReplTestResult where
pretty (ReplTestResult _name loc res) =
pretty loc <> ":" <> pretty res

data ReplOutput where
ReplStdOut :: ReplOutput
ReplLogOut :: IORef [(Text, FileLocSpanInfo)] -> ReplOutput
Expand Down
2 changes: 1 addition & 1 deletion pact/Pact/Core/Info.hs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ instance HasSpanInfo FileLocSpanInfo where
spanInfo = lens _flsiSpan (\s i -> s { _flsiSpan = i })

instance Pretty FileLocSpanInfo where
pretty (FileLocSpanInfo f s) = pretty f <> " " <> pretty s
pretty (FileLocSpanInfo f s) = pretty f <> ":" <> pretty s

instance Default FileLocSpanInfo where
def = FileLocSpanInfo "" def

0 comments on commit 97e3e67

Please sign in to comment.