mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-26 10:37:04 -06:00
Remove commented out test code
And replace it with something that verifies that generated dependency code is imported correctly. Also address other nits.
This commit is contained in:
@@ -114,10 +114,7 @@ func generateDepCode(depsDir string, p types.Package, cs chunks.ChunkSource) dep
|
||||
deps := depsMap{}
|
||||
p.Dependencies().IterAll(func(r types.RefOfPackage) {
|
||||
p := r.GetValue(cs)
|
||||
pDeps := map[ref.Ref]types.Package{}
|
||||
if !p.Dependencies().Empty() {
|
||||
pDeps = generateDepCode(depsDir, p, cs)
|
||||
}
|
||||
pDeps := generateDepCode(depsDir, p, cs)
|
||||
tag := toTag(p.Ref().String())
|
||||
parsed := pkg.Parsed{PackageDef: p.Def(), Name: tag}
|
||||
generateAndEmit(tag, filepath.Join(depsDir, tag, tag+".go"), importPaths(depsDir, pDeps), pDeps, parsed)
|
||||
@@ -496,15 +493,13 @@ func (gen *codeGen) userName(t types.TypeRef) string {
|
||||
|
||||
func toTypeRef(t types.TypeRef, fileID, packageName string) string {
|
||||
if t.HasPackageRef() {
|
||||
refCode := fmt.Sprintf(`ref.Parse("%s")`, t.PackageRef().String())
|
||||
return fmt.Sprintf(`types.MakeTypeRef("%s", %s)`, t.Name(), refCode)
|
||||
return fmt.Sprintf(`types.MakeTypeRef("%s", ref.Parse("%s"))`, t.Name(), t.PackageRef().String())
|
||||
}
|
||||
if t.IsUnresolved() && fileID != "" {
|
||||
refCode := fmt.Sprintf("__%sPackageInFile_%s_CachedRef", packageName, fileID)
|
||||
return fmt.Sprintf(`types.MakeTypeRef("%s", %s)`, t.Name(), refCode)
|
||||
return fmt.Sprintf(`types.MakeTypeRef("%s", __%sPackageInFile_%s_CachedRef)`, t.Name(), packageName, fileID)
|
||||
}
|
||||
if t.IsUnresolved() {
|
||||
return fmt.Sprintf(`types.MakeTypeRef("%s", %s)`, t.Name(), "ref.Ref{}")
|
||||
return fmt.Sprintf(`types.MakeTypeRef("%s", ref.Ref{})`, t.Name())
|
||||
}
|
||||
|
||||
if types.IsPrimitiveKind(t.Desc.Kind()) {
|
||||
|
||||
@@ -3,6 +3,9 @@ package main
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"go/build"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
@@ -183,24 +186,28 @@ func TestImportedTypes(t *testing.T) {
|
||||
depsDir := filepath.Join(thisFileDir(), "deps")
|
||||
defer os.RemoveAll(depsDir)
|
||||
|
||||
pkgDS = generate("name", inFile, filepath.Join(dir, "out.go"), depsDir, pkgDS)
|
||||
outFile := filepath.Join(dir, "out.go")
|
||||
pkgDS = generate("name", inFile, outFile, depsDir, pkgDS)
|
||||
|
||||
// outFiles, err := filepath.Glob(filepath.Join(dir, "*.go"))
|
||||
// assert.NoError(err)
|
||||
// depFiles, err := filepath.Glob(filepath.Join(depsDir, "*", "*.go"))
|
||||
// assert.NoError(err)
|
||||
// for _, file := range append(outFiles, depFiles...) {
|
||||
// b, _ := ioutil.ReadFile(file)
|
||||
// fmt.Printf("%s\n***************\n%s\n", file, b)
|
||||
// }
|
||||
// Check that dependency code was generated.
|
||||
expectedDepPkgAbs := filepath.Join(depsDir, toTag(importedRef.String()))
|
||||
_, err = os.Stat(expectedDepPkgAbs)
|
||||
assert.NoError(err)
|
||||
|
||||
// importedSha := toTag(importedRef.String())
|
||||
// b, _ = ioutil.ReadFile(filepath.Join(dir, importedSha, importedSha+".go"))
|
||||
// fmt.Printf("%s\n", b)
|
||||
// s := types.SetOfRefOfPackageFromVal(pkgDS.Head().Value())
|
||||
// assert.EqualValues(1, s.Len())
|
||||
// tr := s.Any().GetValue(ds).NamedTypes().Get("Simple")
|
||||
// assert.EqualValues(types.StructKind, tr.Kind())
|
||||
// Get the imports from out.go
|
||||
ast, err := parser.ParseFile(token.NewFileSet(), outFile, nil, parser.ImportsOnly)
|
||||
assert.NoError(err)
|
||||
imports := []string{}
|
||||
for _, s := range ast.Imports {
|
||||
//Strip enclosing quotes from s.Path.Value
|
||||
imports = append(imports, s.Path.Value[1:len(s.Path.Value)-1])
|
||||
}
|
||||
// Get the canonical import path for the generated dependency code.
|
||||
expectedDepPkg, err := build.ImportDir(expectedDepPkgAbs, build.FindOnly)
|
||||
assert.NoError(err)
|
||||
|
||||
// Make sure that out.go imported the dependency code.
|
||||
assert.Contains(imports, expectedDepPkg.ImportPath)
|
||||
}
|
||||
|
||||
func thisFileDir() string {
|
||||
|
||||
Reference in New Issue
Block a user