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