commit | 8e67e7b4c289726fcdf7683e96d9dfc3e79c37a8 | [log] [tgz] |
---|---|---|
author | Todd Wang <toddw@google.com> | Fri May 22 13:57:39 2015 -0700 |
committer | Todd Wang <toddw@google.com> | Fri May 22 13:57:39 2015 -0700 |
tree | 06edfe3b84f6b36ff8ba652bd9f886ed74d2b263 | |
parent | e8a963245663711ce26a02b572378d41dd98e463 [diff] |
lib: Change test/modules registration mechanism. Previously modules registration and usage looked like this: func foo(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error { ... } func init() { modules.RegisterChild("foo", "", foo) } func TestFoo(t *testing.T) { sh, err := modules.NewShell(...) h, err := sh.Start("foo", nil, ...) ... } The new modules registration and usage looks like this: var foo = modules.Register(func(env *modules.Env, args ...string) error { ... }, "foo") func TestFoo(t *testing.T) { sh, err := modules.NewShell(...) h, err := sh.Start(nil, foo, ...) ... } The main change is that Register now returns a modules.Program, which is typically captured in a global variable, and is used as the argument to Shell.Start. This makes it easy to write the registration manually, and we also have a more obvious linkage between program registration and the Start call through the program variable, rather than using strings. Since registration was annoying to write manually, we used to have 'v23 test generate' detect the functions and automatically add the modules.RegisterChild call. With the new mechanism, the registration is simple to write manually, so 'v23 test generate' has been simplified to remove the detection logic. In fact the Program returned by modules.Register now must be captured, so that it can be passed to Shell.Start; this forces the linkage between Register and Start to be obvious. Also removed the modules Help mechanism, since it wasn't being used, and has questionable utility. In its place, added logic to dump all registered programs when program lookups fail. MultiPart: 2/5 Change-Id: I6d97bc3bc0b74003fb875231ea47a40216a3bac5
This repository contains general purpose libraries used by the Vanadium project.