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

Improve test coverage calculation #102

Merged
merged 1 commit into from
Jul 8, 2024
Merged

Improve test coverage calculation #102

merged 1 commit into from
Jul 8, 2024

Conversation

dfed
Copy link
Owner

@dfed dfed commented Jul 7, 2024

So our test coverage has been cheating a bit – we were including our Tests/ code in our coverage numbers. Now we aren't. To get us back to 99.5+% coverage I added a few more tests. I also mucked with the shape of some lines to make it easier to get coverage – I'm not proud of it... but... here we are.

@dfed dfed self-assigned this Jul 7, 2024
@dfed dfed force-pushed the dfed--test-coverage branch 2 times, most recently from ed6c7e6 to 1b26c48 Compare July 7, 2024 22:56
Copy link

codecov bot commented Jul 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.66%. Comparing base (90c8b98) to head (cdd9968).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #102      +/-   ##
==========================================
- Coverage   99.67%   99.66%   -0.01%     
==========================================
  Files          47       33      -14     
  Lines       11564     2678    -8886     
==========================================
- Hits        11526     2669    -8857     
+ Misses         38        9      -29     
Files Coverage Δ
...ces/SafeDICore/Errors/FixableInjectableError.swift 100.00% <100.00%> (+18.18%) ⬆️
...s/SafeDICore/Errors/FixableInstantiableError.swift 100.00% <100.00%> (+5.33%) ⬆️
...DICore/Extensions/ImportDeclSyntaxExtensions.swift 100.00% <100.00%> (+5.55%) ⬆️
...afeDICore/Generators/DependencyTreeGenerator.swift 100.00% <100.00%> (+2.28%) ⬆️
Sources/SafeDICore/Models/TypeDescription.swift 99.14% <100.00%> (+1.27%) ⬆️
Sources/SafeDICore/Visitors/FileVisitor.swift 100.00% <100.00%> (ø)

... and 18 files with indirect coverage changes

@dfed dfed force-pushed the dfed--test-coverage branch 6 times, most recently from a9446d6 to 2d00400 Compare July 7, 2024 23:29
@dfed dfed marked this pull request as ready for review July 7, 2024 23:36
@@ -23,14 +23,11 @@ import SwiftSyntax
extension ImportDeclSyntax {
// MARK: Public

public var asImportStatement: ImportStatement? {
guard let moduleName = path.first?.name.text else {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we really don't need to guard here – if our code-gen is running then our build succeeded, which means we don't have any dangling import statements.

@@ -41,38 +41,32 @@ public enum FixableInjectableError: DiagnosticError {
// MARK: - InjectableDiagnosticMessage

private struct InjectableDiagnosticMessage: DiagnosticMessage {
var diagnosticID: MessageID {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these computed properties were never executed in tests. There's no good way to do so as part of an integration test. So now we're just creating them up-front.

@@ -105,7 +105,9 @@ public final class DependencyTreeGenerator {
.map(\.asSource)
.joined(separator: " -> "))
"""
}.joined(separator: "\n"))
}
.sorted()
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we didn't have a test for multiple fulfillable properties! once I added one, it became clear that the error wasn't stable, so we now sort here.

@@ -136,11 +138,7 @@ public final class DependencyTreeGenerator {
}
}

struct UnfulfillableProperty: Hashable, Comparable {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need the property to be comparable because the generated error is already comparable and we sort that

@@ -153,32 +151,25 @@ public final class DependencyTreeGenerator {
private let typeDescriptionToFulfillingInstantiableMap: [TypeDescription: Instantiable]
private var rootScopeGenerators: [ScopeGenerator] {
get throws {
if let _rootScopeGenerators {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we never actually used the cached object. so now it's gone.

Comment on lines -269 to -271
// We can't find an instantiable for this type.
// This is bad, but we handle this error in `validateReachableTypeDescriptions()`.
return
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was impossible to hit, and we already have validateReachableTypeDescriptions() to handle less egregious cases. So I folded in this guard let with the one below

@@ -222,28 +222,6 @@ public enum TypeDescription: Codable, Hashable, Comparable, Sendable {
}
}

var isUnknown: Bool {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was only used in tests – so I moved it to tests

@@ -423,8 +401,6 @@ extension ExprSyntax {
if memberAccessExpr.declName.baseName.text == "self" {
if let base = memberAccessExpr.base {
return base.typeDescription
} else {
return .unknown(text: memberAccessExpr.trimmedDescription)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unreachable

@@ -440,8 +416,6 @@ extension ExprSyntax {
generics: []
)
}
} else {
return .unknown(text: memberAccessExpr.trimmedDescription)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unreachable

@@ -508,8 +482,6 @@ extension ExprSyntax {
doesThrow: arrow.effectSpecifiers?.throwsSpecifier != nil,
returnType: returnType.typeDescription
)
} else {
return .unknown(text: trimmedDescription)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unreachable

}
return .unknown(text: trimmedDescription)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hate fall through like this but... it does work

@@ -2685,7 +2685,7 @@ final class SafeDIToolCodeGenerationTests: XCTestCase {
}
""",
"""
import Foundation
@_implementationOnly import Foundation
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

helps exercise some of our import handling code we previously were not

@dfed dfed force-pushed the dfed--test-coverage branch from cdd9968 to af4c468 Compare July 7, 2024 23:56
@dfed dfed merged commit 5948f90 into main Jul 8, 2024
12 checks passed
@dfed dfed deleted the dfed--test-coverage branch July 8, 2024 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant