Documentation
¶
Overview ¶
Package test contains the code to parse and execute Gno tests and filetests.
Index ¶
- Constants
- func Context(caller crypto.Bech32Address, pkgPath string, send std.Coins) *teststd.TestExecContext
- func LoadImports(store gno.Store, mpkg *std.MemPackage, abortOnError bool) (err error)
- func Machine(testStore gno.Store, output io.Writer, pkgPath string, debug bool) *gno.Machine
- func OutputWithError(output, errWriter io.Writer) io.Writer
- func ProdStore(rootDir string, output io.Writer) (baseStore storetypes.CommitStore, gnoStore gno.Store)
- func StoreWithOptions(rootDir string, output io.Writer, opts StoreOptions) (baseStore storetypes.CommitStore, gnoStore gno.Store)
- func Test(mpkg *std.MemPackage, fsDir string, opts *TestOptions) error
- func TestStore(rootDir string, output io.Writer) (baseStore storetypes.CommitStore, gnoStore gno.Store)
- type Directive
- type Directives
- type StoreOptions
- type TestImportError
- 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" DirectiveTypeCheckError = "TypeCheckError" )
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.DerivePkgBech32Addr("user1.gno"), // used as the default caller in [Context]. DefaultCaller crypto.Bech32Address = "g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" )
Variables ¶
This section is empty.
Functions ¶
func Context ¶
func Context(caller crypto.Bech32Address, pkgPath string, send std.Coins) *teststd.TestExecContext
Context returns a TestExecContext. Usable for test purpose only. The caller should be empty for package initialization. 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 MemPackage 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 Machine ¶
Machine is a minimal machine, set up with just the Store, Output and Context. It is only used for linting/preprocessing.
func OutputWithError ¶
OutputWithError returns an io.Writer that can be used as a gno.Machine.Output, where the test standard libraries will write to errWriter when using os.Stderr.
func ProdStore ¶
func ProdStore( rootDir string, output io.Writer, ) ( baseStore storetypes.CommitStore, gnoStore gno.Store, )
This store without options supports stdlibs without test/stdlibs overrides. It is used for type-checking gno files without any test files. NOTE: It's called "Prod*" because it's suitable for type-checking non-test (production) files of a mem package, but it shouldn't be used for production systems.
func StoreWithOptions ¶
func StoreWithOptions( rootDir string, output io.Writer, opts StoreOptions, ) ( baseStore storetypes.CommitStore, gnoStore gno.Store, )
======================================== StoreWithOptions is a variant of [Store] which additionally accepts a StoreOptions argument.
func Test ¶
func Test(mpkg *std.MemPackage, fsDir string, opts *TestOptions) error
Test runs tests on the specified mpkg. 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. It is assumed that mpkg is already type-checked, even filetests.
func TestStore ¶
func TestStore( rootDir string, output io.Writer, ) ( baseStore storetypes.CommitStore, gnoStore gno.Store, )
This store without options supports stdlibs with test/stdlibs overrides. It is used for type-checking normal + non-xxx_test *_test.gno files, as well as xxx_test integrataion files, and filetest files.
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 StoreOptions ¶
type StoreOptions struct { // WithExamples if true includes the examples/ folder in the gno project. WithExamples bool // Testing if true includes tests/stdlibs. If false, WithExtern omitted. Testing bool // WithExtern lets imports of packages "filetests/extern/" // as imports under the directory in "gnovm/tests/files/extern". // This should only be used for GnoVM internal filetests (gnovm/tests/files). WithExtern bool // PreprocessOnly instructs the PackageGetter to run the imported files using // [gno.Machine.PreprocessFiles]. It avoids executing code for contexts // which only intend to perform a type check, ie. `gno lint`. PreprocessOnly bool // When transpiling code in examples/ we use the test store. gno fix may need // gno.mod to not be auto-generated when importing from the test store. DoNotGenerateGnoMod bool // When fixing code from an earler gno version. Not supported for stdlibs. FixFrom string }
type TestImportError ¶
type TestImportError struct {
PkgPath string
}
XXX use it; this isn't used yet.
func (TestImportError) Error ¶
func (err TestImportError) Error() string
func (TestImportError) String ¶
func (err TestImportError) String() string
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 // Debug enables the interactive debugger on gno tests. Debug bool // Flag to filter tests to run. RunFlag string // Flag to stop executing as soon a test fails. FailfastFlag bool // 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 ¶
func NewTestOptions(rootDir string, stdout, stderr io.Writer) *TestOptions
NewTestOptions sets up TestOptions, filling out all "required" parameters.
func (*TestOptions) RunFiletest ¶
RunFiletest executes a gnovm internal filetest in test/files. 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. Before the filetest is run it will be type-checked.
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.