Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

teamcity reporter: output location of test failure #626

Merged
merged 1 commit into from
Nov 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions reporters/teamcity_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func (reporter *TeamCityReporter) handleSetupSummary(name string, setupSummary *
if setupSummary.State != types.SpecStatePassed {
testName := escape(name)
fmt.Fprintf(reporter.writer, "%s[testStarted name='%s']\n", messageId, testName)
message := escape(setupSummary.Failure.ComponentCodeLocation.String())
details := escape(setupSummary.Failure.Message)
message := reporter.failureMessage(setupSummary.Failure)
details := reporter.failureDetails(setupSummary.Failure)
fmt.Fprintf(reporter.writer, "%s[testFailed name='%s' message='%s' details='%s']\n", messageId, testName, message, details)
durationInMilliseconds := setupSummary.RunTime.Seconds() * 1000
fmt.Fprintf(reporter.writer, "%s[testFinished name='%s' duration='%v']\n", messageId, testName, durationInMilliseconds)
Expand All @@ -71,8 +71,8 @@ func (reporter *TeamCityReporter) SpecDidComplete(specSummary *types.SpecSummary
fmt.Fprintf(reporter.writer, "%s[testPassed name='%s' details='%s']\n", messageId, testName, details)
}
if specSummary.State == types.SpecStateFailed || specSummary.State == types.SpecStateTimedOut || specSummary.State == types.SpecStatePanicked {
message := escape(specSummary.Failure.ComponentCodeLocation.String())
details := escape(specSummary.Failure.Message)
message := reporter.failureMessage(specSummary.Failure)
details := reporter.failureDetails(specSummary.Failure)
fmt.Fprintf(reporter.writer, "%s[testFailed name='%s' message='%s' details='%s']\n", messageId, testName, message, details)
}
if specSummary.State == types.SpecStateSkipped || specSummary.State == types.SpecStatePending {
Expand All @@ -87,6 +87,14 @@ func (reporter *TeamCityReporter) SpecSuiteDidEnd(summary *types.SuiteSummary) {
fmt.Fprintf(reporter.writer, "%s[testSuiteFinished name='%s']\n", messageId, reporter.testSuiteName)
}

func (reporter *TeamCityReporter) failureMessage(failure types.SpecFailure) string {
return escape(failure.ComponentCodeLocation.String())
}

func (reporter *TeamCityReporter) failureDetails(failure types.SpecFailure) string {
return escape(fmt.Sprintf("%s\n%s", failure.Message, failure.Location.String()))
}

func escape(output string) string {
output = strings.Replace(output, "|", "||", -1)
output = strings.Replace(output, "'", "|'", -1)
Expand Down
22 changes: 16 additions & 6 deletions reporters/teamcity_reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ var _ = Describe("TeamCity Reporter", func() {
Failure: types.SpecFailure{
Message: "failed to setup\n",
ComponentCodeLocation: codelocation.New(0),
Location: codelocation.New(2),
},
}
reporter.BeforeSuiteDidRun(beforeSuite)
Expand All @@ -97,9 +98,11 @@ var _ = Describe("TeamCity Reporter", func() {
expected := fmt.Sprintf(
"##teamcity[testSuiteStarted name='Foo|'s test suite']\n"+
"##teamcity[testStarted name='BeforeSuite']\n"+
"##teamcity[testFailed name='BeforeSuite' message='%s' details='failed to setup|n']\n"+
"##teamcity[testFailed name='BeforeSuite' message='%s' details='failed to setup|n|n%s']\n"+
"##teamcity[testFinished name='BeforeSuite' duration='3000']\n"+
"##teamcity[testSuiteFinished name='Foo|'s test suite']\n", beforeSuite.Failure.ComponentCodeLocation.String(),
"##teamcity[testSuiteFinished name='Foo|'s test suite']\n",
beforeSuite.Failure.ComponentCodeLocation.String(),
beforeSuite.Failure.Location.String(),
)
Ω(actual).Should(Equal(expected))
})
Expand All @@ -115,6 +118,7 @@ var _ = Describe("TeamCity Reporter", func() {
Failure: types.SpecFailure{
Message: "failed to setup\n",
ComponentCodeLocation: codelocation.New(0),
Location: codelocation.New(2),
},
}
reporter.AfterSuiteDidRun(afterSuite)
Expand All @@ -131,9 +135,11 @@ var _ = Describe("TeamCity Reporter", func() {
expected := fmt.Sprintf(
"##teamcity[testSuiteStarted name='Foo|'s test suite']\n"+
"##teamcity[testStarted name='AfterSuite']\n"+
"##teamcity[testFailed name='AfterSuite' message='%s' details='failed to setup|n']\n"+
"##teamcity[testFailed name='AfterSuite' message='%s' details='failed to setup|n|n%s']\n"+
"##teamcity[testFinished name='AfterSuite' duration='3000']\n"+
"##teamcity[testSuiteFinished name='Foo|'s test suite']\n", afterSuite.Failure.ComponentCodeLocation.String(),
"##teamcity[testSuiteFinished name='Foo|'s test suite']\n",
afterSuite.Failure.ComponentCodeLocation.String(),
afterSuite.Failure.Location.String(),
)
Ω(actual).Should(Equal(expected))
})
Expand All @@ -158,6 +164,7 @@ var _ = Describe("TeamCity Reporter", func() {
RunTime: 5 * time.Second,
Failure: types.SpecFailure{
ComponentCodeLocation: codelocation.New(0),
Location: codelocation.New(2),
Message: "I failed",
},
}
Expand All @@ -176,9 +183,12 @@ var _ = Describe("TeamCity Reporter", func() {
expected :=
fmt.Sprintf("##teamcity[testSuiteStarted name='Foo|'s test suite']\n"+
"##teamcity[testStarted name='A B C']\n"+
"##teamcity[testFailed name='A B C' message='%s' details='I failed']\n"+
"##teamcity[testFailed name='A B C' message='%s' details='I failed|n%s']\n"+
"##teamcity[testFinished name='A B C' duration='5000']\n"+
"##teamcity[testSuiteFinished name='Foo|'s test suite']\n", spec.Failure.ComponentCodeLocation.String())
"##teamcity[testSuiteFinished name='Foo|'s test suite']\n",
spec.Failure.ComponentCodeLocation.String(),
spec.Failure.Location.String(),
)
Ω(actual).Should(Equal(expected))
})
})
Expand Down