Esempio n. 1
0
func TestGeneratorWithLibFlat(t *testing.T) {
	g := generator.New("example.com/repo", generator.FlatMode)
	pkg := packageFromDir(t, filepath.Join(testData(), "lib"))
	rules, err := g.Generate("lib", pkg)
	if err != nil {
		t.Errorf(`g.Generate("lib", %#v) failed with %v; want success`, pkg, err)
	}

	want := canonicalize(t, "lib/BUILD", `
		go_library(
			name = "lib",
			srcs = ["doc.go", "lib.go"],
			deps = [":lib/deep"],
		)

		go_test(
			name = "lib_test",
			srcs = ["lib_test.go"],
			library = ":lib",
		)

		go_test(
			name = "lib_xtest",
			srcs = ["lib_external_test.go"],
			deps = [":lib"],
		)
	`)
	if got := format(rules); got != want {
		t.Errorf(`g.Generate("lib", %#v) = %s; want %s`, pkg, got, want)
	}
}
Esempio n. 2
0
File: main.go Progetto: yugui/gazel
func newGen() (*gen, error) {
	base, err := filepath.Abs(*baseDir)
	if err != nil {
		return nil, err
	}

	bctx := build.Default
	// Ignore $GOPATH environment variable
	bctx.GOPATH = ""

	m := generator.StructuredMode
	if *flat {
		m = generator.FlatMode
	}

	g := gen{
		base: filepath.Clean(base),
		bctx: bctx,
		g:    generator.New(*goPrefix, m),
	}
	switch *mode {
	case "print":
		g.emit = printFile
	case "fix":
		g.emit = fixFile
	case "diff":
		g.emit = diffFile
	}
	return &g, nil
}
Esempio n. 3
0
func TestGeneratorWithBinFlat(t *testing.T) {
	g := generator.New("example.com/repo", generator.FlatMode)
	pkg := packageFromDir(t, filepath.Join(testData(), "bin"))
	rules, err := g.Generate("bin", pkg)
	if err != nil {
		t.Errorf(`g.Generate("bin", %#v) failed with %v; want success`, pkg, err)
	}

	want := canonicalize(t, "bin/BUILD", `
		go_binary(
			name = "bin",
			srcs = ["main.go"],
			deps = [":lib"],
		)
	`)
	if got := format(rules); got != want {
		t.Errorf(`g.Generate("bin", %#v) = %s; want %s`, pkg, got, want)
	}
}