rewriteimpl

package
v0.0.0-...-a88ca5f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Rewriter will take one or more existing Go test files on the command-line and rewrite "goconvey" tests in them to use go.chromium.org/luci/common/testing/ftt.

This makes the following changes:

  • Converts all Convey function calls to ftt.Run calls. This will also rewrite the callback from `func() {...}` to `func(t *ftt.Test) {...}`. If the test already had an explicit context variable (e.g. `func(c C)`), this will preserve that name.
  • Removes dot-imported convey.
  • Adds imports for go.chromium.org/luci/testing/common/truth/assert and go.chromium.org/luci/testing/common/truth/should.
  • Rewrites So and SoMsg calls.

Note that 'fancy' uses of Convey/So will likely be missed by this tool, and will require hand editing... however this does complete successfully for all code in luci-go, infra and infra_internal at the time of writing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseOne

func ParseOne(fname string) (*decorator.Decorator, *dst.File, error)

ParseOne just parses go code from a local file path.

Returns a File and it's matching FileSet (containing ONLY `fname`).

func Rewrite

func Rewrite(dec *decorator.Decorator, f *dst.File, adaptedAssertions stringset.Set) (newFile *ast.File, rewrote, warned bool, err error)

Rewrite rewrites a single file in `dec` to use:

assert.Loosely instead of So
ftt.Run / t.Run instead of Convey
should.X instead of ShouldX

adaptedAssertions is an input and output parameter which is state of the assertions that have been adapted with convey.Adapt(old). This is used by rewrite to only emit an FYI message for the first time each unique assertion is adapted.

Returns the new file (even if no rewrite took place). Rewrote will be true if the file was rewritten. Warned will be true if the file contained warnings (e.g. convey suites or SoMsg assertions that we couldn't translate).

Types

This section is empty.

Directories

Path Synopsis
Package test_inputs is a valid Go package which contains test files (and only test files) using a variety of testing functionality.
Package test_inputs is a valid Go package which contains test files (and only test files) using a variety of testing functionality.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL