Skip to content

Commit 2637350

Browse files
authored
test formatting issues as part of sanity check (#84)
motivaiton: unified format changes: * use official docker image 🎉 * fix outstanding formatting issues * add a call to swiftformat as part of sanity script * fix sanity script language check debugging statements
1 parent 99786c8 commit 2637350

File tree

12 files changed

+82
-89
lines changed

12 files changed

+82
-89
lines changed

.swiftformat

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# file options
22

3+
--exclude .build
4+
35
# format options
46

5-
--self insert
6-
--patternlet inline
7-
--stripunusedargs unnamed-only
7+
--self insert
8+
--patternlet inline
9+
--stripunusedargs unnamed-only
810
--comments ignore
11+
--ifdef no-indent
912

1013
# rules
11-

Sources/Logging/Locks.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
//===----------------------------------------------------------------------===//
2828

2929
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
30-
import Darwin
30+
import Darwin
3131
#else
32-
import Glibc
32+
import Glibc
3333
#endif
3434

3535
/// A threading lock based on `libpthread` instead of `libdispatch`.

Sources/Logging/Logging.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
16-
import Darwin
16+
import Darwin
1717
#else
18-
import Glibc
18+
import Glibc
1919
#endif
2020

2121
/// A `Logger` is the central type in `SwiftLog`. Its central function is to emit log messages using one of the methods
@@ -537,7 +537,6 @@ let systemStdout = Glibc.stdout!
537537
/// `StreamLogHandler` is a simple implementation of `LogHandler` for directing
538538
/// `Logger` output to either `stderr` or `stdout` via the factory methods.
539539
public struct StreamLogHandler: LogHandler {
540-
541540
/// Factory that makes a `StreamLogHandler` to directs its output to `stdout`
542541
public static func standardOutput(label: String) -> StreamLogHandler {
543542
return StreamLogHandler(label: label, stream: StdioOutputStream.stdout)
@@ -555,16 +554,16 @@ public struct StreamLogHandler: LogHandler {
555554
private var prettyMetadata: String?
556555
public var metadata = Logger.Metadata() {
557556
didSet {
558-
prettyMetadata = prettify(metadata)
557+
self.prettyMetadata = self.prettify(self.metadata)
559558
}
560559
}
561560

562561
public subscript(metadataKey metadataKey: String) -> Logger.Metadata.Value? {
563562
get {
564-
return metadata[metadataKey]
563+
return self.metadata[metadataKey]
565564
}
566565
set {
567-
metadata[metadataKey] = newValue
566+
self.metadata[metadataKey] = newValue
568567
}
569568
}
570569

@@ -582,7 +581,7 @@ public struct StreamLogHandler: LogHandler {
582581
: self.prettify(self.metadata.merging(metadata!, uniquingKeysWith: { _, new in new }))
583582

584583
var stream = self.stream
585-
stream.write("\(timestamp()) \(level):\(prettyMetadata.map { " \($0)" } ?? "") \(message)\n")
584+
stream.write("\(self.timestamp()) \(level):\(prettyMetadata.map { " \($0)" } ?? "") \(message)\n")
586585
}
587586

588587
private func prettify(_ metadata: Logger.Metadata) -> String? {

Tests/LinuxMain.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ import XCTest
2323
///
2424

2525
#if os(Linux) || os(FreeBSD)
26-
@testable import LoggingTests
26+
@testable import LoggingTests
2727

28-
XCTMain([
29-
testCase(GlobalLoggerTest.allTests),
30-
testCase(LocalLoggerTest.allTests),
31-
testCase(LoggingTest.allTests),
32-
testCase(MDCTest.allTests),
33-
])
28+
XCTMain([
29+
testCase(GlobalLoggerTest.allTests),
30+
testCase(LocalLoggerTest.allTests),
31+
testCase(LoggingTest.allTests),
32+
testCase(MDCTest.allTests),
33+
])
3434
#endif

Tests/LoggingTests/GlobalLoggingTest.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ private struct Struct3 {
147147
let group = DispatchGroup()
148148
group.enter()
149149
let loggingMetadata = MDC.global.metadata
150-
queue.async {
150+
self.queue.async {
151151
MDC.global.with(metadata: loggingMetadata) {
152152
self.logger.warning("Struct3::doSomethingElseAsync")
153153
let library = TestLibrary()
@@ -160,9 +160,9 @@ private struct Struct3 {
160160
group.wait()
161161
MDC.global["foo"] = nil
162162
// only effects the logger instance
163-
var l = logger
163+
var l = self.logger
164164
l[metadataKey: "baz"] = "qux"
165165
l.debug("Struct3::doSomethingElse::Local")
166-
logger.debug("Struct3::doSomethingElse::end")
166+
self.logger.debug("Struct3::doSomethingElse::end")
167167
}
168168
}

Tests/LoggingTests/LocalLoggingTest.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private struct Struct2 {
111111
var c = context
112112
c.logLevel = .info // only effects from this point on
113113
c.logger.info("Struct2::doSomething")
114-
doSomethingElse(context: c)
114+
self.doSomethingElse(context: c)
115115
c.logger.debug("Struct2::doSomething::end")
116116
}
117117

@@ -131,15 +131,15 @@ private struct Struct3 {
131131
var c = context
132132
c["bar"] = "baz" // only effects from this point on
133133
c.logger.error("Struct3::doSomething")
134-
doSomethingElse(context: c)
134+
self.doSomethingElse(context: c)
135135
c.logger.debug("Struct3::doSomething::end")
136136
}
137137

138138
private func doSomethingElse(context: Context) {
139139
context.logger.error("Struct3::doSomethingElse")
140140
let group = DispatchGroup()
141141
group.enter()
142-
queue.async {
142+
self.queue.async {
143143
context.logger.warning("Struct3::doSomethingElseAsync")
144144
let library = TestLibrary()
145145
library.doSomething()

Tests/LoggingTests/LoggingTest.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class LoggingTest: XCTestCase {
5555
// bootstrap with our test logging impl
5656
let logging1 = TestLogging()
5757
let logging2 = TestLogging()
58-
LoggingSystem.bootstrapInternal({ MultiplexLogHandler([logging1.make(label: $0), logging2.make(label: $0)]) })
58+
LoggingSystem.bootstrapInternal { MultiplexLogHandler([logging1.make(label: $0), logging2.make(label: $0)]) }
5959

6060
var logger = Logger(label: "test")
6161
logger.logLevel = .warning
@@ -137,13 +137,13 @@ class LoggingTest: XCTestCase {
137137
var logger = Logger(label: "\(#function)")
138138

139139
logger[metadataKey: "foo"] = .stringConvertible("raw-string")
140-
let lazyBox = LazyMetadataBox({ "rendered-at-first-use" })
140+
let lazyBox = LazyMetadataBox { "rendered-at-first-use" }
141141
logger[metadataKey: "lazy"] = .stringConvertible(lazyBox)
142142
logger.info("hello world!")
143143
testLogging.history.assertExist(level: .info,
144144
message: "hello world!",
145145
metadata: ["foo": .stringConvertible("raw-string"),
146-
"lazy": .stringConvertible(LazyMetadataBox({ "rendered-at-first-use" }))])
146+
"lazy": .stringConvertible(LazyMetadataBox { "rendered-at-first-use" })])
147147
}
148148

149149
private func dontEvaluateThisString(file: StaticString = #file, line: UInt = #line) -> Logger.Message {
@@ -361,7 +361,7 @@ class LoggingTest: XCTestCase {
361361

362362
let logRecorder = Recorder()
363363
LoggingSystem.bootstrapInternal { _ in
364-
return LogHandlerWithGlobalLogLevelOverride(recorder: logRecorder)
364+
LogHandlerWithGlobalLogLevelOverride(recorder: logRecorder)
365365
}
366366

367367
var logger1 = Logger(label: "logger-\(#file):\(#line)")
@@ -388,7 +388,7 @@ class LoggingTest: XCTestCase {
388388
logRecorder.assertExist(level: .notice, message: "logger1, after")
389389
logRecorder.assertExist(level: .notice, message: "logger2, after")
390390
}
391-
391+
392392
func testLogLevelCases() {
393393
let levels = Logger.Level.allCases
394394
XCTAssertEqual(7, levels.count)
@@ -424,8 +424,8 @@ class LoggingTest: XCTestCase {
424424

425425
func write(_ string: String) {
426426
// This is a test implementation, a real implementation would include locking
427-
strings.append(string)
428-
interceptedText = (interceptedText ?? "") + string
427+
self.strings.append(string)
428+
self.interceptedText = (self.interceptedText ?? "") + string
429429
}
430430
}
431431

Tests/LoggingTests/TestLogger.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ internal struct TestLogHandler: LogHandler {
4545

4646
func log(level: Logger.Level, message: Logger.Message, metadata: Logger.Metadata?, file: String, function: String, line: UInt) {
4747
let metadata = (self._metadataSet ? self.metadata : MDC.global.metadata).merging(metadata ?? [:], uniquingKeysWith: { _, new in new })
48-
logger.log(level: level, message, metadata: metadata, file: file, function: function, line: line)
48+
self.logger.log(level: level, message, metadata: metadata, file: file, function: function, line: line)
4949
self.recorder.record(level: level, metadata: metadata, message: message)
5050
}
5151

@@ -208,7 +208,7 @@ public class MDC {
208208
}
209209
set {
210210
self.lock.withLock {
211-
if nil == self.storage[self.threadId] {
211+
if self.storage[self.threadId] == nil {
212212
self.storage[self.threadId] = Logger.Metadata()
213213
}
214214
self.storage[self.threadId]![metadataKey] = newValue
@@ -253,9 +253,9 @@ public class MDC {
253253

254254
private var threadId: Int {
255255
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
256-
return Int(pthread_mach_thread_np(pthread_self()))
256+
return Int(pthread_mach_thread_np(pthread_self()))
257257
#else
258-
return Int(pthread_self())
258+
return Int(pthread_self())
259259
#endif
260260
}
261261
}
@@ -284,7 +284,7 @@ internal struct TestLibrary {
284284
// libraries that use global loggers and async, need to make sure they propagate the
285285
// logging metadata when creating a new thread
286286
let metadata = MDC.global.metadata
287-
queue.asyncAfter(deadline: .now() + 0.1) {
287+
self.queue.asyncAfter(deadline: .now() + 0.1) {
288288
MDC.global.with(metadata: metadata) {
289289
self.logger.info("TestLibrary::doSomethingAsync")
290290
completion()

docker/Dockerfile

Lines changed: 24 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,35 @@
1-
ARG ubuntu_version=18.04
2-
FROM ubuntu:$ubuntu_version
1+
ARG swift_version=5.0
2+
ARG ubuntu_version=bionic
3+
FROM swift:$swift_version-$ubuntu_version
34
# needed to do again after FROM due to docker limitation
5+
ARG swift_version
46
ARG ubuntu_version
57

6-
ARG DEBIAN_FRONTEND=noninteractive
7-
# do not start services during installation as this will fail and log a warning / error.
8-
RUN echo "#!/bin/sh\nexit 0" > /usr/sbin/policy-rc.d
8+
# set as UTF-8
9+
RUN apt-get update && apt-get install -y locales locales-all
10+
ENV LC_ALL en_US.UTF-8
11+
ENV LANG en_US.UTF-8
12+
ENV LANGUAGE en_US.UTF-8
913

10-
# basic dependencies
11-
RUN apt-get update && apt-get install -y wget git build-essential software-properties-common pkg-config locales
12-
RUN apt-get update && apt-get install -y libicu-dev libblocksruntime0 curl libcurl4-openssl-dev libz-dev
13-
14-
# local
15-
RUN locale-gen en_US.UTF-8
16-
RUN locale-gen en_US en_US.UTF-8
17-
RUN dpkg-reconfigure locales
18-
RUN echo 'export LANG=en_US.UTF-8' >> $HOME/.profile
19-
RUN echo 'export LANGUAGE=en_US:en' >> $HOME/.profile
20-
RUN echo 'export LC_ALL=en_US.UTF-8' >> $HOME/.profile
21-
22-
# known_hosts
23-
RUN mkdir -p $HOME/.ssh
24-
RUN touch $HOME/.ssh/known_hosts
25-
RUN ssh-keyscan github.com 2> /dev/null >> $HOME/.ssh/known_hosts
26-
27-
# clang
28-
RUN apt-get update && apt-get install -y clang-3.9
29-
RUN update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.9 100
30-
RUN update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.9 100
14+
# dependencies
15+
RUN apt-get update && apt-get install -y wget
16+
RUN apt-get update && apt-get install -y lsof dnsutils netcat-openbsd net-tools # used by integration tests
3117

3218
# ruby and jazzy for docs generation
33-
#ARG skip_ruby_from_ppa
34-
#RUN [ -n "$skip_ruby_from_ppa" ] || apt-add-repository -y ppa:brightbox/ruby-ng
35-
#RUN [ -n "$skip_ruby_from_ppa" ] || { apt-get update && apt-get install -y ruby2.4 ruby2.4-dev; }
36-
#RUN [ -z "$skip_ruby_from_ppa" ] || { apt-get update && apt-get install -y ruby ruby-dev; }
37-
#RUN apt-get update && apt-get install -y libsqlite3-dev
3819
RUN apt-get update && apt-get install -y ruby ruby-dev libsqlite3-dev
3920
RUN gem install jazzy --no-ri --no-rdoc
4021

41-
# swift
42-
ARG swift_version=4.2.3
43-
ARG swift_flavour=RELEASE
44-
ARG swift_builds_suffix=release
22+
# tools
23+
RUN mkdir -p $HOME/.tools
24+
RUN echo 'export PATH="$HOME/.tools:$PATH"' >> $HOME/.profile
25+
26+
# script to allow mapping framepointers on linux (until part of the toolchain)
27+
RUN wget -q https://raw.githubusercontent.com/apple/swift/master/utils/symbolicate-linux-fatal -O $HOME/.tools/symbolicate-linux-fatal
28+
RUN chmod 755 $HOME/.tools/symbolicate-linux-fatal
4529

46-
RUN mkdir $HOME/.swift
47-
RUN wget -q "https://swift.org/builds/swift-${swift_version}-${swift_builds_suffix}/ubuntu$(echo $ubuntu_version | sed 's/\.//g')/swift-${swift_version}-${swift_flavour}/swift-${swift_version}-${swift_flavour}-ubuntu${ubuntu_version}.tar.gz" -O $HOME/swift.tar.gz
48-
RUN tar xzf $HOME/swift.tar.gz --directory $HOME/.swift --strip-components=1
49-
RUN echo 'export PATH="$HOME/.swift/usr/bin:$PATH"' >> $HOME/.profile
50-
RUN echo 'export LINUX_SOURCEKIT_LIB_PATH="$HOME/.swift/usr/lib"' >> $HOME/.profile
30+
# swiftformat (until part of the toolchain)
5131

52-
# script to allow mapping framepointers on linux
53-
RUN mkdir -p $HOME/.scripts
54-
RUN wget -q https://raw.githubusercontent.com/apple/swift/master/utils/symbolicate-linux-fatal -O $HOME/.scripts/symbolicate-linux-fatal
55-
RUN chmod 755 $HOME/.scripts/symbolicate-linux-fatal
56-
RUN echo 'export PATH="$HOME/.scripts:$PATH"' >> $HOME/.profile
32+
ARG swiftformat_version=0.40.11
33+
RUN git clone --branch $swiftformat_version --depth 1 https://github.com/nicklockwood/SwiftFormat $HOME/.tools/swift-format
34+
RUN cd $HOME/.tools/swift-format && swift build -c release
35+
RUN ln -s $HOME/.tools/swift-format/.build/release/swiftformat $HOME/.tools/swiftformat

docker/docker-compose.1804.50.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ services:
66
image: swift-log:18.04-5.0
77
build:
88
args:
9-
ubuntu_version: "18.04"
9+
ubuntu_version: "bionic"
1010
swift_version: "5.0"
1111

1212
test:

0 commit comments

Comments
 (0)