mirror of
https://github.com/hanzoai/yaegi.git
synced 2026-10-01 00:49:47 +00:00
Per the standing fork rule, a hanzoai fork declares its OWN module path and
is required directly -- never resolved via a `replace` against the upstream
path. Keeping the upstream path meant every import line in every consumer
carried the upstream brand.
module github.com/traefik/yaegi -> module github.com/hanzoai/yaegi
Mechanical and behaviour-neutral: every occurrence is an import path
(package self-imports, cmd/, _test/ fixtures interpreted at test time, and
the guthib.com/<org>/{fromage,cheese,vin} fake vendor trees under
example/pkg, whose directory components were renamed in lockstep with the
import strings that reference them).
GOPATH-mode source-import tests (interp TestFile) resolve the module by its
path under $GOPATH/src, so the required checkout location moves with the
module path -- as README already documents. Verified green at
$GOPATH/src/github.com/hanzoai/yaegi.
LICENSE is untouched: "Copyright 2020 Traefik Labs SAS" is the Apache-2.0
attribution and is a legal obligation, not a brand leak.
Also drops the inherited CONTRIBUTING.md CLA clause, which named an
upstream agreement this fork does not administer.
93 lines
1.4 KiB
Go
93 lines
1.4 KiB
Go
package interp_test
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/hanzoai/yaegi/interp"
|
|
)
|
|
|
|
// IntChan is a channel type alias for testing.
|
|
type IntChan chan int
|
|
|
|
// NewIntChan creates a new IntChan.
|
|
func NewIntChan() IntChan {
|
|
return make(IntChan, 1)
|
|
}
|
|
|
|
func TestSendToBinaryChannelTypeAlias(t *testing.T) {
|
|
i := interp.New(interp.Options{})
|
|
|
|
err := i.Use(interp.Exports{
|
|
"mypkg/mypkg": {
|
|
"IntChan": reflect.ValueOf((*IntChan)(nil)),
|
|
"NewIntChan": reflect.ValueOf(NewIntChan),
|
|
},
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
_, err = i.Eval(`
|
|
package main
|
|
|
|
import "mypkg"
|
|
|
|
func main() {
|
|
ch := mypkg.NewIntChan()
|
|
ch <- 42
|
|
val := <-ch
|
|
if val != 42 {
|
|
panic("unexpected value")
|
|
}
|
|
}
|
|
`)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestSendToSourceDefinedChannel(t *testing.T) {
|
|
i := interp.New(interp.Options{})
|
|
|
|
// Test with a channel defined purely in interpreted code
|
|
_, err := i.Eval(`
|
|
package main
|
|
|
|
func main() {
|
|
ch := make(chan int, 1)
|
|
ch <- 42
|
|
val := <-ch
|
|
if val != 42 {
|
|
panic("unexpected value")
|
|
}
|
|
}
|
|
`)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestSendToSourceDefinedChannelTypeAlias(t *testing.T) {
|
|
i := interp.New(interp.Options{})
|
|
|
|
// Test with a channel type alias defined in interpreted code
|
|
_, err := i.Eval(`
|
|
package main
|
|
|
|
type MyChan chan int
|
|
|
|
func main() {
|
|
ch := make(MyChan, 1)
|
|
ch <- 42
|
|
val := <-ch
|
|
if val != 42 {
|
|
panic("unexpected value")
|
|
}
|
|
}
|
|
`)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|