@@ -237,6 +237,8 @@ package enum CoverageFormat: String, ExpressibleByArgument, CaseIterable, Compar
237
237
}
238
238
}
239
239
240
+ extension CoverageFormat : Encodable { }
241
+
240
242
enum CoveragePrintPathMode : String , ExpressibleByArgument , CaseIterable {
241
243
case json
242
244
case text
@@ -390,7 +392,7 @@ package func getOutputDir(from content: String) throws -> AbsolutePath? {
390
392
391
393
return returnValue
392
394
}
393
- package struct CoverageFormatOutput {
395
+ package struct CoverageFormatOutput : Encodable {
394
396
private var _underlying : [ CoverageFormat : AbsolutePath ]
395
397
396
398
package init ( ) {
@@ -1104,13 +1106,13 @@ extension SwiftTestCommand {
1104
1106
formats: [ CoverageFormat ] ,
1105
1107
printMode: CoveragePrintPathMode ,
1106
1108
) async throws {
1107
- var data = [ CoverageFormat : AbsolutePath] ( )
1109
+ var coverageData = [ CoverageFormat : AbsolutePath] ( )
1108
1110
for format in formats {
1109
1111
let config = try await self . getCodeCoverageConfiguration ( swiftCommandState, format: format)
1110
- data [ format] = config. outputDir
1112
+ coverageData [ format] = config. outputDir
1111
1113
}
1112
1114
1113
- let coverageOutput = CoverageFormatOutput ( data: data )
1115
+ let coverageOutput = CoverageFormatOutput ( data: coverageData )
1114
1116
1115
1117
switch printMode {
1116
1118
case . json:
@@ -1120,6 +1122,20 @@ extension SwiftTestCommand {
1120
1122
let textOutput = coverageOutput. encodeAsText ( )
1121
1123
print ( textOutput)
1122
1124
}
1125
+
1126
+ print ( " ----------------------- " )
1127
+ let data : Data
1128
+ switch printMode {
1129
+ case . json:
1130
+ let encoder = JSONEncoder . makeWithDefaults ( )
1131
+ encoder. keyEncodingStrategy = . convertToSnakeCase
1132
+ data = try encoder. encode ( coverageOutput)
1133
+ case . text:
1134
+ var encoder = PlainTextEncoder ( )
1135
+ encoder. formattingOptions = [ . prettyPrinted]
1136
+ data = try encoder. encode ( coverageOutput)
1137
+ }
1138
+ print ( String ( decoding: data, as: UTF8 . self) )
1123
1139
}
1124
1140
}
1125
1141
0 commit comments