Skip to content

Commit

Permalink
Make --accept write the file if it doesn't exist (#4743)
Browse files Browse the repository at this point in the history
This makes it work like --accept in tasty-golden, which is what we
want.
  • Loading branch information
michaelpj committed Jun 29, 2022
1 parent 3b8edd2 commit 892bd2a
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions plutus-conformance/src/PlutusConformance/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,25 @@ instance IsOption AcceptTests where
-- | Checks an expected file against actual computed contents.
checkExpected :: AcceptTests -> FilePath -> T.Text -> IO Result
checkExpected (AcceptTests accept) expectedFile actual = do
expected <- T.readFile expectedFile
if actual == expected
-- matched
then pure (testPassed "")
else
-- didn't match
if accept
expectedExists <- doesFileExist expectedFile
if expectedExists
then do
expected <- T.readFile expectedFile
if actual == expected
-- matched
then pure (testPassed "")
else
-- didn't match
if accept
then do
T.writeFile expectedFile actual
pure $ testPassed "Unexpected output, accepted it"
else pure $ testFailed $ "Unexpected output:" ++ show actual
else if accept
then do
T.writeFile expectedFile actual
pure $ testPassed "Unexpected output, accepted it"
else pure $ testFailed $ "Unexpected output:" ++ show actual
pure $ testPassed "Expected file did not exist, created it"
else pure $ testFailed $ "Expected file did not exist:" ++ show expectedFile

-- Tells 'tasty' that 'UplcEvaluationTest' "is" a test that can be run,
-- by specifying how to run it and what custom options it might expect.
Expand Down

0 comments on commit 892bd2a

Please sign in to comment.