Skip to content

Commit 7db972b

Browse files
committed
Addressed an issue with testImageLogging() which prevented it from passing on some Macs.
This allows PlaygroundLogger's test suite to pass on macOS, iOS Simulator, and tvOS Simulator.
1 parent f2aa282 commit 7db972b

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

PlaygroundLogger/PlaygroundLoggerTests/LegacyPlaygroundLoggerTests.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,21 @@ class LegacyPlaygroundLoggerTests: XCTestCase {
341341
XCTFail("Decoded payload is not an image")
342342
return
343343
}
344-
XCTAssertEqual(payloadImage.size, size)
344+
345+
let expectedSize: CGSize
346+
#if os(macOS)
347+
// On macOS, the image we create above is rendered at a scale factor. We get the best-available scale factor from all screens and use that when creating our expectation.
348+
let scaleFactor = NSScreen.screens.reduce(1.0) { previousBestScaleFactor, screen in
349+
return max(previousBestScaleFactor, screen.backingScaleFactor)
350+
}
351+
352+
expectedSize = CGSize(width: size.width * scaleFactor, height: size.height * scaleFactor)
353+
#elseif os(iOS) || os(tvOS)
354+
// On iOS and tvOS, we expect the output image to be the same size as the input image.
355+
expectedSize = size
356+
#endif
357+
358+
XCTAssertEqual(payloadImage.size, expectedSize)
345359
}
346360

347361
// testSpriteKitLogging() is excluded, as it cannot be trivially ported.

0 commit comments

Comments
 (0)