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) = ...@@ -66,9 +66,15 @@ phyloGolden (fp, actualOutput) =
, failFirstTime = True , 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 -- | Use this variant for those tests which requires a more sophisticated way of
-- comparing outputs directly on the GraphData -- comparing outputs directly on the GraphData
phyloGoldenGraphData :: (FilePath, GraphData) -> Golden GraphData phyloGoldenGraphData :: (FilePath, GraphDataFuzzy) -> Golden GraphDataFuzzy
phyloGoldenGraphData (goldenPath, new) = phyloGoldenGraphData (goldenPath, new) =
Golden { Golden {
output = new output = new
...@@ -80,16 +86,14 @@ phyloGoldenGraphData (goldenPath, new) = ...@@ -80,16 +86,14 @@ phyloGoldenGraphData (goldenPath, new) =
, failFirstTime = True , failFirstTime = True
} }
where where
differ :: GraphData -> String differ :: GraphDataFuzzy -> String
differ ref = case compareGraphDataFuzzy ref new of differ (GraphDataFuzzy ref) = show (ansiWlEditExprCompact $ ediff ref (_GraphDataFuzzy new))
True -> mempty
False -> show (ansiWlEditExprCompact $ ediff ref new)
updateGolden :: GraphData -> IO () updateGolden :: GraphDataFuzzy -> IO ()
updateGolden gd = BL.writeFile goldenPath (JSON.encodePretty gd) updateGolden (GraphDataFuzzy gd) = BL.writeFile goldenPath (JSON.encodePretty gd)
getGolden :: IO GraphData getGolden :: IO GraphDataFuzzy
getGolden = do getGolden = GraphDataFuzzy <$> do
expected_e <- JSON.eitherDecodeFileStrict' =<< getDataFileName goldenPath expected_e <- JSON.eitherDecodeFileStrict' =<< getDataFileName goldenPath
case expected_e of case expected_e of
Left err -> fail err Left err -> fail err
...@@ -155,12 +159,12 @@ testSmallPhyloWithoutLinkExpectedOutput = do ...@@ -155,12 +159,12 @@ testSmallPhyloWithoutLinkExpectedOutput = do
expected <- setConfig phyloTestConfig <$> (readPhylo =<< getDataFileName "test-data/phylo/small-phylo.golden.json") expected <- setConfig phyloTestConfig <$> (readPhylo =<< getDataFileName "test-data/phylo/small-phylo.golden.json")
assertBool (show $ ansiWlEditExprCompact $ ediff expected actual) (expected == actual) assertBool (show $ ansiWlEditExprCompact $ ediff expected actual) (expected == actual)
testPhylo2dot2json :: IO (FilePath, GraphData) testPhylo2dot2json :: IO (FilePath, GraphDataFuzzy)
testPhylo2dot2json = do testPhylo2dot2json = do
actual_e <- JSON.parseEither JSON.parseJSON <$> phylo2dot2json Cleopatre.phyloCleopatre actual_e <- JSON.parseEither JSON.parseJSON <$> phylo2dot2json Cleopatre.phyloCleopatre
case actual_e of case actual_e of
Left err -> fail err 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 :: GraphData -> GraphData -> Bool
compareGraphDataFuzzy gd1 gd2 = 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