I have this test:
testReadFile = runTestTT $ TestLabel "InteractionDomain.readFileContentsToList" (TestList [
(TestLabel "testing infrastructure: read test file" (TestList [
TestCase (withTempFileContainingText (\fileHandle ->
assertEqual "contents as expected" "The dog barks at midnight." (do
content <- hGetContents fileHandle
return content)))]))])
and (in case it helps) withTempFileContainingText
is this function
withTempFileContainingText lambda =
bracketOnError
(do (path, fileHandle) <- openTempFile "." "input.txt"
return fileHandle)
(deleteFile)
(\fileHandle -> do
hPutStr fileHandle "The dog barks at midnight."
hClose fileHandle --hoping this flushes buffers
return (lambda fileHandle))
ghc
complains that
InteractionDomain.hs:36:4: Couldn't match expected type `IO String' against inferred type `[String]' In a stmt of a 'do' expression: content ≤- hGetContents fileHandle
Which I don't understand. Why is there the inference that content
is a list of String? And what should this code look like?