<commit_before>
module Test.Cache(main) where

import Development.Shake
import Development.Shake.FilePath
import Data.Char
import Test.Type


main = shakenCwd test $ \args obj -> do
    want $ map obj args
    vowels <- newCache $ \file -> do
        src <- readFile' file
        liftIO $ appendFile (obj "trace.txt") "1"
        return $ length $ filter isDigit src
    obj "*.out*" %> \x ->
        writeFile' x . show =<< vowels (dropExtension x <.> "txt")


test build obj = do
    writeFile (obj "trace.txt") ""
    writeFile (obj "vowels.txt") "abc123a"
    build ["vowels.out1","vowels.out2","-j3","--sleep"]
    assertContents (obj "trace.txt") "1"
    assertContents (obj "vowels.out1") "3"
    assertContents (obj "vowels.out2") "3"

    build ["vowels.out2","-j3"]
    assertContents (obj "trace.txt") "1"
    assertContents (obj "vowels.out1") "3"

    writeFile (obj "vowels.txt") "12xyz34"
    build ["vowels.out2","-j3","--sleep"]
    assertContents (obj "trace.txt") "11"
    assertContents (obj "vowels.out2") "4"<commit_msg>Switch the cache to shakeTest<commit_after>
module Test.Cache(main) where

import Development.Shake
import Development.Shake.FilePath
import Data.Char
import Test.Type


main = shakeTest_ test $ do
    let obj = id
    vowels <- newCache $ \file -> do
        src <- readFile' file
        liftIO $ appendFile (obj "trace.txt") "1"
        return $ length $ filter isDigit src
    obj "*.out*" %> \x ->
        writeFile' x . show =<< vowels (dropExtension x <.> "txt")


test build = do
    let obj = id
    writeFile (obj "trace.txt") ""
    writeFile (obj "vowels.txt") "abc123a"
    build ["vowels.out1","vowels.out2","-j3","--sleep"]
    assertContents (obj "trace.txt") "1"
    assertContents (obj "vowels.out1") "3"
    assertContents (obj "vowels.out2") "3"

    build ["vowels.out2","-j3"]
    assertContents (obj "trace.txt") "1"
    assertContents (obj "vowels.out1") "3"

    writeFile (obj "vowels.txt") "12xyz34"
    build ["vowels.out2","-j3","--sleep"]
    assertContents (obj "trace.txt") "11"
    assertContents (obj "vowels.out2") "4"
{'fraction_non_alphanumeric': 0.16125954198473283, 'fraction_numerical': 0.025763358778625955, 'mean_word_length': 3.0326923076923076, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1154889', 'n_tokens_mistral': 771, 'n_tokens_neox': 741, 'n_words': 198}