expect-migrate

command
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

README

expect-migrate

expect-migrate is a small command line tool to upgrade your go test source files using github.com/halimath/expect-go@v0.1.0 to github.com/halimath/expect@latest. The tool rewrites go source files that in a lot of cases directly compile and run. In some cases minor work by the developer is needed.

Installation

go install github.com/halimath/expect/cmd/expect-migrate@main

Usage

Given an input file some_test.go

package some

import (
	"testing"
	. "github.com/halimath/expect-go"
)

func TestSomething(t *testing.T) {
	var err error
	s := produceValue()

	EnsureThat(t, err).Is(NoError())
	ExpectThat(t, s).Is(Equal("foo"))
}

applying

expect-migrate some_test.go

will rewrite the file to

package some

import (
	"testing"
	"github.com/halimath/expect"
	"github.com/halimath/expect/is"
)

func TestSomething(t *testing.T) {
	var err error
	s := produceValue()
	expect.That(t, expect.FailNow(is.NoError(err)))
	expect.That(t, is.EqualTo(s, "foo"))
}

Documentation

Overview

Package main contains a cli application that rewrites go source code containing test code using github.com/halimath/expect-go with a dot import and matchers from v0.1.0 to the same test code using github.com/halimath/expect v0.3.0 with regular imports. It handles most of the matchers (for some a manual work is needed), handels ExpectThat and EnsureThat but does not wrap multiple expectations into a single call to expect.That. Thus, this tool can reduce the amount of manual work needed when upgrading expect to v0.3.0 but some remainings are still needed in order to have readable, maintainable test code.

Usage:

  • either: cat source_test.go | expect1to3 > source_test.go
  • or: expect1to3 source_test.go

Jump to

Keyboard shortcuts

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