|
|
@ -6,8 +6,7 @@ import (
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type env struct {
|
|
|
|
type env struct {
|
|
|
|
key string
|
|
|
|
data map[string]interface{}
|
|
|
|
value interface{}
|
|
|
|
|
|
|
|
parent *env
|
|
|
|
parent *env
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -17,7 +16,8 @@ func mkenv(test Test) *env {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// save looks at the Test t and saves the values of its fields marked with a
|
|
|
|
// save looks at the Test t and saves the values of its fields marked with a
|
|
|
|
// save tag
|
|
|
|
// save tag. All of the fields for that tests are stored together as a data
|
|
|
|
|
|
|
|
// layer.
|
|
|
|
func (e *env) save(test Test) *env {
|
|
|
|
func (e *env) save(test Test) *env {
|
|
|
|
V := reflect.ValueOf(test)
|
|
|
|
V := reflect.ValueOf(test)
|
|
|
|
if V.Type().Kind() == reflect.Ptr {
|
|
|
|
if V.Type().Kind() == reflect.Ptr {
|
|
|
@ -25,6 +25,7 @@ func (e *env) save(test Test) *env {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
T := V.Type()
|
|
|
|
T := V.Type()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
saved := make(map[string]interface{})
|
|
|
|
for i := 0; i < T.NumField(); i++ {
|
|
|
|
for i := 0; i < T.NumField(); i++ {
|
|
|
|
f := T.Field(i)
|
|
|
|
f := T.Field(i)
|
|
|
|
if !isSaveField(f) {
|
|
|
|
if !isSaveField(f) {
|
|
|
@ -32,9 +33,11 @@ func (e *env) save(test Test) *env {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fv := V.Field(i)
|
|
|
|
fv := V.Field(i)
|
|
|
|
e = &env{
|
|
|
|
saved[f.Name] = fv.Interface()
|
|
|
|
key: f.Name,
|
|
|
|
}
|
|
|
|
value: fv.Interface(),
|
|
|
|
if len(saved) > 0 {
|
|
|
|
|
|
|
|
return &env{
|
|
|
|
|
|
|
|
data: saved,
|
|
|
|
parent: e,
|
|
|
|
parent: e,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -55,13 +58,16 @@ func (e *env) load(dest Test) error {
|
|
|
|
|
|
|
|
|
|
|
|
set := false
|
|
|
|
set := false
|
|
|
|
for e := e; e != nil; e = e.parent {
|
|
|
|
for e := e; e != nil; e = e.parent {
|
|
|
|
if e.key == f.Name {
|
|
|
|
v, ok := e.data[f.Name]
|
|
|
|
ev := reflect.ValueOf(e.value)
|
|
|
|
if !ok {
|
|
|
|
if ev.Type().AssignableTo(fv.Type()) {
|
|
|
|
continue
|
|
|
|
set = true
|
|
|
|
}
|
|
|
|
fv.Set(ev)
|
|
|
|
|
|
|
|
break
|
|
|
|
ev := reflect.ValueOf(v)
|
|
|
|
}
|
|
|
|
if ev.Type().AssignableTo(fv.Type()) {
|
|
|
|
|
|
|
|
set = true
|
|
|
|
|
|
|
|
fv.Set(ev)
|
|
|
|
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|