forked from LoopKit/Loop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiagnosticLogTests.swift
More file actions
151 lines (112 loc) · 5.45 KB
/
Copy pathDiagnosticLogTests.swift
File metadata and controls
151 lines (112 loc) · 5.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//
// DiagnosticLogTests.swift
// LoopKitTests
//
// Created by Darin Krauss on 8/23/19.
// Copyright © 2019 LoopKit Authors. All rights reserved.
//
import XCTest
import os.log
import LoopKit
@testable import Loop
class DiagnosticLogTests: XCTestCase {
fileprivate var testLogging: TestLogging!
override func setUp() {
testLogging = TestLogging()
SharedLogging.instance = testLogging
}
override func tearDown() {
SharedLogging.instance = nil
testLogging = nil
}
func testInitializer() {
XCTAssertNotNil(DiagnosticLog(subsystem: "subsystem", category: "category"))
}
func testDebugWithoutArguments() {
let diagnosticLog = DiagnosticLog(subsystem: "debug subsystem", category: "debug category")
diagnosticLog.debug("debug message without arguments")
XCTAssertEqual(testLogging.message.description, "debug message without arguments")
XCTAssertEqual(testLogging.subsystem, "debug subsystem")
XCTAssertEqual(testLogging.category, "debug category")
XCTAssertEqual(testLogging.type, .debug)
XCTAssertEqual(testLogging.args.count, 0)
}
func testDebugWithArguments() {
let diagnosticLog = DiagnosticLog(subsystem: "debug subsystem", category: "debug category")
diagnosticLog.debug("debug message with arguments", "a")
XCTAssertEqual(testLogging.message.description, "debug message with arguments")
XCTAssertEqual(testLogging.subsystem, "debug subsystem")
XCTAssertEqual(testLogging.category, "debug category")
XCTAssertEqual(testLogging.type, .debug)
XCTAssertEqual(testLogging.args.count, 1)
}
func testInfoWithoutArguments() {
let diagnosticLog = DiagnosticLog(subsystem: "info subsystem", category: "info category")
diagnosticLog.info("info message without arguments")
XCTAssertEqual(testLogging.message.description, "info message without arguments")
XCTAssertEqual(testLogging.subsystem, "info subsystem")
XCTAssertEqual(testLogging.category, "info category")
XCTAssertEqual(testLogging.type, .info)
XCTAssertEqual(testLogging.args.count, 0)
}
func testInfoWithArguments() {
let diagnosticLog = DiagnosticLog(subsystem: "info subsystem", category: "info category")
diagnosticLog.info("info message with arguments", "a", "b")
XCTAssertEqual(testLogging.message.description, "info message with arguments")
XCTAssertEqual(testLogging.subsystem, "info subsystem")
XCTAssertEqual(testLogging.category, "info category")
XCTAssertEqual(testLogging.type, .info)
XCTAssertEqual(testLogging.args.count, 2)
}
func testDefaultWithoutArguments() {
let diagnosticLog = DiagnosticLog(subsystem: "default subsystem", category: "default category")
diagnosticLog.default("default message without arguments")
XCTAssertEqual(testLogging.message.description, "default message without arguments")
XCTAssertEqual(testLogging.subsystem, "default subsystem")
XCTAssertEqual(testLogging.category, "default category")
XCTAssertEqual(testLogging.type, .default)
XCTAssertEqual(testLogging.args.count, 0)
}
func testDefaultWithArguments() {
let diagnosticLog = DiagnosticLog(subsystem: "default subsystem", category: "default category")
diagnosticLog.default("default message with arguments", "a", "b", "c")
XCTAssertEqual(testLogging.message.description, "default message with arguments")
XCTAssertEqual(testLogging.subsystem, "default subsystem")
XCTAssertEqual(testLogging.category, "default category")
XCTAssertEqual(testLogging.type, .default)
XCTAssertEqual(testLogging.args.count, 3)
}
func testErrorWithoutArguments() {
let diagnosticLog = DiagnosticLog(subsystem: "error subsystem", category: "error category")
diagnosticLog.error("error message without arguments")
XCTAssertEqual(testLogging.message.description, "error message without arguments")
XCTAssertEqual(testLogging.subsystem, "error subsystem")
XCTAssertEqual(testLogging.category, "error category")
XCTAssertEqual(testLogging.type, .error)
XCTAssertEqual(testLogging.args.count, 0)
}
func testErrorWithArguments() {
let diagnosticLog = DiagnosticLog(subsystem: "error subsystem", category: "error category")
diagnosticLog.error("error message with arguments", "a", "b", "c", "d")
XCTAssertEqual(testLogging.message.description, "error message with arguments")
XCTAssertEqual(testLogging.subsystem, "error subsystem")
XCTAssertEqual(testLogging.category, "error category")
XCTAssertEqual(testLogging.type, .error)
XCTAssertEqual(testLogging.args.count, 4)
}
}
fileprivate class TestLogging: Logging {
var message: StaticString!
var subsystem: String!
var category: String!
var type: OSLogType!
var args: [CVarArg]!
init() {}
func log (_ message: StaticString, subsystem: String, category: String, type: OSLogType, _ args: [CVarArg]) {
self.message = message
self.subsystem = subsystem
self.category = category
self.type = type
self.args = args
}
}