<commit_before>module Main where

import Spec
import System.Exit
import System.Environment
import System.Process
import Control.Exception
import Data.List
import Data.Maybe
import Data.Functor

clients :: [(String, String)]
clients = [
 ("rtorrent","rtorrent -p 51234-51234 res/testfile.torrent") ]

main :: IO ()
main = do
  args <- getArgs
  let cmd' = do
        cl <- listToMaybe $ reverse
                   $ map (tail . dropWhile (/='='))
                   $ filter (isPrefixOf "--bittorrent-client=") args
        cmd <- (++) "screen -dm -S bittorrent-testsuite " <$> lookup cl clients
        return cmd
  case cmd' of
    Just cmd -> do _ <- system "screen -S bittorrent-testsuite -X quit"
                   createProcess (shell cmd) >> return ()
    Nothing -> return ()

  let args' = (filter (not . isPrefixOf "--bittorrent-client=") args)
  code <- catch (withArgs args' hspecMain >> return ExitSuccess) return

  _ <- system "screen -S bittorrent-testsuite -X quit"
  exitWith code >> return ()
<commit_msg>Run bittorrent-client in res/ so it can seed the testfile<commit_after>module Main where

import Spec
import System.Exit
import System.Environment
import System.Process
import System.Directory
import Control.Exception
import Data.List
import Data.Maybe
import Data.Functor

clients :: [(String, String)]
clients = [
 ("rtorrent","rtorrent -p 51234-51234 testfile.torrent") ]

main :: IO ()
main = do
  args <- getArgs
  let cmd' = do
        cl <- listToMaybe $ reverse
                   $ map (tail . dropWhile (/='='))
                   $ filter (isPrefixOf "--bittorrent-client=") args
        cmd <- (++) "screen -dm -S bittorrent-testsuite " <$> lookup cl clients
        return cmd
  case cmd' of
    Just cmd -> do _ <- system "screen -S bittorrent-testsuite -X quit"
                   dir <- getCurrentDirectory
                   _ <- createProcess (shell cmd) { cwd = Just (dir ++ "/res") }
                   return ()
    Nothing -> return ()

  let args' = (filter (not . isPrefixOf "--bittorrent-client=") args)
  code <- catch (withArgs args' hspecMain >> return ExitSuccess) return

  _ <- system "screen -S bittorrent-testsuite -X quit"
  exitWith code >> return ()

{'fraction_non_alphanumeric': 0.12217194570135746, 'fraction_numerical': 0.00904977375565611, 'mean_word_length': 2.548956661316212, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '1622312', 'n_tokens_mistral': 696, 'n_tokens_neox': 649, 'n_words': 213}