func TestBinaryExpression(t *testing.T) {
	expr := parse("assert.Ok(t, foo == bar)")
	v := instrumentor.NewVisitor()
	ast.Walk(v, expr)
	result, _ := instrumentor.ToCode(expr)
	streq(t, result, "assert.PowerOk(t, assert.Capt(foo, \"foo\") == assert.Capt(bar, \"bar\"), \"assert.Ok(t, foo == bar)\")", "output")
}
func TestSingleIdent(t *testing.T) {
	expr := parse("assert.Ok(t, val)")
	v := instrumentor.NewVisitor()
	//	ast.Print(token.NewFileSet(), expr)
	ast.Walk(v, expr)
	result, _ := instrumentor.ToCode(expr)
	streq(t, result, "assert.PowerOk(t, assert.Capt(val, \"val\"), \"assert.Ok(t, val)\")", "output")
}
Exemple #3
0
// How to generate powered test code:
// $ GOPATH=`pwd` go run src/twada/gopwr/gopwr.go < src/twada/exam/bt_test.go
func main() {
	in := os.Stdin
	out := os.Stdout

	src, err := ioutil.ReadAll(in)
	if err != nil {
		os.Exit(2)
	}

	fset := token.NewFileSet()
	f, err := parser.ParseFile(fset, "", src, 0)
	if err != nil {
		os.Exit(2)
	}

	v := instrumentor.NewVisitor()
	ast.Walk(v, f)
	res, _ := instrumentor.ToCode(f)

	io.WriteString(out, res)
}
func TestAstSpike(t *testing.T) {
	src := `package p

import (
	"testing"
	"power/assert"
)

func TestTargetMethod(t *testing.T) {
	hoge := "foo"
	fuga := "bar"
	assert.Ok(t, hoge == fuga)
}
`
	fset := token.NewFileSet()
	f, err := parser.ParseFile(fset, "", src, 0)
	if err != nil {
		panic(err)
	}
	// ast.Print(fset, f)

	v := instrumentor.NewVisitor()
	ast.Walk(v, f)

	expected := `package p

import (
	"testing"
	"power/assert"
)

func TestTargetMethod(t *testing.T) {
	hoge := "foo"
	fuga := "bar"
	assert.PowerOk(t, assert.Capt(hoge, "hoge") == assert.Capt(fuga, "fuga"), "assert.Ok(t, hoge == fuga)")
}
`
	result, _ := instrumentor.ToCode(f)
	streq(t, result, expected, "output")
}