result.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package contract
  2. import (
  3. "github.com/smartystreets/goconvey/convey/reporting"
  4. "github.com/smartystreets/goconvey/web/server/messaging"
  5. )
  6. type Package struct {
  7. Path string
  8. Name string
  9. Ignored bool
  10. Disabled bool
  11. BuildTags []string
  12. TestArguments []string
  13. Error error
  14. Output string
  15. Result *PackageResult
  16. HasImportCycle bool
  17. }
  18. func NewPackage(folder *messaging.Folder, name string, hasImportCycle bool) *Package {
  19. self := new(Package)
  20. self.Path = folder.Path
  21. self.Name = name
  22. self.Result = NewPackageResult(self.Name)
  23. self.Ignored = folder.Ignored
  24. self.Disabled = folder.Disabled
  25. self.BuildTags = folder.BuildTags
  26. self.TestArguments = folder.TestArguments
  27. self.HasImportCycle = hasImportCycle
  28. return self
  29. }
  30. func (self *Package) Active() bool {
  31. return !self.Disabled && !self.Ignored
  32. }
  33. func (self *Package) HasUsableResult() bool {
  34. return self.Active() && (self.Error == nil || (self.Output != ""))
  35. }
  36. type CompleteOutput struct {
  37. Packages []*PackageResult
  38. Revision string
  39. Paused bool
  40. }
  41. var ( // PackageResult.Outcome values:
  42. Ignored = "ignored"
  43. Disabled = "disabled"
  44. Passed = "passed"
  45. Failed = "failed"
  46. Panicked = "panicked"
  47. BuildFailure = "build failure"
  48. NoTestFiles = "no test files"
  49. NoTestFunctions = "no test functions"
  50. NoGoFiles = "no go code"
  51. TestRunAbortedUnexpectedly = "test run aborted unexpectedly"
  52. )
  53. type PackageResult struct {
  54. PackageName string
  55. Elapsed float64
  56. Coverage float64
  57. Outcome string
  58. BuildOutput string
  59. TestResults []TestResult
  60. }
  61. func NewPackageResult(packageName string) *PackageResult {
  62. self := new(PackageResult)
  63. self.PackageName = packageName
  64. self.TestResults = []TestResult{}
  65. self.Coverage = -1
  66. return self
  67. }
  68. type TestResult struct {
  69. TestName string
  70. Elapsed float64
  71. Passed bool
  72. Skipped bool
  73. File string
  74. Line int
  75. Message string
  76. Error string
  77. Stories []reporting.ScopeResult
  78. RawLines []string `json:",omitempty"`
  79. }
  80. func NewTestResult(testName string) *TestResult {
  81. self := new(TestResult)
  82. self.Stories = []reporting.ScopeResult{}
  83. self.RawLines = []string{}
  84. self.TestName = testName
  85. return self
  86. }