add golden tests
This commit is contained in:
parent
e9053be78f
commit
18b3801c99
6 changed files with 305 additions and 1 deletions
44
agora-test/Golden.hs
Normal file
44
agora-test/Golden.hs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
module Golden (testGolden) where
|
||||
|
||||
import Agora.Bootstrap qualified as Bootstrap
|
||||
import Agora.Linker (linker)
|
||||
import Data.ByteString.Lazy qualified as LBS
|
||||
import Data.Text qualified as Text
|
||||
import Plutarch (Config (Config), TracingMode (DoTracing, NoTracing))
|
||||
import ScriptExport.File qualified as ScriptExport
|
||||
import ScriptExport.Options qualified as ScriptExport
|
||||
import ScriptExport.Types qualified as ScriptExport
|
||||
import System.Directory (createDirectoryIfMissing)
|
||||
import Test.Tasty (TestTree, testGroup)
|
||||
import Test.Tasty.Golden (goldenVsString)
|
||||
import Test.Tasty.Providers (TestName)
|
||||
|
||||
builders :: ScriptExport.Builders
|
||||
builders =
|
||||
mconcat
|
||||
[ ScriptExport.insertScriptExportWithLinker "agora" (Bootstrap.agoraScripts (Config NoTracing)) linker
|
||||
, ScriptExport.insertScriptExportWithLinker "agoraDebug" (Bootstrap.agoraScripts (Config DoTracing)) linker
|
||||
]
|
||||
|
||||
testGolden :: TestTree
|
||||
testGolden =
|
||||
testGroup
|
||||
"Golden tests for script export"
|
||||
[ goldenTest "agora" "./agora-test/goldens/"
|
||||
, goldenTest "agoraDebug" "./agora-test/goldens/"
|
||||
]
|
||||
|
||||
goldenTest :: TestName -> FilePath -> TestTree
|
||||
goldenTest builder outputPath =
|
||||
goldenVsString
|
||||
builder
|
||||
(outputPath <> builder <> "-golden.json")
|
||||
(callExportScript builder outputPath)
|
||||
|
||||
-- Call the script server and generate an unapplied script set.
|
||||
callExportScript :: String -> FilePath -> IO LBS.ByteString
|
||||
callExportScript builder outputPath = do
|
||||
_ <- createDirectoryIfMissing False outputPath
|
||||
let sampleFilePath = outputPath <> builder <> ".json"
|
||||
ScriptExport.runFile builders (ScriptExport.FileOptions {out = outputPath, param = "", builder = Text.pack builder})
|
||||
LBS.readFile sampleFilePath
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
import GHC.IO.Encoding (setLocaleEncoding, utf8)
|
||||
import Golden qualified
|
||||
import Test.Tasty (defaultMain, testGroup)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
|
@ -22,7 +23,8 @@ main = do
|
|||
defaultMain $
|
||||
testGroup
|
||||
"test suite"
|
||||
[ testGroup
|
||||
[ Golden.testGolden
|
||||
, testGroup
|
||||
"Effects"
|
||||
[ toTestTree $ group "Treasury Withdrawal Effect" TreasuryWithdrawal.specs
|
||||
, toTestTree $ group "Governor Mutation Effect" GovernorMutation.specs
|
||||
|
|
|
|||
125
agora-test/goldens/agora-golden.json
Normal file
125
agora-test/goldens/agora-golden.json
Normal file
File diff suppressed because one or more lines are too long
125
agora-test/goldens/agoraDebug-golden.json
Normal file
125
agora-test/goldens/agoraDebug-golden.json
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue