File tree Expand file tree Collapse file tree
src/Cardano/Wasm/Internal/Api
test/cardano-wasm-golden/Test/Golden/Cardano/Wasm Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,7 +2,24 @@ module Main where
22
33import Cardano.Wasm.Internal.Api.Info (apiInfo )
44import Cardano.Wasm.Internal.Api.InfoToTypeScript (apiInfoToTypeScriptFile )
5- import Cardano.Wasm.Internal.Api.TypeScriptDefs (printTypeScriptFile )
5+ import Cardano.Wasm.Internal.Api.TypeScriptDefs (writeTypeScriptToDir )
6+
7+ import Options.Applicative
8+
9+ newtype CmdArgs
10+ = CmdArgs { outputDir :: String }
11+
12+ parser :: Parser CmdArgs
13+ parser =
14+ CmdArgs
15+ <$> strOption
16+ ( long " output-dir"
17+ <> short ' o'
18+ <> metavar " OUTPUT_DIR"
19+ <> help " Output directory for the TypeScript declaration files (it must exist)"
20+ )
621
722main :: IO ()
8- main = printTypeScriptFile (apiInfoToTypeScriptFile apiInfo)
23+ main = do
24+ cmdArgs <- execParser (info (parser <**> helper) fullDesc)
25+ writeTypeScriptToDir (outputDir cmdArgs) (apiInfoToTypeScriptFile apiInfo)
Original file line number Diff line number Diff line change @@ -63,7 +63,9 @@ executable cardano-wasm
6363 cardano-strict-containers,
6464 containers,
6565 exceptions,
66+ filepath,
6667 microlens,
68+ optparse-applicative,
6769 text,
6870
6971 if arch(wasm32)
@@ -80,10 +82,13 @@ test-suite cardano-wasm-golden
8082 if !arch(wasm32)
8183 import : project-config
8284 build-depends :
85+ filepath,
8386 hedgehog >= 1.1 ,
8487 hedgehog-extras ^>= 0.8 ,
88+ monad-control,
8589 tasty,
8690 tasty-hedgehog,
91+ temporary,
8792
8893 ghc-options :
8994 -threaded
Original file line number Diff line number Diff line change @@ -207,4 +207,3 @@ declare interface CardanoApi {
207207 */
208208 restoreTestnetPaymentWalletFromSigningKeyBech32 ( networkMagic : number , signingKeyBech32 : string ) : Promise < Wallet > ;
209209}
210-
Original file line number Diff line number Diff line change @@ -16,12 +16,15 @@ module Cardano.Wasm.Internal.Api.TypeScriptDefs where
1616import Data.List.NonEmpty qualified as LNE
1717import Data.Text.Lazy qualified as TL
1818import Data.Text.Lazy.Builder qualified as TLB
19+ import Data.Text.Lazy.IO qualified as TL
20+ import System.FilePath ((</>) )
1921
20- -- | Prints the TypeScript declaration file to stdout .
21- printTypeScriptFile :: TypeScriptFile -> IO ()
22- printTypeScriptFile tsFile = do
22+ -- | Output the TypeScript declaration files to the specified directory .
23+ writeTypeScriptToDir :: FilePath -> TypeScriptFile -> IO ()
24+ writeTypeScriptToDir dir tsFile = do
2325 let content = buildTypeScriptFile tsFile
24- putStrLn $ TL. unpack $ TLB. toLazyText content
26+ filePath = dir </> typeScriptFileName tsFile
27+ TL. writeFile filePath (TLB. toLazyText content)
2528
2629-- | Creates a builder for a JavaScript-style multiline comment
2730-- with the specified indentation level (in spaces) and each line
Original file line number Diff line number Diff line change 11module Test.Golden.Cardano.Wasm.TypeScript where
22
3+ import Control.Monad (forM_ )
4+ import Control.Monad.IO.Class qualified as H
5+ import Control.Monad.Trans.Control (control )
6+ import System.FilePath ((</>) )
7+ import System.IO.Temp (withSystemTempDirectory )
8+
39import Hedgehog as H
410import Hedgehog.Extras qualified as H
511
612hprop_cardano_wasm_typescript_declarations_match_generated :: Property
713hprop_cardano_wasm_typescript_declarations_match_generated =
814 H. propertyOnce $ do
9- result <- H. execFlex " cardano-wasm" " CARDANO_WASM" []
10- H. diffVsGoldenFile result " lib-wrapper/cardano-api.d.ts"
15+ control $ \ runInHedgehog ->
16+ H. liftIO $ withSystemTempDirectory " cardano-wasm-ts-decls" $ \ dir -> do
17+ runInHedgehog $ do
18+ _ <- H. execFlex " cardano-wasm" " CARDANO_WASM" [" --output-dir" , dir]
19+ forFilesInDir dir $ \ file -> do
20+ H. annotate (dir </> file)
21+ H. diffFileVsGoldenFile (dir </> file) (" lib-wrapper" </> file)
22+
23+ forFilesInDir :: (H. MonadTest m , H. MonadIO m ) => FilePath -> (FilePath -> m () ) -> m ()
24+ forFilesInDir dir action = do
25+ files <- H. listDirectory dir
26+ forM_ files $ \ file -> do
27+ let fullPath = dir </> file
28+ H. assertFileExists fullPath
29+ action file
You can’t perform that action at this time.
0 commit comments