type myFact … func (f *myFact) String() string { … } func (f *myFact) AFact() { … } func init() { … } func TestEncodeDecode(t *testing.T) { … } type lookup … type pkgLookups … // testEncodeDecode tests fact encoding and decoding and simulates how package facts // are passed during analysis. It operates on a group of Go file contents. Then // for each <package, []lookup> in tests it does the following: // 1. loads and type checks the package, // 2. calls (*facts.Decoder).Decode to load the facts exported by its imports, // 3. exports a myFact Fact for all of package level objects, // 4. For each lookup for the current package: // 4.a) lookup the types.Object for a Go source expression in the current package // (or confirms one is not expected want=="no object"), // 4.b) finds a Fact for the object (or confirms one is not expected want=="no fact"), // 4.c) compares the content of the Fact to want. // 5. encodes the Facts of the package. // // Note: tests are not independent test cases; order matters (as does a package being // skipped). It changes what Facts can be imported. // // Failures are reported on t. func testEncodeDecode(t *testing.T, files map[string]string, tests []pkgLookups) { … } func find(p *types.Package, expr string) types.Object { … } func load(t *testing.T, dir string, path string) (*types.Package, error) { … } type otherFact … func (f *otherFact) String() string { … } func (f *otherFact) AFact() { … } func TestFactFilter(t *testing.T) { … } // TestMalformed checks that facts can be encoded and decoded *despite* // types.Config.Check returning an error. Importing facts is expected to // happen when Analyzers have RunDespiteErrors set to true. So this // needs to robust, e.g. no infinite loops. func TestMalformed(t *testing.T) { … } type closure … func (c closure) Import(path string) (*types.Package, error) { … }