From 51399193143ccba26f3bdba7098ee00e9804d82b Mon Sep 17 00:00:00 2001 From: Iurii Khvorost Date: Tue, 16 Jan 2024 18:03:01 +0200 Subject: [PATCH] Code coverage --- Sources/DLog/LogItem.swift | 5 +---- Sources/DLog/LogMetadata.swift | 4 ++-- Sources/DLog/LogPrivacy.swift | 20 ++------------------ Tests/DLogTests/DLogTests.swift | 1 - 4 files changed, 5 insertions(+), 25 deletions(-) diff --git a/Sources/DLog/LogItem.swift b/Sources/DLog/LogItem.swift index 130badf..dc64e12 100644 --- a/Sources/DLog/LogItem.swift +++ b/Sources/DLog/LogItem.swift @@ -43,10 +43,7 @@ public class LogLocation: NSObject { /// The module name. public lazy var moduleName: String = { - guard fileID.contains("/") else { - return fileID - } - return (fileID as NSString).pathComponents.first! + (fileID as NSString).pathComponents.first! }() /// The file name. diff --git a/Sources/DLog/LogMetadata.swift b/Sources/DLog/LogMetadata.swift index e71e8ab..5c4b938 100644 --- a/Sources/DLog/LogMetadata.swift +++ b/Sources/DLog/LogMetadata.swift @@ -53,14 +53,14 @@ extension Metadata { return Dictionary(uniqueKeysWithValues: keyValues) } - func json(quotes: Bool = false, pretty: Bool = false) -> String { + func json(pretty: Bool = false) -> String { let options: JSONSerialization.WritingOptions = pretty ? [.sortedKeys, .prettyPrinted] : [.sortedKeys] guard self.isEmpty == false, let data = try? JSONSerialization.data(withJSONObject: self, options: options), let json = String(data: data, encoding: .utf8) else { return "" } - return quotes ? json : json.replacingOccurrences(of: "\"", with: "") + return json.replacingOccurrences(of: "\"", with: "") } } diff --git a/Sources/DLog/LogPrivacy.swift b/Sources/DLog/LogPrivacy.swift index 0fedc8c..917d906 100644 --- a/Sources/DLog/LogPrivacy.swift +++ b/Sources/DLog/LogPrivacy.swift @@ -73,8 +73,7 @@ public enum LogPrivacy { /// /// - Parameters: /// - mask: Mask to use with the privacy option. - /// - auto: If `true` the mask is not applied while debugging. If `false` the mask is applied both in Debug and Release. Defaults to `true`. - case `private`(mask: Mask, auto: Bool = true) + case `private`(mask: Mask) /// Sets the privacy level of a log message to private. /// @@ -84,15 +83,6 @@ public enum LogPrivacy { .private(mask: .custom(value: "")) } - private static let isDebugger: Bool = { - var info = kinfo_proc() - var size = MemoryLayout.size(ofValue: info) - var mib: [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()] - return sysctl(&mib, UInt32(mib.count), &info, &size, nil, 0) == 0 && (info.kp_proc.p_flag & P_TRACED) != 0 - }() - - private static let isXCTest: Bool = { NSClassFromString("XCTest") != nil }() - private static let letters: [Character] = { let lower = (Unicode.Scalar("a").value...Unicode.Scalar("z").value) let upper = (Unicode.Scalar("A").value...Unicode.Scalar("Z").value) @@ -215,14 +205,8 @@ public enum LogPrivacy { case .public: return text - case let .private(mask, auto): - // Skip for debugging and testing - guard !auto || !Self.isDebugger || Self.isXCTest else { - return text - } - + case let .private(mask): switch mask { - case .hash: return String(format: "%02X", text.hashValue) diff --git a/Tests/DLogTests/DLogTests.swift b/Tests/DLogTests/DLogTests.swift index d73c162..51bdcea 100644 --- a/Tests/DLogTests/DLogTests.swift +++ b/Tests/DLogTests/DLogTests.swift @@ -647,7 +647,6 @@ final class FormatTests: XCTestCase { XCTAssert(logger.log("Private: \(cardNumber, privacy: .private)")?.match("") == true) XCTAssert(logger.log("Private hash: \(cardNumber, privacy: .private(mask: .hash))")?.match("[0-9a-fA-F]+") == true) - XCTAssert(logger.log("Private hash: \(cardNumber, privacy: .private(mask: .hash, auto: false))")?.match("[0-9a-fA-F]+") == true) XCTAssert(logger.log("Private random: \(empty, privacy: .private(mask: .random))")?.match(": $") == true) XCTAssert(logger.log("Private random: \(cardNumber, privacy: .private(mask: .random))")?.match(cardNumber) == false)