当前位置: 首页>>代码示例>>Golang>>正文


Golang types.GenerateCodeLocation函数代码示例

本文整理汇总了Golang中github.com/innotech/hydra/vendors/github.com/onsi/ginkgo/types.GenerateCodeLocation函数的典型用法代码示例。如果您正苦于以下问题:Golang GenerateCodeLocation函数的具体用法?Golang GenerateCodeLocation怎么用?Golang GenerateCodeLocation使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了GenerateCodeLocation函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: run

func (runnable *runnableNode) run() (outcome runOutcome, failure failureData) {
	done := make(chan interface{}, 1)

	defer func() {
		if e := recover(); e != nil {
			outcome = runOutcomePanicked
			failure = failureData{
				message:        "Test Panicked",
				codeLocation:   types.GenerateCodeLocation(2),
				forwardedPanic: e,
			}
		}
	}()

	if runnable.isAsync {
		go runnable.asyncFunc(done)
	} else {
		runnable.syncFunc()
		done <- true
	}

	select {
	case <-done:
		outcome = runOutcomeCompleted
	case <-time.After(runnable.timeoutThreshold):
		outcome = runOutcomeTimedOut
		failure = failureData{
			message:      "Timed out",
			codeLocation: runnable.codeLocation,
		}
	}

	return
}
开发者ID:lichia,项目名称:hydra,代码行数:34,代码来源:runnable_node.go

示例2: fail

func (suite *suite) fail(message string, callerSkip int) {
	if suite.exampleCollection != nil {
		suite.exampleCollection.fail(failureData{
			message:      message,
			codeLocation: types.GenerateCodeLocation(callerSkip + 2),
		})
	}
}
开发者ID:lichia,项目名称:hydra,代码行数:8,代码来源:suite.go

示例3: init

func init() {
	Describe("MeasureNode", func() {
		var measure *measureNode
		var i int
		var codeLocation types.CodeLocation

		BeforeEach(func() {
			i = 0
			codeLocation = types.GenerateCodeLocation(0)
			measure = newMeasureNode("foo", func(b Benchmarker) {
				b.RecordValue("bar", float64(i))
				i += 1
			}, flagTypeFocused, codeLocation, 10)
		})

		It("should report on itself accurately", func() {
			Ω(measure.getText()).Should(Equal("foo"))
			Ω(measure.getFlag()).Should(Equal(flagTypeFocused))
			Ω(measure.getCodeLocation()).Should(Equal(codeLocation))
			Ω(measure.nodeType()).Should(Equal(nodeTypeMeasure))
			Ω(measure.samples).Should(Equal(10))
		})

		Context("when run", func() {
			It("should provide the body function with a benchmarker and be able to aggregate reports", func() {
				measure.run()
				measure.run()
				measure.run()
				measure.run()

				report := measure.measurementsReport()
				Ω(report).Should(HaveLen(1))
				Ω(report["bar"].Name).Should(Equal("bar"))
				Ω(report["bar"].Results).Should(Equal([]float64{0, 1, 2, 3}))
			})
		})
	})
}
开发者ID:lichia,项目名称:hydra,代码行数:38,代码来源:measure_node_test.go

示例4:

		{types.ExampleStateFailed, "Failure"},
		{types.ExampleStateTimedOut, "Timeout"},
		{types.ExampleStatePanicked, "Panic"},
	}

	for _, exampleStateCase := range exampleStateCases {
		exampleStateCase := exampleStateCase
		Describe("a failing test", func() {
			var example *types.ExampleSummary
			BeforeEach(func() {
				example = &types.ExampleSummary{
					ComponentTexts: []string{"[Top Level]", "A", "B", "C"},
					State:          exampleStateCase.state,
					RunTime:        5 * time.Second,
					Failure: types.ExampleFailure{
						ComponentCodeLocation: types.GenerateCodeLocation(0),
						Message:               "I failed",
					},
				}
				reporter.ExampleWillRun(example)
				reporter.ExampleDidComplete(example)

				reporter.SpecSuiteDidEnd(&types.SuiteSummary{
					NumberOfExamplesThatWillBeRun: 1,
					NumberOfFailedExamples:        1,
					RunTime:                       10 * time.Second,
				})
			})

			It("should record test as failing", func() {
				output := readOutputFile()
开发者ID:lichia,项目名称:hydra,代码行数:31,代码来源:junit_reporter_test.go

示例5: init

func init() {
	Describe("Container Node", func() {
		var (
			codeLocation types.CodeLocation
			container    *containerNode
		)

		BeforeEach(func() {
			codeLocation = types.GenerateCodeLocation(0)
			container = newContainerNode("description text", flagTypeFocused, codeLocation)
		})

		Describe("creating a container node", func() {
			It("stores off the passed in properties", func() {
				Ω(container.text).Should(Equal("description text"))
				Ω(container.flag).Should(Equal(flagTypeFocused))
				Ω(container.codeLocation).Should(Equal(codeLocation))
			})
		})

		Describe("appending", func() {
			Describe("it nodes", func() {
				It("can append container nodes and it nodes", func() {
					itA := newItNode("itA", func() {}, flagTypeNone, types.GenerateCodeLocation(0), 0)
					itB := newItNode("itB", func() {}, flagTypeNone, types.GenerateCodeLocation(0), 0)
					subContainer := newContainerNode("subcontainer", flagTypeNone, types.GenerateCodeLocation(0))
					container.pushSubjectNode(itA)
					container.pushContainerNode(subContainer)
					container.pushSubjectNode(itB)
					Ω(container.subjectAndContainerNodes).Should(Equal([]node{
						itA,
						subContainer,
						itB,
					}))
				})
			})

			Describe("other runnable nodes", func() {
				var (
					runnableA *runnableNode
					runnableB *runnableNode
				)

				BeforeEach(func() {
					runnableA = newRunnableNode(func() {}, types.GenerateCodeLocation(0), 0)
					runnableB = newRunnableNode(func() {}, types.GenerateCodeLocation(0), 0)
				})

				It("can append multiple beforeEach nodes", func() {
					container.pushBeforeEachNode(runnableA)
					container.pushBeforeEachNode(runnableB)
					Ω(container.beforeEachNodes).Should(Equal([]*runnableNode{
						runnableA,
						runnableB,
					}))
				})

				It("can append multiple justBeforeEach nodes", func() {
					container.pushJustBeforeEachNode(runnableA)
					container.pushJustBeforeEachNode(runnableB)
					Ω(container.justBeforeEachNodes).Should(Equal([]*runnableNode{
						runnableA,
						runnableB,
					}))
				})

				It("can append multiple afterEach nodes", func() {
					container.pushAfterEachNode(runnableA)
					container.pushAfterEachNode(runnableB)
					Ω(container.afterEachNodes).Should(Equal([]*runnableNode{
						runnableA,
						runnableB,
					}))
				})
			})
		})

		Describe("generating examples", func() {
			var (
				itA          *itNode
				itB          *itNode
				subContainer *containerNode
				subItA       *itNode
				subItB       *itNode
			)

			BeforeEach(func() {
				itA = newItNode("itA", func() {}, flagTypeNone, types.GenerateCodeLocation(0), 0)
				itB = newItNode("itB", func() {}, flagTypeNone, types.GenerateCodeLocation(0), 0)
				subContainer = newContainerNode("subcontainer", flagTypeNone, types.GenerateCodeLocation(0))
				subItA = newItNode("subItA", func() {}, flagTypeNone, types.GenerateCodeLocation(0), 0)
				subItB = newItNode("subItB", func() {}, flagTypeNone, types.GenerateCodeLocation(0), 0)

				container.pushSubjectNode(itA)
				container.pushContainerNode(subContainer)
				container.pushSubjectNode(itB)

				subContainer.pushSubjectNode(subItA)
				subContainer.pushSubjectNode(subItB)
			})
//.........这里部分代码省略.........
开发者ID:lichia,项目名称:hydra,代码行数:101,代码来源:container_node_test.go

示例6: init

func init() {
	Describe("Example", func() {
		var it *itNode

		BeforeEach(func() {
			it = newItNode("It", func() {}, flagTypeNone, types.GenerateCodeLocation(0), 0)
		})

		Describe("creating examples and adding container nodes", func() {
			var (
				containerA *containerNode
				containerB *containerNode
				ex         *example
			)

			BeforeEach(func() {
				containerA = newContainerNode("A", flagTypeNone, types.GenerateCodeLocation(0))
				containerB = newContainerNode("B", flagTypeNone, types.GenerateCodeLocation(0))
			})

			JustBeforeEach(func() {
				ex = newExample(it)
				ex.addContainerNode(containerB)
				ex.addContainerNode(containerA)
			})

			It("should store off the it node", func() {
				Ω(ex.subject).Should(Equal(it))
			})

			It("should store off the container nodes in reverse order", func() {
				Ω(ex.containers).Should(Equal([]*containerNode{containerA, containerB}))
			})

			It("should provide the concatenated strings", func() {
				Ω(ex.concatenatedString()).Should(Equal("A B It"))
			})

			Context("when neither the It node nor the containers is focused or pending", func() {
				It("should not be focused or pending", func() {
					Ω(ex.focused).Should(BeFalse())
					Ω(ex.state).Should(BeZero())
				})
			})

			Context("when the It node is focused", func() {
				BeforeEach(func() {
					it.flag = flagTypeFocused
				})

				It("should be focused", func() {
					Ω(ex.focused).Should(BeTrue())
				})
			})

			Context("when one of the containers is focused", func() {
				BeforeEach(func() {
					containerB.flag = flagTypeFocused
				})

				It("should be focused", func() {
					Ω(ex.focused).Should(BeTrue())
				})
			})

			Context("when the It node is pending", func() {
				BeforeEach(func() {
					it.flag = flagTypePending
				})

				It("should be in the pending state", func() {
					Ω(ex.state).Should(Equal(types.ExampleStatePending))
				})
			})

			Context("when one of the containers is pending", func() {
				BeforeEach(func() {
					containerB.flag = flagTypePending
				})

				It("should be in the pending state", func() {
					Ω(ex.state).Should(Equal(types.ExampleStatePending))
				})
			})

			Context("when one container is pending and another container is focused", func() {
				BeforeEach(func() {
					containerA.flag = flagTypeFocused
					containerB.flag = flagTypePending
				})

				It("should be focused and have the pending state", func() {
					Ω(ex.focused).Should(BeTrue())
					Ω(ex.state).Should(Equal(types.ExampleStatePending))
				})
			})
		})

		Describe("Skipping an example", func() {
			It("should mark the example as skipped", func() {
//.........这里部分代码省略.........
开发者ID:lichia,项目名称:hydra,代码行数:101,代码来源:example_test.go

示例7: init

func init() {
	Describe("RunnableNode", func() {
		Describe("basic construction parameters", func() {
			It("should store off the passed in code location", func() {
				codeLocation := types.GenerateCodeLocation(0)
				Ω(newRunnableNode(func() {}, codeLocation, 0).codeLocation).Should(Equal(codeLocation))
			})
		})

		Describe("running the passed in function", func() {
			Context("when the function is synchronous and does not panic", func() {
				It("should run the function and report a runOutcomeCompleted", func() {
					didRun := false
					runnableNode := newRunnableNode(func() {
						didRun = true
					}, types.GenerateCodeLocation(0), 0)

					outcome, failure := runnableNode.run()

					Ω(didRun).Should(BeTrue())
					Ω(outcome).Should(Equal(runOutcomeCompleted))
					Ω(failure).Should(BeZero())
				})
			})

			Context("when the function is synchronous and *does* panic", func() {
				var (
					codeLocation types.CodeLocation
					outcome      runOutcome
					failure      failureData
				)

				BeforeEach(func() {
					node := newRunnableNode(func() {
						codeLocation = types.GenerateCodeLocation(0)
						panic("ack!")
					}, types.GenerateCodeLocation(0), 0)

					outcome, failure = node.run()
				})

				It("should run the function and report a runOutcomePanicked", func() {
					Ω(outcome).Should(Equal(runOutcomePanicked))
					Ω(failure.message).Should(Equal("Test Panicked"))
				})

				It("should include the code location of the panic itself", func() {
					Ω(failure.codeLocation.FileName).Should(Equal(codeLocation.FileName))
					Ω(failure.codeLocation.LineNumber).Should(Equal(codeLocation.LineNumber + 1))
				})

				It("should include the panic data", func() {
					Ω(failure.forwardedPanic).Should(Equal("ack!"))
				})
			})

			Context("when the function is asynchronous", func() {
				var (
					node               *runnableNode
					sleepDuration      time.Duration
					timeoutDuration    time.Duration
					numberOfGoRoutines int
				)

				BeforeEach(func() {
					sleepDuration = time.Duration(0.001 * float64(time.Second))
					timeoutDuration = time.Duration(1 * float64(time.Second))
				})

				JustBeforeEach(func() {
					node = newRunnableNode(func(done Done) {
						numberOfGoRoutines = runtime.NumGoroutine()
						time.Sleep(sleepDuration)
						done <- true
					}, types.GenerateCodeLocation(0), timeoutDuration)
				})

				It("should run the function as a goroutine", func() {
					initialNumberOfGoRoutines := runtime.NumGoroutine()
					outcome, failure := node.run()

					Ω(outcome).Should(Equal(runOutcomeCompleted))
					Ω(failure).Should(BeZero())

					Ω(numberOfGoRoutines).Should(Equal(initialNumberOfGoRoutines + 1))
				})

				Context("when the function takes longer than the timeout", func() {
					BeforeEach(func() {
						sleepDuration = time.Duration(0.002 * float64(time.Second))
						timeoutDuration = time.Duration(0.001 * float64(time.Second))
					})

					It("should timeout", func() {
						outcome, failure := node.run()
						Ω(outcome).Should(Equal(runOutcomeTimedOut))
						Ω(failure.message).Should(Equal("Timed out"))
						Ω(failure.codeLocation).Should(Equal(node.codeLocation))
					})
				})
//.........这里部分代码省略.........
开发者ID:lichia,项目名称:hydra,代码行数:101,代码来源:runnable_node_test.go

示例8: 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, BeforeEach 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, types.GenerateCodeLocation(1), parseTimeout(timeout...))
	return true
}
开发者ID:lichia,项目名称:hydra,代码行数:9,代码来源:ginkgo.go

示例9: XMeasure

//You can mark Maeasurements as pending using XMeasure
func XMeasure(text string, _ ...interface{}) bool {
	globalSuite.pushMeasureNode(text, func(b Benchmarker) {}, flagTypePending, types.GenerateCodeLocation(1), 0)
	return true
}
开发者ID:lichia,项目名称:hydra,代码行数:5,代码来源:ginkgo.go

示例10: FMeasure

//You can focus individual Measures using FMeasure
func FMeasure(text string, body func(Benchmarker), samples int) bool {
	globalSuite.pushMeasureNode(text, body, flagTypeFocused, types.GenerateCodeLocation(1), samples)
	return true
}
开发者ID:lichia,项目名称:hydra,代码行数:5,代码来源:ginkgo.go

示例11: XIt

//You can mark Its as pending using XIt
func XIt(text string, _ ...interface{}) bool {
	globalSuite.pushItNode(text, func() {}, flagTypePending, types.GenerateCodeLocation(1), 0)
	return true
}
开发者ID:lichia,项目名称:hydra,代码行数:5,代码来源:ginkgo.go

示例12: FIt

//You can focus individual Its using FIt
func FIt(text string, body interface{}, timeout ...float64) bool {
	globalSuite.pushItNode(text, body, flagTypeFocused, types.GenerateCodeLocation(1), parseTimeout(timeout...))
	return true
}
开发者ID:lichia,项目名称:hydra,代码行数:5,代码来源:ginkgo.go

示例13: 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, flagTypePending, types.GenerateCodeLocation(1))
	return true
}
开发者ID:lichia,项目名称:hydra,代码行数:5,代码来源:ginkgo.go

示例14: FDescribe

//You can focus the tests within a describe block using FDescribe
func FDescribe(text string, body func()) bool {
	globalSuite.pushContainerNode(text, body, flagTypeFocused, types.GenerateCodeLocation(1))
	return true
}
开发者ID:lichia,项目名称:hydra,代码行数:5,代码来源:ginkgo.go

示例15: init

func init() {
	Describe("Suite", func() {
		var (
			specSuite *suite
			fakeT     *fakeTestingT
			fakeR     *reporters.FakeReporter
		)

		BeforeEach(func() {
			fakeT = &fakeTestingT{}
			fakeR = reporters.NewFakeReporter()
			specSuite = newSuite()
		})

		Describe("running a suite", func() {
			var (
				runOrder          []string
				randomizeAllSpecs bool
				randomSeed        int64
				focusString       string
				parallelNode      int
				parallelTotal     int
				runResult         bool
			)

			var f = func(runText string) func() {
				return func() {
					runOrder = append(runOrder, runText)
				}
			}

			BeforeEach(func() {
				randomizeAllSpecs = false
				randomSeed = 11
				parallelNode = 1
				parallelTotal = 1
				focusString = ""

				runOrder = make([]string, 0)
				specSuite.pushBeforeEachNode(f("top BE"), types.GenerateCodeLocation(0), 0)
				specSuite.pushJustBeforeEachNode(f("top JBE"), types.GenerateCodeLocation(0), 0)
				specSuite.pushAfterEachNode(f("top AE"), types.GenerateCodeLocation(0), 0)

				specSuite.pushContainerNode("container", func() {
					specSuite.pushBeforeEachNode(f("BE"), types.GenerateCodeLocation(0), 0)
					specSuite.pushJustBeforeEachNode(f("JBE"), types.GenerateCodeLocation(0), 0)
					specSuite.pushAfterEachNode(f("AE"), types.GenerateCodeLocation(0), 0)
					specSuite.pushItNode("it", f("IT"), flagTypeNone, types.GenerateCodeLocation(0), 0)

					specSuite.pushContainerNode("inner container", func() {
						specSuite.pushItNode("inner it", f("inner IT"), flagTypeNone, types.GenerateCodeLocation(0), 0)
					}, flagTypeNone, types.GenerateCodeLocation(0))
				}, flagTypeNone, types.GenerateCodeLocation(0))

				specSuite.pushContainerNode("container 2", func() {
					specSuite.pushBeforeEachNode(f("BE 2"), types.GenerateCodeLocation(0), 0)
					specSuite.pushItNode("it 2", f("IT 2"), flagTypeNone, types.GenerateCodeLocation(0), 0)
				}, flagTypeNone, types.GenerateCodeLocation(0))

				specSuite.pushItNode("top level it", f("top IT"), flagTypeNone, types.GenerateCodeLocation(0), 0)
			})

			JustBeforeEach(func() {
				runResult = specSuite.run(fakeT, "suite description", []Reporter{fakeR}, config.GinkgoConfigType{
					RandomSeed:        randomSeed,
					RandomizeAllSpecs: randomizeAllSpecs,
					FocusString:       focusString,
					ParallelNode:      parallelNode,
					ParallelTotal:     parallelTotal,
				})
			})

			It("provides the config and suite description to the reporter", func() {
				Ω(fakeR.Config.RandomSeed).Should(Equal(int64(randomSeed)))
				Ω(fakeR.Config.RandomizeAllSpecs).Should(Equal(randomizeAllSpecs))
				Ω(fakeR.BeginSummary.SuiteDescription).Should(Equal("suite description"))
			})

			It("provides information about the current test", func() {
				description := CurrentGinkgoTestDescription()
				Ω(description.ComponentTexts).Should(Equal([]string{"Suite", "running a suite", "provides information about the current test"}))
				Ω(description.FullTestText).Should(Equal("Suite running a suite provides information about the current test"))
				Ω(description.TestText).Should(Equal("provides information about the current test"))
				Ω(description.IsMeasurement).Should(BeFalse())
				Ω(description.FileName).Should(ContainSubstring("suite_test.go"))
				Ω(description.LineNumber).Should(BeNumerically(">", 50))
				Ω(description.LineNumber).Should(BeNumerically("<", 150))
			})

			Measure("should run measurements", func(b Benchmarker) {
				r := rand.New(rand.NewSource(time.Now().UnixNano()))

				runtime := b.Time("sleeping", func() {
					sleepTime := time.Duration(r.Float64() * 0.01 * float64(time.Second))
					time.Sleep(sleepTime)
				})
				Ω(runtime.Seconds()).Should(BeNumerically("<=", 0.012))
				Ω(runtime.Seconds()).Should(BeNumerically(">=", 0))

				randomValue := r.Float64() * 10.0
//.........这里部分代码省略.........
开发者ID:lichia,项目名称:hydra,代码行数:101,代码来源:suite_test.go


注:本文中的github.com/innotech/hydra/vendors/github.com/onsi/ginkgo/types.GenerateCodeLocation函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。