Этот коммит содержится в:
gedi 2016-06-13 23:47:24 +03:00
родитель f16addd9c9
коммит 2162380725

35
run.go
Просмотреть файл

@ -11,10 +11,11 @@ type initializer func(*Suite)
type runner struct { type runner struct {
sync.WaitGroup sync.WaitGroup
semaphore chan int semaphore chan int
features []*feature stopOnFailure bool
fmt Formatter // needs to support concurrency features []*feature
initializer initializer fmt Formatter // needs to support concurrency
initializer initializer
} }
func (r *runner) run() (failed bool) { func (r *runner) run() (failed bool) {
@ -22,17 +23,23 @@ func (r *runner) run() (failed bool) {
for _, ft := range r.features { for _, ft := range r.features {
go func(fail *bool, feat *feature) { go func(fail *bool, feat *feature) {
r.semaphore <- 1 r.semaphore <- 1
defer func() {
r.Done()
<-r.semaphore
}()
if r.stopOnFailure && *fail {
return
}
suite := &Suite{ suite := &Suite{
fmt: r.fmt, fmt: r.fmt,
features: []*feature{feat}, stopOnFailure: r.stopOnFailure,
features: []*feature{feat},
} }
r.initializer(suite) r.initializer(suite)
suite.run() suite.run()
if suite.failed { if suite.failed {
*fail = true *fail = true
} }
<-r.semaphore
r.Done()
}(&failed, ft) }(&failed, ft)
} }
r.Wait() r.Wait()
@ -78,9 +85,6 @@ func Run(contextInitializer func(suite *Suite)) int {
if concurrency > 1 && format != "progress" { if concurrency > 1 && format != "progress" {
fatal(fmt.Errorf("when concurrency level is higher than 1, only progress format is supported")) fatal(fmt.Errorf("when concurrency level is higher than 1, only progress format is supported"))
} }
if concurrency > 1 && sof {
fatal(fmt.Errorf("when concurrency level is higher than 1, cannot stop on first failure for now"))
}
formatter, err := findFmt(format) formatter, err := findFmt(format)
fatal(err) fatal(err)
@ -88,10 +92,11 @@ func Run(contextInitializer func(suite *Suite)) int {
fatal(err) fatal(err)
r := runner{ r := runner{
fmt: formatter, fmt: formatter,
initializer: contextInitializer, initializer: contextInitializer,
semaphore: make(chan int, concurrency), semaphore: make(chan int, concurrency),
features: features, features: features,
stopOnFailure: sof,
} }
if failed := r.run(); failed { if failed := r.run(); failed {