Files
moxa/example/getfunc/getfunc_test.go
Ethan Reesor 1df5dc2e93 Update Interpreter.Use API
### Background

#1102 changed how `Interpreter.Use` interprets export paths such that the last path component is stripped and used as the package name. This resulted in #1139 - attempting to Use an export with only one path component, such as `foo`, would result in the import path being `.`.

### Breaking API Change

This PR changes the signature of `Interpreter.Use` from `Use(Exports)` to `Use(Exports) error`.

### Fix for #1139

With this PR, if Use is called with an incomplete export path, such as `foo`, Use will return an error.
2021-06-24 10:00:05 +02:00

28 lines
454 B
Go

package main
import (
"fmt"
"testing"
"github.com/traefik/yaegi/interp"
"github.com/traefik/yaegi/stdlib"
)
func TestGetFunc(t *testing.T) {
i := interp.New(interp.Options{GoPath: "./_gopath/"})
if err := i.Use(stdlib.Symbols); err != nil {
t.Fatal(err)
}
if _, err := i.Eval(`import "github.com/foo/bar"`); err != nil {
t.Fatal(err)
}
val, err := i.Eval(`bar.NewFoo`)
if err != nil {
t.Fatal(err)
}
fmt.Println(val.Call(nil))
}