<commit_before>{- 

Before running this, check that /tmp/test does not exist and
contain something important. Then do:

 $ touch /tmp/test

If you do:

 $ runhaskell Test.hs

it will work. If you do:

 $ runhaskell Test.hs fail

it will fail every time with:

Test.hs: writeFile: /tmp/test: openFile: resource busy (file is locked)

-}

import Control.Monad
import System.Directory
import System.IO
import System.Environment
import System.Posix.IO

fp = "2122-test"

main :: IO ()
main = do
   writeFile fp "test"
   test True

-- fails everytime when causeFailure is True in GHCi, with runhaskell,
-- or when compiled.
test :: Bool -> IO ()
test causeFailure =
    do h1 <- openFile fp ReadMode `Prelude.catch` (\e -> error ("openFile 1: " ++ show e))
       when causeFailure $ do
         h2 <- openFile fp ReadMode `Prelude.catch` (\e -> error ("openFile 2: " ++ show e))
         hClose h2
       hClose h1
       removeFile fp
       writeFile fp (show [1..100]) `Prelude.catch` (\e -> error ("writeFile: " ++ show e))

-- this version never fails (except in GHCi, if test has previously failed).
-- probably because openFd does not try to lock the file
test2 :: Bool -> IO ()
test2 causeFailure =
    do fd1 <- openFd fp ReadOnly Nothing defaultFileFlags `Prelude.catch` (\e -> error ("openFile 1: " ++ show e))
       when causeFailure $ do
         fd2 <- openFd fp ReadOnly Nothing defaultFileFlags `Prelude.catch` (\e -> error ("openFile 2: " ++ show e))
         closeFd fd2
       closeFd fd1
       removeFile fp
       writeFile fp (show [1..100]) `Prelude.catch` (\e -> error ("writeFile: " ++ show e))

-- fails sometimes when run repeated in GHCi, but seems fine with
-- runhaskell or compiled
test3 :: IO ()
test3 =
    do h1 <- openFile fp ReadMode `Prelude.catch` (\e -> error ("openFile 1: " ++ show e))
       h2 <- openFile fp ReadMode `Prelude.catch` (\e -> error ("openFile 2: " ++ show e))
       removeFile fp
       writeFile fp (show [1..100]) `Prelude.catch` (\e -> error ("writeFile: " ++ show e))
       print =<< hGetContents h1
       print =<< hGetContents h2
       hClose h2
       hClose h1
<commit_msg>Comment out some unused code in test 2122 This was causing the test to fail on Windows, as the unused code used System.Posix.IO.<commit_after>{-

Before running this, check that /tmp/test does not exist and
contain something important. Then do:

 $ touch /tmp/test

If you do:

 $ runhaskell Test.hs

it will work. If you do:

 $ runhaskell Test.hs fail

it will fail every time with:

Test.hs: writeFile: /tmp/test: openFile: resource busy (file is locked)

-}

import Control.Monad
import System.Directory
import System.IO
import System.Environment
-- Used by test2:
-- import System.Posix.IO

fp = "2122-test"

main :: IO ()
main = do
   writeFile fp "test"
   test True

-- fails everytime when causeFailure is True in GHCi, with runhaskell,
-- or when compiled.
test :: Bool -> IO ()
test causeFailure =
    do h1 <- openFile fp ReadMode `Prelude.catch` (\e -> error ("openFile 1: " ++ show e))
       when causeFailure $ do
         h2 <- openFile fp ReadMode `Prelude.catch` (\e -> error ("openFile 2: " ++ show e))
         hClose h2
       hClose h1
       removeFile fp
       writeFile fp (show [1..100]) `Prelude.catch` (\e -> error ("writeFile: " ++ show e))

{-
-- this version never fails (except in GHCi, if test has previously failed).
-- probably because openFd does not try to lock the file
test2 :: Bool -> IO ()
test2 causeFailure =
    do fd1 <- openFd fp ReadOnly Nothing defaultFileFlags `Prelude.catch` (\e -> error ("openFile 1: " ++ show e))
       when causeFailure $ do
         fd2 <- openFd fp ReadOnly Nothing defaultFileFlags `Prelude.catch` (\e -> error ("openFile 2: " ++ show e))
         closeFd fd2
       closeFd fd1
       removeFile fp
       writeFile fp (show [1..100]) `Prelude.catch` (\e -> error ("writeFile: " ++ show e))
-}

{-
-- fails sometimes when run repeated in GHCi, but seems fine with
-- runhaskell or compiled
test3 :: IO ()
test3 =
    do h1 <- openFile fp ReadMode `Prelude.catch` (\e -> error ("openFile 1: " ++ show e))
       h2 <- openFile fp ReadMode `Prelude.catch` (\e -> error ("openFile 2: " ++ show e))
       removeFile fp
       writeFile fp (show [1..100]) `Prelude.catch` (\e -> error ("writeFile: " ++ show e))
       print =<< hGetContents h1
       print =<< hGetContents h2
       hClose h2
       hClose h1
-}


{'fraction_non_alphanumeric': 0.12161552346570396, 'fraction_numerical': 0.01917870036101083, 'mean_word_length': 2.697247706422018, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3859134', 'n_tokens_mistral': 1465, 'n_tokens_neox': 1401, 'n_words': 551}