本文整理汇总了Golang中github.com/jwaldrip/odin/Godeps/_workspace/src/github.com/onsi/ginkgo/internal/codelocation.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: runAsync
func (r *runner) runAsync() (outcome types.SpecState, failure types.SpecFailure) {
done := make(chan interface{}, 1)
go func() {
defer func() {
if e := recover(); e != nil {
r.failer.Panic(codelocation.New(2), e)
select {
case <-done:
break
default:
close(done)
}
}
}()
r.asyncFunc(done)
}()
select {
case <-done:
case <-time.After(r.timeoutThreshold):
r.failer.Timeout(r.codeLocation)
}
failure, outcome = r.failer.Drain(r.nodeType, r.componentIndex, r.codeLocation)
return
}
示例2: SynchronizedAfterSuite
//SynchronizedAfterSuite blocks complement the SynchronizedBeforeSuite blocks in solving the problem of setting up
//external singleton resources shared across nodes when running tests in parallel.
//
//SynchronizedAfterSuite accomplishes this by taking *two* function arguments. The first runs on all nodes. The second runs only on parallel node #1
//and *only* after all other nodes have finished and exited. This ensures that node 1, and any resources it is running, remain alive until
//all other nodes are finished.
//
//Both functions have the same signature: either func() or func(done Done) to run asynchronously.
//
//Here's a pseudo-code example that complements that given in SynchronizedBeforeSuite. Here, SynchronizedAfterSuite is used to tear down the shared database
//only after all nodes have finished:
//
// var _ = SynchronizedAfterSuite(func() {
// dbClient.Cleanup()
// }, func() {
// dbRunner.Stop()
// })
func SynchronizedAfterSuite(allNodesBody interface{}, node1Body interface{}, timeout ...float64) bool {
globalSuite.SetSynchronizedAfterSuiteNode(
allNodesBody,
node1Body,
codelocation.New(1),
parseTimeout(timeout...),
)
return true
}
示例3: Fail
//Fail notifies Ginkgo that the current spec has failed. (Gomega will call Fail for you automatically when an assertion fails.)
func Fail(message string, callerSkip ...int) {
skip := 0
if len(callerSkip) > 0 {
skip = callerSkip[0]
}
globalFailer.Fail(message, codelocation.New(skip+1))
panic(GINKGO_PANIC)
}
示例4: runSync
func (r *runner) runSync() (outcome types.SpecState, failure types.SpecFailure) {
defer func() {
if e := recover(); e != nil {
r.failer.Panic(codelocation.New(2), e)
}
failure, outcome = r.failer.Drain(r.nodeType, r.componentIndex, r.codeLocation)
}()
r.syncFunc()
return
}
示例5: InvalidSharedRunnerBehaviors
func InvalidSharedRunnerBehaviors(build func(body interface{}, timeout time.Duration, failer *Failer.Failer, componentCodeLocation types.CodeLocation) runnable, componentType types.SpecComponentType) {
var (
failer *Failer.Failer
componentCodeLocation types.CodeLocation
innerCodeLocation types.CodeLocation
)
BeforeEach(func() {
failer = Failer.New()
componentCodeLocation = codelocation.New(0)
innerCodeLocation = codelocation.New(0)
})
Describe("invalid functions", func() {
Context("when passed something that's not a function", func() {
It("should panic", func() {
Ω(func() {
build("not a function", 0, failer, componentCodeLocation)
}).Should(Panic())
})
})
Context("when the function takes the wrong kind of argument", func() {
It("should panic", func() {
Ω(func() {
build(func(oops string) {}, 0, failer, componentCodeLocation)
}).Should(Panic())
})
})
Context("when the function takes more than one argument", func() {
It("should panic", func() {
Ω(func() {
build(func(done Done, oops string) {}, 0, failer, componentCodeLocation)
}).Should(Panic())
})
})
})
}
示例6: AfterEach
//AfterEach blocks are run after It blocks. When multiple AfterEach blocks are defined in nested
//Describe and Context blocks the innermost AfterEach blocks are run first.
//
//Like It blocks, AfterEach blocks can be made asynchronous by providing a body function that accepts
//a Done channel
func AfterEach(body interface{}, timeout ...float64) bool {
globalSuite.PushAfterEachNode(body, codelocation.New(1), parseTimeout(timeout...))
return true
}
示例7:
. "github.com/jwaldrip/odin/Godeps/_workspace/src/github.com/onsi/ginkgo"
"github.com/jwaldrip/odin/Godeps/_workspace/src/github.com/onsi/ginkgo/internal/codelocation"
"github.com/jwaldrip/odin/Godeps/_workspace/src/github.com/onsi/ginkgo/types"
. "github.com/jwaldrip/odin/Godeps/_workspace/src/github.com/onsi/gomega"
"runtime"
)
var _ = Describe("CodeLocation", func() {
var (
codeLocation types.CodeLocation
expectedFileName string
expectedLineNumber int
)
caller0 := func() {
codeLocation = codelocation.New(1)
}
caller1 := func() {
_, expectedFileName, expectedLineNumber, _ = runtime.Caller(0)
expectedLineNumber += 2
caller0()
}
BeforeEach(func() {
caller1()
})
It("should use the passed in skip parameter to pick out the correct file & line number", func() {
Ω(codeLocation.FileName).Should(Equal(expectedFileName))
Ω(codeLocation.LineNumber).Should(Equal(expectedLineNumber))
示例8:
. "github.com/jwaldrip/odin/Godeps/_workspace/src/github.com/onsi/ginkgo"
. "github.com/jwaldrip/odin/Godeps/_workspace/src/github.com/onsi/gomega"
"github.com/jwaldrip/odin/Godeps/_workspace/src/github.com/onsi/ginkgo/internal/codelocation"
. "github.com/jwaldrip/odin/Godeps/_workspace/src/github.com/onsi/ginkgo/internal/containernode"
"github.com/jwaldrip/odin/Godeps/_workspace/src/github.com/onsi/ginkgo/types"
)
var _ = Describe("Container Node", func() {
var (
codeLocation types.CodeLocation
container *ContainerNode
)
BeforeEach(func() {
codeLocation = codelocation.New(0)
container = New("description text", types.FlagTypeFocused, codeLocation)
})
Describe("creating a container node", func() {
It("can answer questions about itself", func() {
Ω(container.Text()).Should(Equal("description text"))
Ω(container.Flag()).Should(Equal(types.FlagTypeFocused))
Ω(container.CodeLocation()).Should(Equal(codeLocation))
})
})
Describe("pushing setup nodes", func() {
It("can append setup nodes of various types and fetch them by type", func() {
befA := leafnodes.NewBeforeEachNode(func() {}, codelocation.New(0), 0, nil, 0)
befB := leafnodes.NewBeforeEachNode(func() {}, codelocation.New(0), 0, nil, 0)
示例9:
. "github.com/jwaldrip/odin/Godeps/_workspace/src/github.com/onsi/ginkgo/internal/failer"
. "github.com/jwaldrip/odin/Godeps/_workspace/src/github.com/onsi/gomega"
"github.com/jwaldrip/odin/Godeps/_workspace/src/github.com/onsi/ginkgo/internal/codelocation"
"github.com/jwaldrip/odin/Godeps/_workspace/src/github.com/onsi/ginkgo/types"
)
var _ = Describe("Failer", func() {
var (
failer *Failer
codeLocationA types.CodeLocation
codeLocationB types.CodeLocation
)
BeforeEach(func() {
codeLocationA = codelocation.New(0)
codeLocationB = codelocation.New(0)
failer = New()
})
Context("with no failures", func() {
It("should return success when drained", func() {
failure, state := failer.Drain(types.SpecComponentTypeIt, 3, codeLocationB)
Ω(failure).Should(BeZero())
Ω(state).Should(Equal(types.SpecStatePassed))
})
})
Describe("Fail", func() {
It("should handle failures", func() {
failer.Fail("something failed", codeLocationA)
示例10: XContext
//You can mark the tests within a describe block as pending using XContext
func XContext(text string, body func()) bool {
globalSuite.PushContainerNode(text, body, types.FlagTypePending, codelocation.New(1))
return true
}
示例11: FDescribe
//You can focus the tests within a describe block using FDescribe
func FDescribe(text string, body func()) bool {
globalSuite.PushContainerNode(text, body, types.FlagTypeFocused, codelocation.New(1))
return true
}
示例12: GinkgoRecover
//GinkgoRecover should be deferred at the top of any spawned goroutine that (may) call `Fail`
//Since Gomega assertions call fail, you should throw a `defer GinkgoRecover()` at the top of any goroutine that
//calls out to Gomega
//
//Here's why: Ginkgo's `Fail` method records the failure and then panics to prevent
//further assertions from running. This panic must be recovered. Ginkgo does this for you
//if the panic originates in a Ginkgo node (an It, BeforeEach, etc...)
//
//Unfortunately, if a panic originates on a goroutine *launched* from one of these nodes there's no
//way for Ginkgo to rescue the panic. To do this, you must remember to `defer GinkgoRecover()` at the top of such a goroutine.
func GinkgoRecover() {
e := recover()
if e != nil {
globalFailer.Panic(codelocation.New(1), e)
}
}
示例13:
"##teamcity[testFinished name='A B C' duration='5000']" +
"##teamcity[testSuiteFinished name='Foo|'s test suite']"
Ω(actual).Should(Equal(expected))
})
})
Describe("when the BeforeSuite fails", func() {
var beforeSuite *types.SetupSummary
BeforeEach(func() {
beforeSuite = &types.SetupSummary{
State: types.SpecStateFailed,
RunTime: 3 * time.Second,
Failure: types.SpecFailure{
Message: "failed to setup\n",
ComponentCodeLocation: codelocation.New(0),
},
}
reporter.BeforeSuiteDidRun(beforeSuite)
reporter.SpecSuiteDidEnd(&types.SuiteSummary{
NumberOfSpecsThatWillBeRun: 1,
NumberOfFailedSpecs: 1,
RunTime: 10 * time.Second,
})
})
It("should record the test as having failed", func() {
actual := buffer.String()
expected := fmt.Sprintf(
"##teamcity[testSuiteStarted name='Foo|'s test suite']"+
示例14:
newContainer := func(text string, flag types.FlagType, setupNodes ...leafnodes.BasicNode) *containernode.ContainerNode {
c := containernode.New(text, flag, codeLocation)
for _, node := range setupNodes {
c.PushSetupNode(node)
}
return c
}
containers := func(containers ...*containernode.ContainerNode) []*containernode.ContainerNode {
return containers
}
BeforeEach(func() {
buffer = gbytes.NewBuffer()
failer = Failer.New()
codeLocation = codelocation.New(0)
nodesThatRan = []string{}
})
Describe("marking specs focused and pending", func() {
It("should satisfy various caes", func() {
cases := []struct {
ContainerFlags []types.FlagType
SubjectFlag types.FlagType
Pending bool
Focused bool
}{
{[]types.FlagType{}, noneFlag, false, false},
{[]types.FlagType{}, focusedFlag, false, true},
{[]types.FlagType{}, pendingFlag, true, false},
{[]types.FlagType{noneFlag}, noneFlag, false, false},
示例15:
. "github.com/jwaldrip/odin/Godeps/_workspace/src/github.com/onsi/ginkgo"
. "github.com/jwaldrip/odin/Godeps/_workspace/src/github.com/onsi/ginkgo/internal/spec"
. "github.com/jwaldrip/odin/Godeps/_workspace/src/github.com/onsi/gomega"
"github.com/jwaldrip/odin/Godeps/_workspace/src/github.com/onsi/ginkgo/internal/codelocation"
"github.com/jwaldrip/odin/Godeps/_workspace/src/github.com/onsi/ginkgo/internal/containernode"
"github.com/jwaldrip/odin/Godeps/_workspace/src/github.com/onsi/ginkgo/internal/leafnodes"
"github.com/jwaldrip/odin/Godeps/_workspace/src/github.com/onsi/ginkgo/types"
)
var _ = Describe("Specs", func() {
var specs *Specs
newSpec := func(text string, flag types.FlagType) *Spec {
subject := leafnodes.NewItNode(text, func() {}, flag, codelocation.New(0), 0, nil, 0)
return New(subject, []*containernode.ContainerNode{}, false)
}
newMeasureSpec := func(text string, flag types.FlagType) *Spec {
subject := leafnodes.NewMeasureNode(text, func(Benchmarker) {}, flag, codelocation.New(0), 0, nil, 0)
return New(subject, []*containernode.ContainerNode{}, false)
}
newSpecs := func(args ...interface{}) *Specs {
specs := []*Spec{}
for index := 0; index < len(args)-1; index += 2 {
specs = append(specs, newSpec(args[index].(string), args[index+1].(types.FlagType)))
}
return NewSpecs(specs)
}