Skip to content

Commit dd8d717

Browse files
Add additional checks to testAllProposals test
- Test all top level properties for equality - Test that generated JSON is the same - This should catch all changes including: - Removing optional properties - Unexpected changes in formatting - Add convenience method to write JSON files out for diffing
1 parent 84e5df1 commit dd8d717

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

Tests/ExtractionTests/ExtractionTests.swift

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ final class ExtractionTests: XCTestCase {
3030
let string = try XCTUnwrap(String(data: data, encoding: .utf8), "Unable to make string from contents of \(name).\(ext)")
3131
return string
3232
}
33+
34+
// Convenience to write expected and actual metadata files to disk for comparison in a diff tool
35+
func writeJSONFilesToPath(expected: Data, actual: Data, path: String, prefix: String? = nil) throws {
36+
let filePrefix: String
37+
if let prefix { filePrefix = "\(prefix)-" } else { filePrefix = "" }
38+
try expected.write(to: FileUtilities.expandedAndStandardizedURL(for: path).appending(path: "\(filePrefix)expected.json"))
39+
try actual.write(to: FileUtilities.expandedAndStandardizedURL(for: path).appending(path: "\(filePrefix)actual.json"))
40+
}
3341

3442
func testAllProposals() async throws {
3543

@@ -39,9 +47,15 @@ final class ExtractionTests: XCTestCase {
3947
let expectedResultsByProposalID = expectedResults.proposals.reduce(into: [:]) { $0[$1.id] = $1 }
4048

4149
let extractedEvolutionMetadata = try await EvolutionMetadataExtractor.extractEvolutionMetadata(for: extractionJob)
42-
50+
51+
// Check top-level properties
52+
XCTAssertEqual(extractedEvolutionMetadata.commit, expectedResults.commit)
53+
XCTAssertEqual(extractedEvolutionMetadata.creationDate, expectedResults.creationDate)
4354
XCTAssertEqual(extractedEvolutionMetadata.implementationVersions, expectedResults.implementationVersions)
55+
XCTAssertEqual(extractedEvolutionMetadata.schemaVersion, expectedResults.schemaVersion)
56+
XCTAssertEqual(extractedEvolutionMetadata.toolVersion, expectedResults.toolVersion)
4457

58+
// Check proposals
4559
for newProposal in extractedEvolutionMetadata.proposals {
4660
let id = newProposal.id
4761
guard !id.isEmpty else {
@@ -55,6 +69,16 @@ final class ExtractionTests: XCTestCase {
5569

5670
XCTAssertEqual(newProposal, sourceProposal)
5771
}
72+
73+
// Check the generated JSON to catch issues such as removing optional properties from the schema
74+
let expectedResultsURL = snapshotURL.appending(path: "expected-results.json")
75+
let expectedJSONData = try Data(contentsOf: expectedResultsURL)
76+
let actualJSONData = try extractedEvolutionMetadata.jsonRepresentation
77+
XCTAssertEqual(expectedJSONData, actualJSONData)
78+
79+
// Uncomment to write full JSON files out to compare in a diff tool
80+
// try writeJSONFilesToPath(expected: expectedJSONData, actual: actualJSONData, path: "~/Desktop")
81+
5882
}
5983

6084
func testWarningsAndErrors() async throws {

0 commit comments

Comments
 (0)