add support for -test.short flag
Этот коммит содержится в:
родитель
d9ad500cf7
коммит
0dfb336563
2 изменённых файлов: 17 добавлений и 5 удалений
15
main.go
15
main.go
|
@ -159,7 +159,7 @@ func Build(pkgName, outpath string, options *compileopts.Options) error {
|
||||||
|
|
||||||
// Test runs the tests in the given package. Returns whether the test passed and
|
// Test runs the tests in the given package. Returns whether the test passed and
|
||||||
// possibly an error if the test failed to run.
|
// possibly an error if the test failed to run.
|
||||||
func Test(pkgName string, options *compileopts.Options, testCompileOnly, testVerbose bool, outpath string) (bool, error) {
|
func Test(pkgName string, options *compileopts.Options, testCompileOnly, testVerbose, testShort bool, outpath string) (bool, error) {
|
||||||
options.TestConfig.CompileTestBinary = true
|
options.TestConfig.CompileTestBinary = true
|
||||||
config, err := builder.NewConfig(options)
|
config, err := builder.NewConfig(options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -185,7 +185,7 @@ func Test(pkgName string, options *compileopts.Options, testCompileOnly, testVer
|
||||||
// Run the test.
|
// Run the test.
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
var err error
|
var err error
|
||||||
passed, err = runPackageTest(config, result, testVerbose)
|
passed, err = runPackageTest(config, result, testVerbose, testShort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -211,13 +211,17 @@ func Test(pkgName string, options *compileopts.Options, testCompileOnly, testVer
|
||||||
// runPackageTest runs a test binary that was previously built. The return
|
// runPackageTest runs a test binary that was previously built. The return
|
||||||
// values are whether the test passed and any errors encountered while trying to
|
// values are whether the test passed and any errors encountered while trying to
|
||||||
// run the binary.
|
// run the binary.
|
||||||
func runPackageTest(config *compileopts.Config, result builder.BuildResult, testVerbose bool) (bool, error) {
|
func runPackageTest(config *compileopts.Config, result builder.BuildResult, testVerbose, testShort bool) (bool, error) {
|
||||||
if len(config.Target.Emulator) == 0 {
|
if len(config.Target.Emulator) == 0 {
|
||||||
// Run directly.
|
// Run directly.
|
||||||
var flags []string
|
var flags []string
|
||||||
if testVerbose {
|
if testVerbose {
|
||||||
flags = append(flags, "-test.v")
|
flags = append(flags, "-test.v")
|
||||||
}
|
}
|
||||||
|
if testShort {
|
||||||
|
flags = append(flags, "-test.short")
|
||||||
|
}
|
||||||
|
|
||||||
cmd := executeCommand(config.Options, result.Binary, flags...)
|
cmd := executeCommand(config.Options, result.Binary, flags...)
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
@ -1102,10 +1106,11 @@ func main() {
|
||||||
if command == "help" || command == "build" || command == "build-library" || command == "test" {
|
if command == "help" || command == "build" || command == "build-library" || command == "test" {
|
||||||
flag.StringVar(&outpath, "o", "", "output filename")
|
flag.StringVar(&outpath, "o", "", "output filename")
|
||||||
}
|
}
|
||||||
var testCompileOnlyFlag, testVerboseFlag *bool
|
var testCompileOnlyFlag, testVerboseFlag, testShortFlag *bool
|
||||||
if command == "help" || command == "test" {
|
if command == "help" || command == "test" {
|
||||||
testCompileOnlyFlag = flag.Bool("c", false, "compile the test binary but do not run it")
|
testCompileOnlyFlag = flag.Bool("c", false, "compile the test binary but do not run it")
|
||||||
testVerboseFlag = flag.Bool("v", false, "verbose: print additional output")
|
testVerboseFlag = flag.Bool("v", false, "verbose: print additional output")
|
||||||
|
testShortFlag = flag.Bool("short", false, "short: run smaller test suite to save time")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Early command processing, before commands are interpreted by the Go flag
|
// Early command processing, before commands are interpreted by the Go flag
|
||||||
|
@ -1280,7 +1285,7 @@ func main() {
|
||||||
allTestsPassed := true
|
allTestsPassed := true
|
||||||
for _, pkgName := range pkgNames {
|
for _, pkgName := range pkgNames {
|
||||||
// TODO: parallelize building the test binaries
|
// TODO: parallelize building the test binaries
|
||||||
passed, err := Test(pkgName, options, *testCompileOnlyFlag, *testVerboseFlag, outpath)
|
passed, err := Test(pkgName, options, *testCompileOnlyFlag, *testVerboseFlag, *testShortFlag, outpath)
|
||||||
handleCompilerError(err)
|
handleCompilerError(err)
|
||||||
if !passed {
|
if !passed {
|
||||||
allTestsPassed = false
|
allTestsPassed = false
|
||||||
|
|
|
@ -19,6 +19,7 @@ import (
|
||||||
// Testing flags.
|
// Testing flags.
|
||||||
var (
|
var (
|
||||||
flagVerbose bool
|
flagVerbose bool
|
||||||
|
flagShort bool
|
||||||
)
|
)
|
||||||
|
|
||||||
var initRan bool
|
var initRan bool
|
||||||
|
@ -31,6 +32,7 @@ func Init() {
|
||||||
initRan = true
|
initRan = true
|
||||||
|
|
||||||
flag.BoolVar(&flagVerbose, "test.v", false, "verbose: print additional output")
|
flag.BoolVar(&flagVerbose, "test.v", false, "verbose: print additional output")
|
||||||
|
flag.BoolVar(&flagShort, "test.short", false, "short: run smaller test suite to save time")
|
||||||
}
|
}
|
||||||
|
|
||||||
// common holds the elements common between T and B and
|
// common holds the elements common between T and B and
|
||||||
|
@ -282,6 +284,11 @@ func (m *M) Run() int {
|
||||||
return failures
|
return failures
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Short reports whether the -test.short flag is set.
|
||||||
|
func Short() bool {
|
||||||
|
return flagShort
|
||||||
|
}
|
||||||
|
|
||||||
func TestMain(m *M) {
|
func TestMain(m *M) {
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче