Commit 53f1acdc authored by Alfredo Di Napoli's avatar Alfredo Di Napoli

Amend Phylo golden test machinery

parent 282f63c0
Pipeline #7710 passed with stages
in 51 minutes and 41 seconds
......@@ -66,9 +66,15 @@ phyloGolden (fp, actualOutput) =
, failFirstTime = True
}
newtype GraphDataFuzzy =
GraphDataFuzzy { _GraphDataFuzzy :: GraphData }
instance Eq GraphDataFuzzy where
(GraphDataFuzzy a) == (GraphDataFuzzy b) = a `compareGraphDataFuzzy` b
-- | Use this variant for those tests which requires a more sophisticated way of
-- comparing outputs directly on the GraphData
phyloGoldenGraphData :: (FilePath, GraphData) -> Golden GraphData
phyloGoldenGraphData :: (FilePath, GraphDataFuzzy) -> Golden GraphDataFuzzy
phyloGoldenGraphData (goldenPath, new) =
Golden {
output = new
......@@ -80,16 +86,14 @@ phyloGoldenGraphData (goldenPath, new) =
, failFirstTime = True
}
where
differ :: GraphData -> String
differ ref = case compareGraphDataFuzzy ref new of
True -> mempty
False -> show (ansiWlEditExprCompact $ ediff ref new)
differ :: GraphDataFuzzy -> String
differ (GraphDataFuzzy ref) = show (ansiWlEditExprCompact $ ediff ref (_GraphDataFuzzy new))
updateGolden :: GraphData -> IO ()
updateGolden gd = BL.writeFile goldenPath (JSON.encodePretty gd)
updateGolden :: GraphDataFuzzy -> IO ()
updateGolden (GraphDataFuzzy gd) = BL.writeFile goldenPath (JSON.encodePretty gd)
getGolden :: IO GraphData
getGolden = do
getGolden :: IO GraphDataFuzzy
getGolden = GraphDataFuzzy <$> do
expected_e <- JSON.eitherDecodeFileStrict' =<< getDataFileName goldenPath
case expected_e of
Left err -> fail err
......@@ -155,12 +159,12 @@ testSmallPhyloWithoutLinkExpectedOutput = do
expected <- setConfig phyloTestConfig <$> (readPhylo =<< getDataFileName "test-data/phylo/small-phylo.golden.json")
assertBool (show $ ansiWlEditExprCompact $ ediff expected actual) (expected == actual)
testPhylo2dot2json :: IO (FilePath, GraphData)
testPhylo2dot2json :: IO (FilePath, GraphDataFuzzy)
testPhylo2dot2json = do
actual_e <- JSON.parseEither JSON.parseJSON <$> phylo2dot2json Cleopatre.phyloCleopatre
case actual_e of
Left err -> fail err
Right (actual :: GraphData) -> pure ("test-data/phylo/phylo2dot2json.golden.json", actual)
Right (actual :: GraphData) -> pure ("test-data/phylo/phylo2dot2json.golden.json", GraphDataFuzzy actual)
compareGraphDataFuzzy :: GraphData -> GraphData -> Bool
compareGraphDataFuzzy gd1 gd2 =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment