@@ -4,7 +4,7 @@ import Control.Monad (void)
44import Data.ByteString.Lazy qualified as LBS
55import System.Directory (makeAbsolute )
66import System.FilePath (takeFileName , (<.>) , (</>) )
7- import System.IO (hClose )
7+ import System.IO (hClose , Handle )
88import System.IO.Temp (withSystemTempFile )
99import System.Timeout (timeout )
1010import Test.Tasty
@@ -21,7 +21,15 @@ tests allExamples =
2121 testGroup " λ-compiler tests"
2222 [ testGroup " examples"
2323
24- [ testGroup " compile"
24+ [ testGroup " cbpv"
25+ [ anyCBPVTests allExamples
26+ ]
27+
28+ , testGroup " cbpv-opt"
29+ [ anyCBPVOptTests allExamples
30+ ]
31+
32+ , testGroup " compile"
2533 [ cCompileTests allExamples
2634 , amCompileTests allExamples
2735 ]
@@ -33,6 +41,22 @@ tests allExamples =
3341 ]
3442 ]
3543
44+ anyCBPVTests :: [FilePath ] -> TestTree
45+ anyCBPVTests allExamples =
46+ testGroup " Any backend"
47+ $ getCBPVOfExample (makeAMOptions UntilCBPV ) <$> allExamples
48+
49+ getCBPVOfExample :: (FilePath -> Options ) -> String -> TestTree
50+ getCBPVOfExample = goldenOf " cbpv" mainFuncWithOptions
51+
52+ anyCBPVOptTests :: [FilePath ] -> TestTree
53+ anyCBPVOptTests allExamples =
54+ testGroup " Any backend"
55+ $ getCBPVOptOfExample (makeAMOptions UntilCBPVOpt ) <$> allExamples
56+
57+ getCBPVOptOfExample :: (FilePath -> Options ) -> String -> TestTree
58+ getCBPVOptOfExample = goldenOf (" cbpv" <.> " opt" ) mainFuncWithOptions
59+
3660cCompileTests :: [FilePath ] -> TestTree
3761cCompileTests allExamples =
3862 testGroup " C backend"
@@ -44,16 +68,7 @@ amCompileTests allExamples =
4468 $ compileOfExample " am" (makeAMOptions UntilAM ) <$> allExamples
4569
4670compileOfExample :: String -> (FilePath -> Options ) -> String -> TestTree
47- compileOfExample tag optionBuilder s =
48- goldenVsStringDiff s gitDiff (" ." </> " test" </> " golden" </> s <.> tag <.> " compile" )
49- $ withSystemTempFile s
50- $ \ fp handle -> do
51- getExamplePath s
52- >>= void
53- . mainFuncWithOptions handle
54- . optionBuilder
55- hClose handle
56- LBS. take 10000 <$> LBS. readFile fp
71+ compileOfExample tag = goldenOf (tag <.> " compile" ) mainFuncWithOptions
5772
5873cExecutionTests :: [FilePath ] -> TestTree
5974cExecutionTests allExamples =
@@ -66,15 +81,15 @@ amExecutionTests allExamples =
6681 $ executionOfExample " am" (makeAMOptions Run ) <$> allExamples
6782
6883executionOfExample :: String -> (FilePath -> Options ) -> String -> TestTree
69- executionOfExample tag optionBuilder s =
70- goldenVsStringDiff s gitDiff (" ." </> " test" </> " golden" </> s <.> tag <.> " execution" )
84+ executionOfExample tag = goldenOf (tag <.> " execution" ) $ \ handle ->
85+ timeout 300000 . mainFuncWithOptions handle
86+
87+ goldenOf :: String -> (Handle -> Options -> IO a ) -> (FilePath -> Options ) -> String -> TestTree
88+ goldenOf tag f optionBuilder s =
89+ goldenVsStringDiff s gitDiff (" ." </> " test" </> " golden" </> s <.> tag)
7190 $ withSystemTempFile s
7291 $ \ fp handle -> do
73- getExamplePath s
74- >>= void
75- . timeout 300000
76- . mainFuncWithOptions handle
77- . optionBuilder
92+ getExamplePath s >>= void . f handle . optionBuilder
7893 hClose handle
7994 LBS. take 10000 <$> LBS. readFile fp
8095
0 commit comments