<commit_before>{-# LANGUAGE ScopedTypeVariables #-}
module Main where


import Control.Concurrent (threadDelay)
import Control.Exception (catch)
import System.Exit (ExitCode)
import Test.Tasty (defaultMain, testGroup, TestTree)
import Test.Tasty.HUnit
import System.Process

import TestOutParser (tests)
import TestFW.TestGCMCheck (tests)

main :: IO ()
main = do
    -- Setup
    server <- spawnProcess "stack" ["exec", "RestAPI", "--", "--lib", "/Users/alex/Repositories/research/graceful/GRACe/libraries"]
    threadDelay 3000000  -- wait a second for the server to get started

    -- Test
    defaultMain (testGroup "Test all"
      [ TestOutParser.tests
      , TestFW.TestGCMCheck.tests
      , serviceTests
      ]) `catch` \(e :: ExitCode) -> return ()

    -- Teardown
    terminateProcess server

serviceTests = testGroup "Unit tests" 
  [ testService "library/crud" [] "test/test_library.exp"
  , testService "submit/crud"  [ "-H", "Content-Type: application/json"
                               ,  "--data", "@example.json"] "test/test_submit.exp"
  ]

testService :: String -> [String] -> FilePath -> TestTree
testService endpoint options file = testCase ("Testing: " ++ file) $ do
    out <- readProcess "curl" (options ++ ["-s", url]) "" 
    exp <- readFile file
    out @?= exp<commit_msg>No need for absolute path to libs in tests.<commit_after>{-# LANGUAGE ScopedTypeVariables #-}
module Main where


import Control.Concurrent (threadDelay)
import Control.Exception (catch)
import System.Exit (ExitCode)
import Test.Tasty (defaultMain, testGroup, TestTree)
import Test.Tasty.HUnit
import System.Process

import TestOutParser (tests)
import TestFW.TestGCMCheck (tests)

main :: IO ()
main = do
    -- Setup
    server <- spawnProcess "stack" ["exec", "RestAPI", "--", "--lib", "libraries"]
    threadDelay 3000000  -- wait a second for the server to get started

    -- Test
    defaultMain (testGroup "Test all"
      [ TestOutParser.tests
      , TestFW.TestGCMCheck.tests
      , serviceTests
      ]) `catch` \(e :: ExitCode) -> return ()

    -- Teardown
    terminateProcess server

serviceTests = testGroup "Unit tests" 
  [ testService "library/crud" [] "test/test_library.exp"
  , testService "submit/crud"  [ "-H", "Content-Type: application/json"
                               ,  "--data", "@example.json"] "test/test_submit.exp"
  ]

testService :: String -> [String] -> FilePath -> TestTree
testService endpoint options file = testCase ("Testing: " ++ file) $ do
    out <- readProcess "curl" (options ++ ["-s", url]) "" 
    exp <- readFile file
    out @?= exp
{'fraction_non_alphanumeric': 0.13641618497109825, 'fraction_numerical': 0.005394990366088632, 'mean_word_length': 3.1669341894060996, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7510688', 'n_tokens_mistral': 814, 'n_tokens_neox': 779, 'n_words': 221}