{-# LANGUAGE AllowAmbiguousTypes #-} -- For Golden {-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE ImportQualifiedPost #-} {-# LANGUAGE PartialTypeSignatures #-} -- For Golden {-# LANGUAGE RankNTypes #-} {-# OPTIONS_GHC -Wno-orphans #-} module Goldens where import Control.Monad.Trans.Reader as MT import Relude import System.FilePath qualified as Sys import System.IO.Unsafe (unsafePerformIO) import Test.Tasty import Test.Tasty.Golden import Text.Printf (printf) import Examples.Ex01 qualified as Ex01 import Examples.Ex02 qualified as Ex02 import Examples.Ex03 qualified as Ex03 import Examples.Ex04 qualified as Ex04 import Examples.Ex05 qualified as Ex05 import Literate.Web import Paths_literate_web import Utils test :: TestTree test = testGroup "Goldens" [ testGroup "Compiler" [ testGroup (printf "Site%03d" siteNum) [ withResource (goldenCompiler CompilerEnv{..}) (\_ -> return ()) $ \compilerIO -> testGroup (printf "Model%02d" modelNum) [ goldenVsFileDiff (printf "/%s" destPath) goldenDiff (getGoldenDir (printf "Compiler/Site%03d/Model%02d/Expected/%s" siteNum modelNum destPath)) (compilerEnvDest Sys. destPath) compilerIO | destPath <- goldenManifest ] | (modelNum, Golden{..}) <- ol goldenModels , let compilerEnvDest = getGoldenDir (printf "Compiler/Site%03d/Model%02d/Got/" siteNum modelNum) , let compilerEnvIndex :: FilePath = "index.html" -- , let compilerEnvSource = getGoldenDir (printf "Compiler/Site%03d/Model%02d/Source/" siteNum modelNum) ] | (siteNum, goldenModels) <- ol goldens ] ] getGoldenDir :: FilePath -> FilePath getGoldenDir p = unsafePerformIO $ getDataFileName $ "tests/Goldens/" <> p goldenDiff :: FilePath -> FilePath -> [String] goldenDiff ref new = ["diff", "-u", "-w", "-B", ref, new] data Golden = Golden { goldenCompiler :: CompilerEnv -> IO () , goldenManifest :: [Sys.FilePath] } goldens :: [[Golden]] goldens = {- [ Golden @() index [()] , Golden @() ("foo" index) [()] , Golden @(Either () ()) ("root" ("foo" index <+> "bar" index)) [()] , Golden @(Either () (), Either () ()) ( "root" ("a" literalSlug "b" <+> "c" literalSlug "d") <.> ("A" literalSlug "B" <+> "C" literalSlug "D") <. index ) [()] -} [ [ Golden { goldenCompiler = \env -> compile env Ex01.router Ex01.content , goldenManifest = runIdentity $ manifest Ex01.router } ] , [ Golden { goldenCompiler = \env -> compile env Ex02.router Ex02.content , goldenManifest = runIdentity $ manifest Ex02.router } ] , [ Golden { goldenCompiler = \env -> MT.runReaderT (compile env Ex03.router Ex03.content) model , goldenManifest = runReader (manifest Ex03.router) model } | model <- [Ex03.model1, Ex03.model2] ] , [ Golden { goldenCompiler = \env -> MT.runReaderT (compile env Ex04.router Ex04.content) model , goldenManifest = runReader (manifest Ex04.router) model } | model <- [Ex04.model1] ] , [ Golden { goldenCompiler = \env -> MT.runReaderT (MT.runReaderT (compile env Ex05.router Ex05.content) model03) model04 , goldenManifest = MT.runReader (MT.runReaderT (manifest Ex05.router) model03) model04 } | model03 <- [Ex03.model1, Ex03.model2] , model04 <- [Ex04.model1] ] ]