Skip to content

Commit

Permalink
Run swift-format -p -r -i .
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasvl committed Sep 9, 2024
1 parent 5886254 commit ac8da77
Show file tree
Hide file tree
Showing 210 changed files with 30,053 additions and 27,682 deletions.
10 changes: 5 additions & 5 deletions CompileTests/InternalImportsByDefault/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ let package = Package(
.executableTarget(
name: "InternalImportsByDefault",
dependencies: [
.product(name: "SwiftProtobuf", package: "swift-protobuf"),
.product(name: "SwiftProtobuf", package: "swift-protobuf")
],
exclude: [
"Protos/SomeProtoWithBytes.proto",
"Protos/ServiceOnly.proto"
"Protos/ServiceOnly.proto",
],
swiftSettings: [
.enableExperimentalFeature("InternalImportsByDefault"),
.enableExperimentalFeature("AccessLevelOnImport"),
// Enable warnings as errors so the build fails if warnings are
// present in generated code.
.unsafeFlags(["-warnings-as-errors"])
.unsafeFlags(["-warnings-as-errors"]),
],
plugins: [
.plugin(name: "SwiftProtobufPlugin", package: "swift-protobuf")
]
),
)
]
)
#else
Expand All @@ -48,7 +48,7 @@ let package = Package(
exclude: [
"swift-protobuf-config.json",
"Protos/SomeProtoWithBytes.proto",
"Protos/ServiceOnly.proto"
"Protos/ServiceOnly.proto",
]
)
]
Expand Down
2 changes: 1 addition & 1 deletion CompileTests/MultiModule/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let package = Package(
.target(
name: "ModuleA",
dependencies: [
.product(name: "SwiftProtobuf", package: "swift-protobuf"),
.product(name: "SwiftProtobuf", package: "swift-protobuf")
]
),
.target(
Expand Down
46 changes: 23 additions & 23 deletions CompileTests/MultiModule/Tests/Test1/test1.swift
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import ImportsAPublicly
// Don't need to import ModuleA because of the file being a `import public`

import XCTest

final class ExampleTests: XCTestCase {
func testA() {
let anA = A.with { $0.e = .a }
XCTAssertEqual(anA.e, .a)
}
// Don't need to import ModuleA because of the file being a `import public`

func testImportsAPublicly() {
let imports = ImportsAPublicly.with { $0.a.e = .a }
XCTAssertEqual(imports.a.e, .a)
}
final class ExampleTests: XCTestCase {
func testA() {
let anA = A.with { $0.e = .a }
XCTAssertEqual(anA.e, .a)
}

func testInterop() {
let anA = A.with { $0.e = .b }
let imports = ImportsAPublicly.with {
$0.a = anA
$0.e = .b
func testImportsAPublicly() {
let imports = ImportsAPublicly.with { $0.a.e = .a }
XCTAssertEqual(imports.a.e, .a)
}
XCTAssertEqual(imports.a.e, imports.e)
let transitively = UsesATransitively.with {
$0.a = anA
$0.e = imports.e

func testInterop() {
let anA = A.with { $0.e = .b }
let imports = ImportsAPublicly.with {
$0.a = anA
$0.e = .b
}
XCTAssertEqual(imports.a.e, imports.e)
let transitively = UsesATransitively.with {
$0.a = anA
$0.e = imports.e
}
XCTAssertEqual(transitively.a, anA)
XCTAssertEqual(transitively.e, imports.e)
}
XCTAssertEqual(transitively.a, anA)
XCTAssertEqual(transitively.e, imports.e)
}
}
46 changes: 23 additions & 23 deletions CompileTests/MultiModule/Tests/Test2/test2.swift
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import ImportsImportsAPublicly
// Don't need to import ModuleA because of the file being a `import public`

import XCTest

final class ExampleTests: XCTestCase {
func testA() {
let anA = A.with { $0.e = .a }
XCTAssertEqual(anA.e, .a)
}
// Don't need to import ModuleA because of the file being a `import public`

func testImportsImportsAPublicly() {
let imports = ImportsImportsAPublicly.with { $0.a.e = .a }
XCTAssertEqual(imports.a.e, .a)
}
final class ExampleTests: XCTestCase {
func testA() {
let anA = A.with { $0.e = .a }
XCTAssertEqual(anA.e, .a)
}

func testInterop() {
let anA = A.with { $0.e = .b }
let imports = ImportsImportsAPublicly.with {
$0.a = anA
$0.e = .b
func testImportsImportsAPublicly() {
let imports = ImportsImportsAPublicly.with { $0.a.e = .a }
XCTAssertEqual(imports.a.e, .a)
}
XCTAssertEqual(imports.a.e, imports.e)
let transitively = UsesATransitively2.with {
$0.a = anA
$0.e = imports.e

func testInterop() {
let anA = A.with { $0.e = .b }
let imports = ImportsImportsAPublicly.with {
$0.a = anA
$0.e = .b
}
XCTAssertEqual(imports.a.e, imports.e)
let transitively = UsesATransitively2.with {
$0.a = anA
$0.e = imports.e
}
XCTAssertEqual(transitively.a, anA)
XCTAssertEqual(transitively.e, imports.e)
}
XCTAssertEqual(transitively.a, anA)
XCTAssertEqual(transitively.e, imports.e)
}
}
25 changes: 16 additions & 9 deletions FuzzTesting/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,39 @@ import PackageDescription
let package = Package(
name: "FuzzTesting",
platforms: [
.macOS(.v10_15),
.macOS(.v10_15)
],
dependencies: [
.package(name: "SwiftProtobuf", path: ".."),
.package(name: "SwiftProtobuf", path: "..")
],
targets: [
.target(
name: "FuzzCommon",
dependencies: ["SwiftProtobuf"]),
dependencies: ["SwiftProtobuf"]
),
.target(
name: "FuzzBinary",
dependencies: ["SwiftProtobuf", "FuzzCommon"]),
dependencies: ["SwiftProtobuf", "FuzzCommon"]
),
.target(
name: "FuzzBinaryDelimited",
dependencies: ["SwiftProtobuf", "FuzzCommon"]),
dependencies: ["SwiftProtobuf", "FuzzCommon"]
),
.target(
name: "FuzzAsyncMessageSequence",
dependencies: ["SwiftProtobuf", "FuzzCommon"]),
dependencies: ["SwiftProtobuf", "FuzzCommon"]
),
.target(
name: "FuzzJSON",
dependencies: ["SwiftProtobuf", "FuzzCommon"]),
dependencies: ["SwiftProtobuf", "FuzzCommon"]
),
.target(
name: "FuzzTextFormat",
dependencies: ["SwiftProtobuf", "FuzzCommon"]),
dependencies: ["SwiftProtobuf", "FuzzCommon"]
),
.testTarget(
name: "FuzzCommonTests",
dependencies: ["FuzzCommon"]),
dependencies: ["FuzzCommon"]
),
]
)
67 changes: 33 additions & 34 deletions FuzzTesting/Sources/FuzzAsyncMessageSequence/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,48 @@
// -----------------------------------------------------------------------------

import Foundation

import FuzzCommon

import SwiftProtobuf

fileprivate func asyncByteStream(bytes: UnsafeRawBufferPointer) -> AsyncStream<UInt8> {
AsyncStream(UInt8.self) { continuation in
for i in 0..<bytes.count {
continuation.yield(bytes.loadUnaligned(fromByteOffset: i, as: UInt8.self))
private func asyncByteStream(bytes: UnsafeRawBufferPointer) -> AsyncStream<UInt8> {
AsyncStream(UInt8.self) { continuation in
for i in 0..<bytes.count {
continuation.yield(bytes.loadUnaligned(fromByteOffset: i, as: UInt8.self))
}
continuation.finish()
}
continuation.finish()
}
}

@_cdecl("LLVMFuzzerTestOneInput")
public func FuzzAsyncMessageSequence(_ start: UnsafeRawPointer, _ count: Int) -> CInt {
// No decoding options here, a leading zero is actually valid (zero length message),
// so we rely on the other Binary fuzz tester to test options, and just let this
// one focus on issue around framing of the messages on the stream.
let bytes = UnsafeRawBufferPointer(start: start, count: count)
let asyncBytes = asyncByteStream(bytes: bytes)
let decoding = asyncBytes.binaryProtobufDelimitedMessages(
of: SwiftProtoTesting_Fuzz_Message.self,
extensions: SwiftProtoTesting_Fuzz_FuzzTesting_Extensions)
// No decoding options here, a leading zero is actually valid (zero length message),
// so we rely on the other Binary fuzz tester to test options, and just let this
// one focus on issue around framing of the messages on the stream.
let bytes = UnsafeRawBufferPointer(start: start, count: count)
let asyncBytes = asyncByteStream(bytes: bytes)
let decoding = asyncBytes.binaryProtobufDelimitedMessages(
of: SwiftProtoTesting_Fuzz_Message.self,
extensions: SwiftProtoTesting_Fuzz_FuzzTesting_Extensions
)

let semaphore = DispatchSemaphore(value: 0)
Task {
do {
for try await _ in decoding {
// TODO: Test serialization for completeness.
// We could serialize individual messages like this:
// let _: [UInt8] = try! msg.serializedBytes()
// but we don't have a stream writer which is what
// we really want to exercise here.
let semaphore = DispatchSemaphore(value: 0)
Task {
do {
for try await _ in decoding {
// TODO: Test serialization for completeness.
// We could serialize individual messages like this:
// let _: [UInt8] = try! msg.serializedBytes()
// but we don't have a stream writer which is what
// we really want to exercise here.

// Also, serialization here more than doubles the total
// run time, leading to timeouts for the fuzz tester. :(
}
} catch {
// Error parsing are to be expected since not all input will be well formed.
// Also, serialization here more than doubles the total
// run time, leading to timeouts for the fuzz tester. :(
}
} catch {
// Error parsing are to be expected since not all input will be well formed.
}
semaphore.signal()
}
semaphore.signal()
}
semaphore.wait()
return 0
semaphore.wait()
return 0
}
34 changes: 17 additions & 17 deletions FuzzTesting/Sources/FuzzBinary/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@
// -----------------------------------------------------------------------------

import FuzzCommon

import SwiftProtobuf

@_cdecl("LLVMFuzzerTestOneInput")
public func FuzzBinary(_ start: UnsafeRawPointer, _ count: Int) -> CInt {
guard let (options, bytes) = BinaryDecodingOptions.extractOptions(start, count) else {
return 1
}
var msg: SwiftProtoTesting_Fuzz_Message?
do {
msg = try SwiftProtoTesting_Fuzz_Message(
serializedBytes: Array(bytes),
extensions: SwiftProtoTesting_Fuzz_FuzzTesting_Extensions,
options: options)
} catch {
// Error parsing are to be expected since not all input will be well formed.
}
// Test serialization for completeness.
// If a message was parsed, it should not fail to serialize, so assert as such.
let _: [UInt8]? = try! msg?.serializedBytes()
guard let (options, bytes) = BinaryDecodingOptions.extractOptions(start, count) else {
return 1
}
var msg: SwiftProtoTesting_Fuzz_Message?
do {
msg = try SwiftProtoTesting_Fuzz_Message(
serializedBytes: Array(bytes),
extensions: SwiftProtoTesting_Fuzz_FuzzTesting_Extensions,
options: options
)
} catch {
// Error parsing are to be expected since not all input will be well formed.
}
// Test serialization for completeness.
// If a message was parsed, it should not fail to serialize, so assert as such.
let _: [UInt8]? = try! msg?.serializedBytes()

return 0
return 0
}
Loading

0 comments on commit ac8da77

Please sign in to comment.