apple-0.1.0.0: of/Test.hs
{-# LANGUAGE OverloadedStrings #-}
module Main (main) where
import Data.Functor (void)
import qualified Data.Text as T
import H
import System.Directory (getCurrentDirectory, setCurrentDirectory)
import System.FilePath ((</>))
import System.Info (arch)
import System.IO.Temp (withSystemTempDirectory)
import System.Process (proc, readCreateProcess)
import Test.Tasty (DependencyType (AllFinish), TestTree, defaultMain, sequentialTestGroup)
import Test.Tasty.HUnit (testCase, (@?=))
readCc :: FilePath
-> FilePath -- ^ Apple source file
-> T.Text
-> Arch
-> IO String
readCc pwd aSrc tyt a =
withSystemTempDirectory "apple" $ \dir -> do
setCurrentDirectory dir
let n=T.unpack tyt
run (pwd </> aSrc, a, tyt)
let c = pwd </> "test/harness" </> n <> "_harness.c"
{-# SCC "cc" #-} void $ readCreateProcess (proc "cc" [n <> ".o", c, "-I", dir, "-I", pwd </> "include"]) ""
{-# SCC "a.out" #-} readCreateProcess (proc (dir </> "a.out") []) ""
ccOut :: FilePath -> FilePath -> T.Text -> Arch -> String -> TestTree
ccOut pwd fp tyt a expected = testCase (T.unpack tyt) $ do
actual <- readCc pwd fp tyt a
actual @?= expected
main :: IO ()
main = do
pwd <- getCurrentDirectory
defaultMain $
sequentialTestGroup "link object files" AllFinish
[ ccOut pwd "test/examples/shoelace.π" "aaf" sys "6.000000"
, ccOut pwd "test/data/predictionStep.π" "aafa" sys "1 4\n0.716413,0.721679,0.727807,0.731693\n"
, ccOut pwd "test/data/map.π" "aaa" sys "2 2,2\n1.000000,2.000000,2.000000,2.000000\n"
, ccOut pwd "test/data/maa.π" "aa" sys "1 2\n1.000000,3.000000\n"
, ccOut pwd "test/data/bha.π" "bha" sys "1 2\n0.792800,0.663306\n"
, ccOut pwd "test/data/mfa.π" "a" sys "2 4,2\n1.000000,1.000000,3.000000,3.000000,2.000000,2.000000,5.000000,5.000000\n"
, ccOut pwd "test/data/cfLeft.π" "af" sys "4.123106\n"
, ccOut pwd "test/data/sin.π" "ff" sys "-1.000000\n"
, ccOut pwd "test/data/conv.π" "conv" sys "2 3,3\n9.000000,9.000000,9.000000,9.000000,9.000000,9.000000,9.000000,9.000000,9.000000\n"
, ccOut pwd "math/hypergeometric.π" "hyper" sys "2.030078"
]
where
sys = case arch of {"x86_64" -> X64; "aarch64" -> Aarch64}