{"modulePath":"github.com/ethereum-optimism/optimism","version":"v1.21.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package devtest\n\n## Constants\n\n```go\nconst ExpectPreconditionsMet = \"DEVNET_EXPECT_PRECONDITIONS_MET\"\n```\n\n```go\nconst FailFlakyTests = \"DEVNET_FAIL_FLAKY_TESTS\"\n```\n\n## Variables\n\n```go\nvar DefaultTestLogLevel = log.LevelInfo\n```\nDefaultTestLogLevel is set to info level to show relevant logs without being overly verbose unless configured otherwise.\n\n```go\nvar (\n\t// RootContext is the context that is used for the root of the test suite.\n\t// It should be set for good before any tests are run.\n\tRootContext = context.Background()\n)\n```\n\n## Functions\n\n```go\nfunc AddTestScope(ctx context.Context, scope string) context.Context\n```\nAddTestScope combines the sub-scope with the test-scope of the context, and returns a context with the updated scope value.\n\n```go\nfunc RunParallel[V any](t T, elems []V, fn func(t T, v V))\n```\nRunParallel runs the test-function, for each of the given elements, in parallel. This awaits the result of all sub-tests to complete, by grouping everything into a regular sub-test.\n\n```go\nfunc TestScope(ctx context.Context) string\n```\nTestScope retrieves the test-scope from the context\n\n## Types\n\n```go\ntype CommonT interface {\n\tError(args ...any)\n\tErrorf(format string, args ...any)\n\tFail()\n\tFailNow()\n\tSkipNow()\n\n\tTempDir() string\n\tTempDirWithPrefix(prefix string) string\n\tCleanup(fn func())\n\tLog(args ...any)\n\tLogf(format string, args ...any)\n\tHelper()\n\tName() string\n\n\tLogger() log.Logger\n\tTracer() trace.Tracer\n\tCtx() context.Context\n\tRequire() *testreq.Assertions\n}\n```\nCommonT is a subset of testing.T, extended with a few common utils. This interface should not be used directly. Instead, use T in test-scope, or P when operating at package level.\n\nThis CommonT interface is minimal enough such that it can be implemented by tooling, and a \\*testing.T can be used with minimal wrapping.\n\n```go\ntype P interface {\n\tCommonT\n\n\t// WithCtx makes a copy of P with a specific context.\n\t// The ctx must match the test-scope of the existing context.\n\t// This function is used to create a P with annotated context, e.g. a specific resource.\n\tWithCtx(ctx context.Context) P\n\n\t// TempDir creates a temporary directory, and returns the file-path.\n\t// This directory is cleaned up at the end of the package,\n\t// and can be shared safely between tests that run in that package scope.\n\tTempDir() string\n\n\t// Cleanup runs the given function at the end of the package-scope.\n\t// This function will clean-up once the package-level testing is fully complete.\n\t// These resources can thus be shared safely between tests.\n\tCleanup(fn func())\n\n\t// Close closes the testing handle. This cancels the context and runs all cleanup.\n\tClose()\n\t// contains filtered or unexported methods\n}\n```\nP is used by the preset package and system backends as testing interface, to host package-wide resources.\n\n```go\nfunc NewP(ctx context.Context, logger log.Logger, onFail func(now bool), onSkipNow func()) P\n```\n\n```go\ntype T interface {\n\tCommonT\n\n\t// TempDir creates a temporary directory, and returns the file-path.\n\t// This directory is cleaned up at the end of the test, and must not be shared between tests.\n\tTempDir() string\n\n\t// Cleanup runs the given function at the end of the test-scope,\n\t// or at the end of the sub-test (if this is a nested test).\n\t// This function will clean-up before the package-level testing scope may be complete.\n\t// Do not use the test-scope cleanup with shared resources.\n\tCleanup(fn func())\n\n\t// Run runs the given function in as a sub-test.\n\tRun(name string, fn func(T))\n\n\t// Ctx returns a context that will be canceled at the end of this (sub) test-scope,\n\t// and inherits the context of the parent-test-scope.\n\tCtx() context.Context\n\n\t// WithCtx makes a copy of T with a specific context.\n\t// The ctx must match the test-scope of the existing context.\n\t// This function is used to create a T with annotated context, e.g. a specific resource, rather than a sub-scope.\n\tWithCtx(ctx context.Context) T\n\n\t// Parallel signals that this test is to be run in parallel with (and only with) other parallel tests.\n\tParallel()\n\n\t// Skip is equivalent to Log followed by SkipNow.\n\tSkip(args ...any)\n\t// Skipped reports whether the test was skipped.\n\tSkipped() bool\n\t// Skipf is equivalent to Logf followed by SkipNow.\n\tSkipf(format string, args ...any)\n\t// SkipNow marks the test as skipped and stops test execution.\n\t// It is remapped to FailNow if the env var DEVNET_EXPECT_PRECONDITIONS_MET is set to true.\n\tSkipNow()\n\n\t// Gate provides everything that Require does, but skips instead of fails the test upon error.\n\tGate() *testreq.Assertions\n\n\t// MarkFlaky downgrades future test failures to skips unless DEVNET_FAIL_FLAKY_TESTS is set.\n\t// Call this near the top of the test, before storing any Require()-derived helper.\n\tMarkFlaky(reason string)\n\n\t// Deadline reports the time at which the test binary will have\n\t// exceeded the timeout specified by the -timeout flag.\n\t//\n\t// The ok result is false if the -timeout flag indicates \"no timeout\" (0).\n\tDeadline() (deadline time.Time, ok bool)\n\n\t// This distinguishes the interface from other testing interfaces,\n\t// such as the one used at package-level for shared system construction.\n\tTestOnly()\n}\n```\n\n```go\nfunc ParallelT(t *testing.T) T\n```\nParallelT creates a T interface with parallel testing enabled by default\n\n```go\nfunc SerialT(t *testing.T) T\n```\nSerialT wraps around a test-logger and turns it into a T for devstack testing.\n\n","path":"github.com/ethereum-optimism/optimism/op-devstack/devtest","name":"devtest","synopsis":"","isRedistributable":true}
