forked from ProcedureKit/ProcedureKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoggingTests.swift
117 lines (95 loc) · 3.07 KB
/
LoggingTests.swift
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
//
// LoggingTests.swift
// Operations
//
// Created by Daniel Thorpe on 10/11/2015.
// Copyright © 2015 Dan Thorpe. All rights reserved.
//
import XCTest
@testable import Operations
class LoggerTests: XCTestCase {
var severity: LogSeverity!
var log: Logger!
override func setUp() {
super.setUp()
severity = .Notice
log = Logger(severity: severity)
}
override func tearDown() {
log = nil
super.tearDown()
}
func test__init__severity_is_set() {
XCTAssertEqual(log.severity, severity)
}
func test__init__severity_defaults_to_global_severity() {
log = Logger()
XCTAssertEqual(log.severity, LogManager.severity)
}
func test__init__enabled_defaults_to_global_enabled() {
log = Logger()
XCTAssertTrue(log.enabled)
}
func test__operation_name_with_name_set() {
let op = BlockOperation()
op.name = "A Block"
XCTAssertEqual(op.operationName, "A Block")
}
func test__operation_name_with_name_not_set() {
let op = BlockOperation()
op.name = nil
XCTAssertTrue(op.operationName.containsString("Unnamed Operation"))
}
func test__meta_uses_last_path_component() {
let meta = LogManager.metadataForFile("this/is/a/file.swift", function: "the_function", line: 100)
XCTAssertEqual(meta, "[file.swift the_function:100], ")
}
func test__meta_uses_last_path_component_with_operation_name() {
log = Logger()
log.operationName = "MyOperation"
let message = log.messageWithOperationName("a message")
XCTAssertEqual(message, "MyOperation: a message")
}
}
class RunAllTheLoggersTests: XCTestCase {
var log: Logger!
override func tearDown() {
log = nil
super.tearDown()
}
func test__verbose() {
log = Logger(severity: .Verbose) { message, severity, _, _, _ in
XCTAssertEqual(severity, LogSeverity.Verbose)
XCTAssertEqual(message, "Hello World")
}
log.verbose("Hello World")
}
func test__notice() {
log = Logger(severity: .Verbose) { message, severity, _, _, _ in
XCTAssertEqual(severity, LogSeverity.Notice)
XCTAssertEqual(message, "Hello World")
}
log.notice("Hello World")
}
func test__info() {
log = Logger(severity: .Verbose) { message, severity, _, _, _ in
XCTAssertEqual(severity, LogSeverity.Info)
XCTAssertEqual(message, "Hello World")
}
log.info("Hello World")
}
func test__warning() {
log = Logger(severity: .Verbose) { message, severity, _, _, _ in
XCTAssertEqual(severity, LogSeverity.Warning)
XCTAssertEqual(message, "Hello World")
}
log.warning("Hello World")
}
func test__fatal() {
log = Logger(severity: .Verbose) { message, severity, _, _, _ in
XCTAssertEqual(severity, LogSeverity.Fatal)
XCTAssertEqual(message, "Hello World")
}
log.fatal("Hello World")
}
}