File: build_command.go

package info (click to toggle)
golang-ginkgo 1.2.0%2Bgit20161006.acfa16a-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 1,324 kB
  • ctags: 1,210
  • sloc: makefile: 12
file content (68 lines) | stat: -rw-r--r-- 1,665 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main

import (
	"flag"
	"fmt"
	"os"
	"path/filepath"

	"github.com/onsi/ginkgo/ginkgo/interrupthandler"
	"github.com/onsi/ginkgo/ginkgo/testrunner"
)

func BuildBuildCommand() *Command {
	commandFlags := NewBuildCommandFlags(flag.NewFlagSet("build", flag.ExitOnError))
	interruptHandler := interrupthandler.NewInterruptHandler()
	builder := &SpecBuilder{
		commandFlags:     commandFlags,
		interruptHandler: interruptHandler,
	}

	return &Command{
		Name:         "build",
		FlagSet:      commandFlags.FlagSet,
		UsageCommand: "ginkgo build <FLAGS> <PACKAGES>",
		Usage: []string{
			"Build the passed in <PACKAGES> (or the package in the current directory if left blank).",
			"Accepts the following flags:",
		},
		Command: builder.BuildSpecs,
	}
}

type SpecBuilder struct {
	commandFlags     *RunWatchAndBuildCommandFlags
	interruptHandler *interrupthandler.InterruptHandler
}

func (r *SpecBuilder) BuildSpecs(args []string, additionalArgs []string) {
	r.commandFlags.computeNodes()

	suites, _ := findSuites(args, r.commandFlags.Recurse, r.commandFlags.SkipPackage, false)

	if len(suites) == 0 {
		complainAndQuit("Found no test suites")
	}

	passed := true
	for _, suite := range suites {
		runner := testrunner.New(suite, 1, false, r.commandFlags.GoOpts, nil)
		fmt.Printf("Compiling %s...\n", suite.PackageName)

		path, _ := filepath.Abs(filepath.Join(suite.Path, fmt.Sprintf("%s.test", suite.PackageName)))
		err := runner.CompileTo(path)
		if err != nil {
			fmt.Println(err.Error())
			passed = false
		} else {
			fmt.Printf("    compiled %s.test\n", suite.PackageName)
		}

		runner.CleanUp()
	}

	if passed {
		os.Exit(0)
	}
	os.Exit(1)
}