@@ -52,12 +52,14 @@ import Text.Read (readMaybe)
52
52
53
53
import Booster.JsonRpc (rpcJsonConfig )
54
54
import Booster.JsonRpc.Utils (
55
+ DiffResult (DifferentType ),
55
56
KoreRpcJson (RpcRequest ),
56
57
decodeKoreRpc ,
57
58
diffJson ,
58
59
isIdentical ,
59
60
methodOfRpcCall ,
60
61
renderResult ,
62
+ rpcTypeOf ,
61
63
)
62
64
import Booster.Prettyprinter (renderDefault )
63
65
import Booster.Syntax.Json qualified as Syntax
@@ -85,8 +87,8 @@ handleRunOptions common@CommonOptions{dryRun} s = \case
85
87
[] -> case s of
86
88
Just sock -> shutdown sock ShutdownReceive
87
89
Nothing -> pure ()
88
- (RunTarball tarFile keepGoing runOnly : xs) -> do
89
- runTarball common s tarFile keepGoing runOnly
90
+ (RunTarball tarFile keepGoing runOnly noDetails : xs) -> do
91
+ runTarball common s tarFile keepGoing runOnly ( not noDetails)
90
92
handleRunOptions common s xs
91
93
(RunSingle mode optionFile options processingOptions : xs) -> do
92
94
let ProcessingOptions {postProcessing, prettify, time} = processingOptions
@@ -246,7 +248,8 @@ data RunOptions
246
248
RunTarball
247
249
FilePath -- tar file
248
250
Bool -- do not stop on first diff if set to true
249
- [Kore.JsonRpc.Types. APIMethod ] -- only run specified types of requests. run all if empty
251
+ [Kore.JsonRpc.Types. APIMethod ] -- only run specified types of requests. Run all if empty.
252
+ Bool -- omit detailed comparison with expected output
250
253
deriving stock (Show )
251
254
252
255
data ProcessingOptions = ProcessingOptions
@@ -448,6 +451,10 @@ parseMode =
448
451
( long " run-only"
449
452
<> help " Only run the specified request(s), e.g. --run-only \" add-module implies\" "
450
453
)
454
+ <*> switch
455
+ ( long " omit-details"
456
+ <> help " only compare response types, not contents"
457
+ )
451
458
<**> helper
452
459
)
453
460
(progDesc " Run all requests and compare responses from a bug report tarball" )
@@ -479,9 +486,15 @@ parseMode =
479
486
-- Running all requests contained in the `rpc_*` directory of a tarball
480
487
481
488
runTarball ::
482
- CommonOptions -> Maybe Socket -> FilePath -> Bool -> [Kore.JsonRpc.Types. APIMethod ] -> IO ()
483
- runTarball _ Nothing _ _ _ = pure ()
484
- runTarball common (Just sock) tarFile keepGoing runOnly = do
489
+ CommonOptions ->
490
+ Maybe Socket ->
491
+ FilePath ->
492
+ Bool ->
493
+ [Kore.JsonRpc.Types. APIMethod ] ->
494
+ Bool ->
495
+ IO ()
496
+ runTarball _ Nothing _ _ _ _ = pure ()
497
+ runTarball common (Just sock) tarFile keepGoing runOnly compareDetails = do
485
498
-- unpack tar files, determining type from extension(s)
486
499
let unpackTar
487
500
| " .tar" == takeExtension tarFile = Tar. read
@@ -509,6 +522,7 @@ runTarball common (Just sock) tarFile keepGoing runOnly = do
509
522
-- we should not rely on the requests being returned in a sorted order and
510
523
-- should therefore sort them explicitly
511
524
let requests = sort $ mapMaybe (stripSuffix " _request.json" ) jsonFiles
525
+ successMsg = if compareDetails then " matches expected" else " has expected type"
512
526
results <-
513
527
forM requests $ \ r -> do
514
528
mbError <- runRequest skt tmp jsonFiles r
@@ -519,7 +533,7 @@ runTarball common (Just sock) tarFile keepGoing runOnly = do
519
533
liftIO $
520
534
shutdown skt ShutdownReceive >> exitWith (ExitFailure 2 )
521
535
Nothing ->
522
- logInfo_ $ " Response to " <> r <> " matched with expected "
536
+ logInfo_ $ unwords [ " Response to" , r, successMsg]
523
537
pure mbError
524
538
liftIO $ shutdown skt ShutdownReceive
525
539
liftIO $ exitWith (if all isNothing results then ExitSuccess else ExitFailure 2 )
@@ -569,13 +583,22 @@ runTarball common (Just sock) tarFile keepGoing runOnly = do
569
583
request <- liftIO . BS. readFile $ tmpDir </> basename <> " _request.json"
570
584
expected <- liftIO . BS. readFile $ tmpDir </> basename <> " _response.json"
571
585
586
+ let showResult =
587
+ renderResult " expected response" " actual response"
572
588
makeRequest False basename (Just skt) request pure runOnly >>= \ case
573
589
Nothing -> pure Nothing -- should not be reachable
574
- Just actual -> do
575
- let diff = diffJson expected actual
576
- if isIdentical diff
577
- then pure Nothing
578
- else pure . Just $ renderResult " expected response" " actual response" diff
590
+ Just actual
591
+ | compareDetails -> do
592
+ let diff = diffJson expected actual
593
+ if isIdentical diff
594
+ then pure Nothing
595
+ else pure . Just $ showResult diff
596
+ | otherwise -> do
597
+ let expectedType = rpcTypeOf (decodeKoreRpc expected)
598
+ actualType = rpcTypeOf (decodeKoreRpc actual)
599
+ if expectedType == actualType
600
+ then pure Nothing
601
+ else pure . Just $ showResult (DifferentType expectedType actualType)
579
602
580
603
noServerError :: MonadLoggerIO m => CommonOptions -> IOException -> m ()
581
604
noServerError common e@ IOError {ioe_type = NoSuchThing } = do
0 commit comments