Documentation ¶
Overview ¶
Package test contains the code to parse and execute Gno tests and filetests.
Index ¶
- Constants
- func Context(pkgPath string, send std.Coins) *teststd.TestExecContext
- func LoadImports(store gno.Store, filename string, content []byte) (err error)
- func Machine(testStore gno.Store, output io.Writer, pkgPath string) *gno.Machine
- func Store(rootDir string, withExtern bool, stdin io.Reader, stdout, stderr io.Writer) (baseStore storetypes.CommitStore, resStore gno.Store)
- func Test(memPkg *gnovm.MemPackage, fsDir string, opts *TestOptions) error
- type Directive
- type Directives
- type TestOptions
Constants ¶
const ( // These directives are used to set input variables, which should change for // the specific filetest. They must be specified on a single line. DirectivePkgPath = "PKGPATH" DirectiveMaxAlloc = "MAXALLOC" DirectiveSend = "SEND" // These are used to match the result of the filetest against known golden // values. DirectiveOutput = "Output" DirectiveError = "Error" DirectiveRealm = "Realm" DirectiveEvents = "Events" DirectivePreprocessed = "Preprocessed" DirectiveStacktrace = "Stacktrace" )
const ( // DefaultHeight is the default height used in the [Context]. DefaultHeight = 123 // DefaultTimestamp is the Timestamp value used by default in [Context]. DefaultTimestamp = 1234567890 // DefaultCaller is the result of gno.DerivePkgAddr("user1.gno"), // used as the default caller in [Context]. DefaultCaller crypto.Bech32Address = "g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" )
Variables ¶
This section is empty.
Functions ¶
func Context ¶
func Context(pkgPath string, send std.Coins) *teststd.TestExecContext
Context returns a TestExecContext. Usable for test purpose only. The returned context has a mock banker, params and event logger. It will give the pkgAddr the coins in `send` by default, and only that. The Height and Timestamp parameters are set to the DefaultHeight and DefaultTimestamp.
func LoadImports ¶
LoadImports parses the given file and attempts to retrieve all pure packages from the store. This is mostly useful for "eager import loading", whereby all imports are pre-loaded in a permanent store, so that the tests can use ephemeral transaction stores.
func Store ¶
func Store( rootDir string, withExtern bool, stdin io.Reader, stdout, stderr io.Writer, ) ( baseStore storetypes.CommitStore, resStore gno.Store, )
NOTE: this isn't safe, should only be used for testing.
func Test ¶
func Test(memPkg *gnovm.MemPackage, fsDir string, opts *TestOptions) error
Test runs tests on the specified memPkg. fsDir is the directory on filesystem of package; it's used in case opts.Sync is enabled, and points to the directory where the files are contained if they are to be updated. opts is a required set of options, which is often shared among different tests; you can use NewTestOptions for a common base configuration.
Types ¶
type Directive ¶
Directive represents a directive in a filetest. A Directives slice may also contain directives with empty Names: these compose the source file itself, and are used to re-construct the file when a directive is changed.
type Directives ¶
type Directives []Directive
Directives contains the directives of a file. It may also contains directives with empty names, to indicate parts of the original source file (used to re-construct the filetest at the end).
func ParseDirectives ¶
func ParseDirectives(source io.Reader) (Directives, error)
ParseDirectives parses all the directives in the filetest given at source.
func (Directives) FileTest ¶
func (d Directives) FileTest() string
FileTest re-generates the filetest from the given directives; the inverse of ParseDirectives.
func (Directives) First ¶
func (d Directives) First(name string) *Directive
First returns the first directive with the corresponding name.
func (Directives) FirstDefault ¶
func (d Directives) FirstDefault(name, defaultValue string) string
FirstDefault returns the [Directive.Content] of First(name); if First(name) returns nil, then defaultValue is returned.
type TestOptions ¶
type TestOptions struct { // BaseStore / TestStore to use for the tests. BaseStore storetypes.CommitStore TestStore gno.Store // Gno root dir. RootDir string // Used for printing program output, during verbose logging. Output io.Writer // Used for os.Stderr, and for printing errors. Error io.Writer // Flag to filter tests to run. RunFlag string // Whether to update filetest directives. Sync bool // Uses Error to print when starting a test, and prints test output directly, // unbuffered. Verbose bool // Uses Error to print runtime metrics for tests. Metrics bool // Uses Error to print the events emitted. Events bool // contains filtered or unexported fields }
TestOptions is a list of options that must be passed to Test.
func NewTestOptions ¶
NewTestOptions sets up TestOptions, filling out all "required" parameters.
func (*TestOptions) RunFiletest ¶
func (opts *TestOptions) RunFiletest(filename string, source []byte) (string, error)
RunFiletest executes the program in source as a filetest. If opts.Sync is enabled, and the filetest's golden output has changed, the first string is set to the new generated content of the file.
func (*TestOptions) WriterForStore ¶
func (opts *TestOptions) WriterForStore() io.Writer
WriterForStore is the writer that should be passed to Store, so that Test is then able to swap it when needed.