-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enforce UTF-8 encoding on reading and writing files #75
Conversation
@@ -170,7 +174,9 @@ openFile filePath mode = GHC.withFrozenCallStack $ do | |||
readFile :: (MonadTest m, MonadIO m, HasCallStack) => FilePath -> m String | |||
readFile filePath = GHC.withFrozenCallStack $ do | |||
void . H.annotate $ "Reading file: " <> filePath | |||
H.evalIO $ IO.readFile filePath | |||
liftIO $ IO.withFile filePath IO.ReadMode $ \handle -> do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
evalIO
is needed for proper reporting of IO exceptions
liftIO $ IO.withFile filePath IO.ReadMode $ \handle -> do | |
H.evalIO $ IO.withFile filePath IO.ReadMode $ \handle -> do |
Why this change is only in those two places ? I think we should use utf8 in all functions using string / text when accessing files:
appendFile
, textWriteFile
, textReadFile
, fileContains
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are right. However, it makes sense to accept this PR as an improvement to the library and do the other fixes in a future PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do the other fixes in a future PR
Fine but let's do them before making a new release... And the version of hedgehog-extras with this change was tagged already. Can we try to limit technical debt we're introducing?
Or at least put an effort into making technical debt manageable and traceable by creating follow-up tickets/prs?
We were experiencing testing failures on Windows due to GHC 8.10.7's readFile not using UTF-8 by default. This caused golden file comparison errors when Unicode characters were present. For example: