add golden tests
This commit is contained in:
parent
f08bd64565
commit
2014aae5bc
6 changed files with 305 additions and 1 deletions
|
|
@ -4,6 +4,10 @@ This format is based on [Keep A Changelog](https://keepachangelog.com/en/1.0.0).
|
||||||
|
|
||||||
## Unreleased (Candidate for 1.0.0)
|
## Unreleased (Candidate for 1.0.0)
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Golden tests for the script exports.
|
||||||
|
|
||||||
### Modified
|
### Modified
|
||||||
|
|
||||||
- For consistency and performance, the following data types are encoded as flat
|
- For consistency and performance, the following data types are encoded as flat
|
||||||
|
|
|
||||||
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 GHC.IO.Encoding (setLocaleEncoding, utf8)
|
||||||
|
import Golden qualified
|
||||||
import Test.Tasty (defaultMain, testGroup)
|
import Test.Tasty (defaultMain, testGroup)
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
@ -22,7 +23,8 @@ main = do
|
||||||
defaultMain $
|
defaultMain $
|
||||||
testGroup
|
testGroup
|
||||||
"test suite"
|
"test suite"
|
||||||
[ testGroup
|
[ Golden.testGolden
|
||||||
|
, testGroup
|
||||||
"Effects"
|
"Effects"
|
||||||
[ toTestTree $ group "Treasury Withdrawal Effect" TreasuryWithdrawal.specs
|
[ toTestTree $ group "Treasury Withdrawal Effect" TreasuryWithdrawal.specs
|
||||||
, toTestTree $ group "Governor Mutation Effect" GovernorMutation.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
|
|
@ -126,6 +126,7 @@ common test-deps
|
||||||
, agora
|
, agora
|
||||||
, cryptonite
|
, cryptonite
|
||||||
, data-default-class
|
, data-default-class
|
||||||
|
, directory
|
||||||
, memory
|
, memory
|
||||||
, mtl
|
, mtl
|
||||||
, plutarch-context-builder
|
, plutarch-context-builder
|
||||||
|
|
@ -133,6 +134,7 @@ common test-deps
|
||||||
, QuickCheck
|
, QuickCheck
|
||||||
, quickcheck-instances
|
, quickcheck-instances
|
||||||
, tasty
|
, tasty
|
||||||
|
, tasty-golden
|
||||||
, tasty-hedgehog
|
, tasty-hedgehog
|
||||||
, tasty-hunit
|
, tasty-hunit
|
||||||
, tasty-quickcheck
|
, tasty-quickcheck
|
||||||
|
|
@ -231,7 +233,9 @@ test-suite agora-test
|
||||||
type: exitcode-stdio-1.0
|
type: exitcode-stdio-1.0
|
||||||
main-is: Spec.hs
|
main-is: Spec.hs
|
||||||
hs-source-dirs: agora-test
|
hs-source-dirs: agora-test
|
||||||
|
other-modules: Golden
|
||||||
build-depends:
|
build-depends:
|
||||||
|
, agora
|
||||||
, agora-specs
|
, agora-specs
|
||||||
, agora-testlib
|
, agora-testlib
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue