Skip to content

Commit

Permalink
Code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ikhvorost committed Jan 16, 2024
1 parent 31e4f98 commit 5139919
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 25 deletions.
5 changes: 1 addition & 4 deletions Sources/DLog/LogItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions Sources/DLog/LogMetadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: "")
}
}

Expand Down
20 changes: 2 additions & 18 deletions Sources/DLog/LogPrivacy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand All @@ -84,15 +83,6 @@ public enum LogPrivacy {
.private(mask: .custom(value: "<private>"))
}

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)
Expand Down Expand Up @@ -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)

Expand Down
1 change: 0 additions & 1 deletion Tests/DLogTests/DLogTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,6 @@ final class FormatTests: XCTestCase {
XCTAssert(logger.log("Private: \(cardNumber, privacy: .private)")?.match("<private>") == 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)
Expand Down

0 comments on commit 5139919

Please sign in to comment.