-
Notifications
You must be signed in to change notification settings - Fork 108
Show the number of test cases that ran at the end of a test #972
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
Show the number of test cases that ran at the end of a test #972
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for opening this PR! It would be a good idea to familiarize yourself with the existing code in Event.HumanReadableOutputRecorder.swift
and get a feel for how it works and the existing mechanisms we use for gathering data during test runs.
return " with \(numberOfArguments) " + (numberOfArguments > 1 ? "arguments" : "argument") | ||
private func _includeNumberOfTestCases(for test: Test, verbose: Int) -> String { | ||
if verbose == 2 && !test.isSuite { // very verbose | ||
let testCasesCount = test.testCases?.count(where: { _ in true }) ?? 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling testCases
here will produce a second sequence of test cases, which makes getting the number of test cases an O(n) operation instead of O(1). What we would normally do is keep a running count of test cases in the TestData
structure, incrementing it for each .testCaseStarted
event.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, it helps me understand the way you guys think 🙏.
Honestly, it was my first idea; however, I thought it is the same due to the fact that O(n) gets distributed among each test run and also adds a negligible amount of miscalculation to the compute time (because it happens after the start instant as well as it adds 8 bytes of additional data to the test data). For those reasons, I went with the second solution.
I fixed the issue.
let numberOfArguments = _numberOfArguments(for: test.testCases) | ||
return " with \(numberOfArguments) " + (numberOfArguments > 1 ? "arguments" : "argument") | ||
private func _includeNumberOfTestCases(for test: Test, verbose: Int) -> String { | ||
if verbose == 2 && !test.isSuite { // very verbose |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably mean >= 2
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if you want to count test cases, you should use test.isParameterized
, not !test.isSuite
, since it doesn't make sense to count test cases for a non-parameterized test function either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
private func _includeNumberOfTestCases(for test: Test, verbose: Int) -> String { | ||
if verbose == 2 && !test.isSuite { // very verbose | ||
let testCasesCount = test.testCases?.count(where: { _ in true }) ?? 0 | ||
return " with \(testCasesCount) " + (testCasesCount > 1 ? "test cases" : "test case") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a helper function for pluralizing English nouns (used elsewhere in this file.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, applied. 🙏
/// - verbose: If the level is very verbose, a detailed description is returned. | ||
/// | ||
/// - Returns: A string describing the number of arguments in the test cases, or an empty string if it's not very verbose level. | ||
/// - Returns: A string describing the number of argument(s) in the test cases, or an empty string if it's not very verbose level. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation comments (but not code) should wrap at 80 columns. This helps give readers a sense of how long the documentation will be when rendered with DocC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applied, sorry for not double-checking it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For more details see the Style Guide.
…eedback - use counting instead of ternary operator - fixing char limit per row - fixing verbosity condition check - check if test is parameterized
… of after test ends
|
||
case .testCaseStarted: | ||
guard verbosity >= 2 else { break } | ||
let id: [String] = if let test { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't check verbosity in this first switch
intentionally so that the data we collect is always comprehensive. The second switch
below checks verbosity before producing any messages.
test
will never be nil
for this event, and .testStarted
will always be recorded before .testCaseStarted
, so you can just write:
case .testCaseStarted:
let test = test!
context.testData[test.id.keyPathRepresentation]?.testCasesCount += 1
/// - Returns: A string describing the number of test cases in the test, | ||
/// or an empty string if it's not very verbose level. | ||
/// | ||
private func _includeNumberOfTestCasesIfNeeded( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably don't need this helper function and can just construct the string in place in the .testEnded
handler below.
@@ -366,18 +404,21 @@ extension Event.HumanReadableOutputRecorder { | |||
let testData = testDataGraph?.value ?? .init(startInstant: instant) | |||
let issues = _issueCounts(in: testDataGraph) | |||
let duration = testData.startInstant.descriptionOfDuration(to: instant) | |||
let testCasesCountMessage = _includeNumberOfTestCasesIfNeeded(test.isParameterized, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, you can probably just write:
let testCasesCount = if verbosity >= 2 && test.isParameterized {
" with \(testData.testCasesCount.counting("test case"))"
} else {
""
}
("Message" has a domain-specific meaning in this file, which is why I renamed this variable in my example above.)
@grynspan Thank you for being patience with me. I've applied all the requested changes—please review and resolve if everything looks good. Also, I'll make an effort to participate more in code reviews and go through other pull requests to minimize trivial questions in the future. @stmontgomery Thank you for your support as well. 🙏 |
@@ -146,6 +149,7 @@ extension Event.HumanReadableOutputRecorder { | |||
|
|||
return (errorIssueCount, warningIssueCount, knownIssueCount, totalIssueCount, description) | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: stray newline? :)
@@ -566,3 +610,4 @@ struct EventRecorderTests { | |||
} | |||
} | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: stray newline?
@swift-ci test |
@swift-ci test |
@@ -366,18 +373,23 @@ extension Event.HumanReadableOutputRecorder { | |||
let testData = testDataGraph?.value ?? .init(startInstant: instant) | |||
let issues = _issueCounts(in: testDataGraph) | |||
let duration = testData.startInstant.descriptionOfDuration(to: instant) | |||
let testCasesCount = if verbosity >= 2 && test.isParameterized { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stmontgomery What do you think about the required verbosity here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should always include this, and not conditionalize it on verbosity
. It's only a few extra words, not adding any additional lines, and I think it's a generally useful enhancement. The current summary text always includes a count of the issues recorded regardless of verbosity, and this isn't all that different.
(We should continue to check test.isParameterized
, though.)
("f()", #".* Test f\(\) failed after .*"# , 0), | ||
("f()", #".* Test f\(\) failed after .*"# , 2), | ||
("d(_:)", #".* Test d\(_:\) with .+ test cases passed after.*"# , 2), | ||
("PredictablyFailingTests", #".* Suite PredictablyFailingTests failed after .*"# , 1), | ||
("PredictablyFailingTests", #".* Suite PredictablyFailingTests failed after .*"# , 2), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: whitespace
("f()", #".* Test f\(\) failed after .*"# , 0), | |
("f()", #".* Test f\(\) failed after .*"# , 2), | |
("d(_:)", #".* Test d\(_:\) with .+ test cases passed after.*"# , 2), | |
("PredictablyFailingTests", #".* Suite PredictablyFailingTests failed after .*"# , 1), | |
("PredictablyFailingTests", #".* Suite PredictablyFailingTests failed after .*"# , 2), | |
("f()", #".* Test f\(\) failed after .*"#, 0), | |
("f()", #".* Test f\(\) failed after .*"#, 2), | |
("d(_:)", #".* Test d\(_:\) with .+ test cases passed after.*"#, 2), | |
("PredictablyFailingTests", #".* Suite PredictablyFailingTests failed after .*"#, 1), | |
("PredictablyFailingTests", #".* Suite PredictablyFailingTests failed after .*"#, 2), |
@@ -62,6 +62,9 @@ extension Event { | |||
|
|||
/// The number of known issues recorded for the test. | |||
var knownIssueCount = 0 | |||
|
|||
/// The number of test cases for the test. | |||
var testCasesCount: Int = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can omit the explicit type since this isn't a public
property, to match prevailing style
var testCasesCount: Int = 0 | |
var testCasesCount = 0 |
@swift-ci please test |
|
||
@available(_regexAPI, *) | ||
@Test( | ||
"number of arguments based on verbosity level at the end of test run", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The display name of this test can be rephrased now to not mention verbosity. I'd also prefer if we could capitalize the first word to match prevailing style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple more style comments but besides that I think this is ready to land. Thanks @hrayatnia!
@swift-ci please test |
Motivation:
To have the number of test cases at the end of the test in for parameterized tests, so the logs don’t easily get buried.
Modifications:
Log the number of test cases for parameterized tests at the end of a test.
Result:
If the user runs the parameterized tests, an extra piece of information (with * test cases) would get bound to the end log.
Resolves #943.
Resolves rdar://144250498.
Checklist: