-
Notifications
You must be signed in to change notification settings - Fork 555
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More thread-safe execution; Reporting no longer reports stats to the …
…console;
- Loading branch information
1 parent
29375dc
commit aca3c33
Showing
8 changed files
with
104 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package convey | ||
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
"strings" | ||
"sync" | ||
|
||
"github.com/smartystreets/goconvey/execution" | ||
"github.com/smartystreets/goconvey/reporting" | ||
) | ||
|
||
type SuiteContext struct { | ||
runners map[string]execution.Runner | ||
reporters map[string]reporting.Reporter | ||
lock sync.Mutex | ||
} | ||
|
||
func (self *SuiteContext) Assign() execution.Runner { | ||
key := resolveExternalCallerWithTestName() | ||
reporter := buildReporter() | ||
runner := execution.NewRunner() | ||
runner.UpgradeReporter(reporter) | ||
|
||
self.lock.Lock() | ||
self.runners[key] = runner | ||
self.reporters[key] = reporter | ||
self.lock.Unlock() | ||
|
||
return runner | ||
} | ||
|
||
func (self *SuiteContext) CurrentRunner() execution.Runner { | ||
key := resolveExternalCallerWithTestName() | ||
self.lock.Lock() | ||
defer self.lock.Unlock() | ||
return self.runners[key] | ||
} | ||
|
||
func (self *SuiteContext) CurrentReporter() reporting.Reporter { | ||
key := resolveExternalCallerWithTestName() | ||
self.lock.Lock() | ||
defer self.lock.Unlock() | ||
return self.reporters[key] | ||
} | ||
|
||
func NewSuiteContext() *SuiteContext { | ||
self := new(SuiteContext) | ||
self.runners = make(map[string]execution.Runner) | ||
self.reporters = make(map[string]reporting.Reporter) | ||
return self | ||
} | ||
|
||
func resolveExternalCallerWithTestName() string { | ||
// TODO: It turns out the more robust solution is to manually parse the debug.Stack() | ||
// because we can then filter out non-test methods that start with "Test". | ||
|
||
var ( | ||
caller_id uintptr | ||
testName string | ||
file string | ||
) | ||
callers := runtime.Callers(0, callStack) | ||
|
||
var x int | ||
for ; x < callers; x++ { | ||
caller_id, file, _, _ = runtime.Caller(x) | ||
if strings.HasSuffix(file, "test.go") { | ||
break | ||
} | ||
} | ||
|
||
for ; x < callers; x++ { | ||
caller_id, _, _, _ = runtime.Caller(x) | ||
packageAndTestName := runtime.FuncForPC(caller_id).Name() | ||
parts := strings.Split(packageAndTestName, ".") | ||
testName = parts[len(parts)-1] | ||
if strings.HasPrefix(testName, "Test") { | ||
break | ||
} | ||
} | ||
|
||
if testName == "" { | ||
testName = "<unkown test method name>" // panic? | ||
} | ||
return fmt.Sprintf("%s---%s", testName, file) | ||
} | ||
|
||
const maxStackDepth = 100 // This had better be enough... | ||
|
||
var callStack []uintptr = make([]uintptr, maxStackDepth, maxStackDepth) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,26 @@ | ||
package execution | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/smartystreets/goconvey/gotest" | ||
) | ||
import "github.com/smartystreets/goconvey/gotest" | ||
|
||
type Registration struct { | ||
Situation string | ||
Action *Action | ||
Test gotest.T | ||
File string | ||
Line int | ||
TestName string | ||
} | ||
|
||
func (self *Registration) IsTopLevel() bool { | ||
return self.Test != nil | ||
} | ||
|
||
func (self *Registration) KeyName() string { | ||
return fmt.Sprintf("%s:%s", self.File, self.TestName) | ||
} | ||
|
||
func NewRegistration(situation string, action *Action, test gotest.T) *Registration { | ||
file, line, testName := gotest.ResolveExternalCallerWithTestName() | ||
file, line, _ := gotest.ResolveExternalCaller() | ||
self := &Registration{} | ||
self.Situation = situation | ||
self.Action = action | ||
self.Test = test | ||
self.File = file | ||
self.Line = line | ||
self.TestName = testName | ||
return self | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters