Skip to content

Commit db774c6

Browse files
committed
[PlaygroundLogger] Added a test of logging a nil implicitly-unwrapped optional.
In Swift versions where ImplicitlyUnwrappedOptional is a separate type from Optional, logging crashes as the runtime tries to implicitly unwrap the optional. This test ensures that this behavior is covered appropriately.
1 parent e7d664f commit db774c6

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

PlaygroundLogger/PlaygroundLogger.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@
7272
5E27568F1FCF964400B69C83 /* NSBitmapImageRep+CustomOpaqueLoggable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E27568E1FCF964400B69C83 /* NSBitmapImageRep+CustomOpaqueLoggable.swift */; };
7373
5E2756911FCF967300B69C83 /* NSBitmapImageRep+OpaqueImageRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2756901FCF967300B69C83 /* NSBitmapImageRep+OpaqueImageRepresentable.swift */; };
7474
5E2756941FCF9CB000B69C83 /* SpriteKitOpaqueLoggable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E2756931FCF9CB000B69C83 /* SpriteKitOpaqueLoggable.swift */; };
75+
5E48E0AA2042925B00C7712D /* LogEntryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E48E0A92042925B00C7712D /* LogEntryTests.swift */; };
76+
5E48E0AB2042925B00C7712D /* LogEntryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E48E0A92042925B00C7712D /* LogEntryTests.swift */; };
77+
5E48E0AC2042925B00C7712D /* LogEntryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E48E0A92042925B00C7712D /* LogEntryTests.swift */; };
7578
5E4AF1AF1FDDC12A00B7C9D9 /* LegacyEntrypoints.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E4AF1AE1FDDC12A00B7C9D9 /* LegacyEntrypoints.swift */; };
7679
5E5D77802040BD7D00EBC3A9 /* LogPolicyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E5D777F2040BD7D00EBC3A9 /* LogPolicyTests.swift */; };
7780
5E5D77812040BD7D00EBC3A9 /* LogPolicyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E5D777F2040BD7D00EBC3A9 /* LogPolicyTests.swift */; };
@@ -251,6 +254,7 @@
251254
5E27568E1FCF964400B69C83 /* NSBitmapImageRep+CustomOpaqueLoggable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSBitmapImageRep+CustomOpaqueLoggable.swift"; sourceTree = "<group>"; };
252255
5E2756901FCF967300B69C83 /* NSBitmapImageRep+OpaqueImageRepresentable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSBitmapImageRep+OpaqueImageRepresentable.swift"; sourceTree = "<group>"; };
253256
5E2756931FCF9CB000B69C83 /* SpriteKitOpaqueLoggable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpriteKitOpaqueLoggable.swift; sourceTree = "<group>"; };
257+
5E48E0A92042925B00C7712D /* LogEntryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogEntryTests.swift; sourceTree = "<group>"; };
254258
5E4AF1AE1FDDC12A00B7C9D9 /* LegacyEntrypoints.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LegacyEntrypoints.swift; sourceTree = "<group>"; };
255259
5E5D777F2040BD7D00EBC3A9 /* LogPolicyTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogPolicyTests.swift; sourceTree = "<group>"; };
256260
5E5D77832040F5E900EBC3A9 /* LoggingError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoggingError.swift; sourceTree = "<group>"; };
@@ -394,6 +398,7 @@
394398
isa = PBXGroup;
395399
children = (
396400
5EF581512041384700AC14FE /* CustomPlaygroundDisplayConvertibleTests.swift */,
401+
5E48E0A92042925B00C7712D /* LogEntryTests.swift */,
397402
5E5D777F2040BD7D00EBC3A9 /* LogPolicyTests.swift */,
398403
5ECE8F901FFCD2A70034D9BC /* LegacyPlaygroundLoggerTests.swift */,
399404
);
@@ -960,6 +965,7 @@
960965
buildActionMask = 2147483647;
961966
files = (
962967
5E5D77802040BD7D00EBC3A9 /* LogPolicyTests.swift in Sources */,
968+
5E48E0AA2042925B00C7712D /* LogEntryTests.swift in Sources */,
963969
5EF581532041387C00AC14FE /* CustomPlaygroundDisplayConvertibleTests.swift in Sources */,
964970
5ECE8F911FFCD2A70034D9BC /* LegacyPlaygroundLoggerTests.swift in Sources */,
965971
);
@@ -970,6 +976,7 @@
970976
buildActionMask = 2147483647;
971977
files = (
972978
5E5D77812040BD7D00EBC3A9 /* LogPolicyTests.swift in Sources */,
979+
5E48E0AB2042925B00C7712D /* LogEntryTests.swift in Sources */,
973980
5EF581542041387C00AC14FE /* CustomPlaygroundDisplayConvertibleTests.swift in Sources */,
974981
5EFE9193203F6CF900E21BAA /* LegacyPlaygroundLoggerTests.swift in Sources */,
975982
);
@@ -998,6 +1005,7 @@
9981005
buildActionMask = 2147483647;
9991006
files = (
10001007
5E5D77822040BD7D00EBC3A9 /* LogPolicyTests.swift in Sources */,
1008+
5E48E0AC2042925B00C7712D /* LogEntryTests.swift in Sources */,
10011009
5EF581552041387C00AC14FE /* CustomPlaygroundDisplayConvertibleTests.swift in Sources */,
10021010
5EFE91D7203F6F8100E21BAA /* LegacyPlaygroundLoggerTests.swift in Sources */,
10031011
);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===--- LogEntryTests.swift ----------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2018 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import XCTest
14+
@testable import PlaygroundLogger
15+
16+
import Foundation
17+
18+
class LogEntryTests: XCTestCase {
19+
func testNilIUO() throws {
20+
let nilIUO: Int! = nil
21+
22+
let logEntry = try LogEntry(describing: nilIUO as Any, name: "nilIUO", policy: .default)
23+
24+
guard case let .structured(name, _, _, totalChildrenCount, children, _) = logEntry else {
25+
XCTFail("Expected a structured log entry")
26+
return
27+
}
28+
29+
XCTAssertEqual(name, "nilIUO")
30+
XCTAssertEqual(totalChildrenCount, 0)
31+
XCTAssert(children.isEmpty)
32+
}
33+
}

0 commit comments

Comments
 (0)