Просмотр исходного кода

Move SwiftProtobufTests to using `package` visibility. (#1791)

The fuzz testing uses an older SwiftPM manifest version that predates
the addition of `package` visibility, but it appears that things still
build because we're using a newer toolchain version with the support.

Fixes #1784
Thomas Van Lenten 9 месяцев назад
Родитель
Сommit
7f94e232d1

+ 1 - 1
Sources/SwiftProtobuf/Enum.swift

@@ -49,7 +49,7 @@ extension Enum {
     ///
     /// Since the text format and JSON names are always identical, we don't need
     /// to distinguish them.
-    internal var name: _NameMap.Name? {
+    package var name: _NameMap.Name? {
         guard let nameProviding = Self.self as? any _ProtoNameProviding.Type else {
             return nil
         }

+ 8 - 8
Sources/SwiftProtobuf/FieldTag.swift

@@ -19,21 +19,21 @@
 /// improper field number (such as zero) or wire format (such as 6 or 7) to
 /// exist. In other words, a `FieldTag`'s properties never need to be tested
 /// for validity because they are guaranteed correct at initialization time.
-internal struct FieldTag: RawRepresentable {
+package struct FieldTag: RawRepresentable {
 
-    typealias RawValue = UInt32
+    package typealias RawValue = UInt32
 
     /// The raw numeric value of the tag, which contains both the field number and
     /// wire format.
-    let rawValue: UInt32
+    package let rawValue: UInt32
 
     /// The field number component of the tag.
-    var fieldNumber: Int {
+    package var fieldNumber: Int {
         Int(rawValue >> 3)
     }
 
     /// The wire format component of the tag.
-    var wireFormat: WireFormat {
+    package var wireFormat: WireFormat {
         // This force-unwrap is safe because there are only two initialization
         // paths: one that takes a WireFormat directly (and is guaranteed valid at
         // compile-time), or one that takes a raw value but which only lets valid
@@ -43,7 +43,7 @@ internal struct FieldTag: RawRepresentable {
 
     /// A helper property that returns the number of bytes required to
     /// varint-encode this tag.
-    var encodedSize: Int {
+    package var encodedSize: Int {
         Varint.encodedSize(of: rawValue)
     }
 
@@ -51,7 +51,7 @@ internal struct FieldTag: RawRepresentable {
     ///
     /// Note that if the raw value given here is not a valid tag (for example, it
     /// has an invalid wire format), this initializer will fail.
-    init?(rawValue: UInt32) {
+    package init?(rawValue: UInt32) {
         // Verify that the field number and wire format are valid and fail if they
         // are not.
         guard rawValue & ~0x07 != 0,
@@ -63,7 +63,7 @@ internal struct FieldTag: RawRepresentable {
     }
 
     /// Creates a new tag by composing the given field number and wire format.
-    init(fieldNumber: Int, wireFormat: WireFormat) {
+    package init(fieldNumber: Int, wireFormat: WireFormat) {
         self.rawValue = UInt32(truncatingIfNeeded: fieldNumber) << 3 | UInt32(wireFormat.rawValue)
     }
 }

+ 1 - 1
Sources/SwiftProtobuf/NameMap.swift

@@ -88,7 +88,7 @@ public struct _NameMap: ExpressibleByDictionaryLiteral {
     /// block of UTF-8 data) where possible.  In cases where the string
     /// has to be computed, it caches the UTF-8 bytes in an
     /// unmovable and immutable heap area.
-    internal struct Name: Hashable, CustomStringConvertible {
+    package struct Name: Hashable, CustomStringConvertible {
         // This should not be used outside of this file, as it requires
         // coordinating the lifecycle with the lifecycle of the pool
         // where the raw UTF8 gets interned.

+ 1 - 1
Sources/SwiftProtobuf/SimpleExtensionMap.swift

@@ -17,7 +17,7 @@ public struct SimpleExtensionMap: ExtensionMap, ExpressibleByArrayLiteral {
     public typealias Element = AnyMessageExtension
 
     // Since type objects aren't Hashable, we can't do much better than this...
-    internal var fields = [Int: [any AnyMessageExtension]]()
+    package var fields = [Int: [any AnyMessageExtension]]()
 
     public init() {}
 

+ 1 - 1
Sources/SwiftProtobuf/SwiftProtobufError.swift

@@ -60,7 +60,7 @@ public struct SwiftProtobufError: Error, @unchecked Sendable {
     }
 
     /// A message describing what went wrong and how it may be remedied.
-    internal var message: String {
+    package var message: String {
         get { self.storage.message }
         set {
             self.ensureStorageIsUnique()

+ 1 - 1
Sources/SwiftProtobuf/UnknownStorage.swift

@@ -29,7 +29,7 @@ public struct UnknownStorage: Equatable, Sendable {
 
     public init() {}
 
-    internal mutating func append(protobufData: Data) {
+    package mutating func append(protobufData: Data) {
         data.append(protobufData)
     }
 

+ 3 - 3
Sources/SwiftProtobuf/Varint.swift

@@ -13,13 +13,13 @@
 // -----------------------------------------------------------------------------
 
 /// Contains helper methods to varint-encode and decode integers.
-internal enum Varint {
+package enum Varint {
 
     /// Computes the number of bytes that would be needed to store a 32-bit varint.
     ///
     /// - Parameter value: The number whose varint size should be calculated.
     /// - Returns: The size, in bytes, of the 32-bit varint.
-    static func encodedSize(of value: UInt32) -> Int {
+    package static func encodedSize(of value: UInt32) -> Int {
         if (value & (~0 << 7)) == 0 {
             return 1
         }
@@ -40,7 +40,7 @@ internal enum Varint {
     ///
     /// - Parameter value: The number whose varint size should be calculated.
     /// - Returns: The size, in bytes, of the 32-bit varint.
-    static func encodedSize(of value: Int32) -> Int {
+    package static func encodedSize(of value: Int32) -> Int {
         if value >= 0 {
             return encodedSize(of: UInt32(bitPattern: value))
         } else {

+ 1 - 1
Sources/SwiftProtobuf/WireFormat.swift

@@ -13,7 +13,7 @@
 // -----------------------------------------------------------------------------
 
 /// Denotes the wire format by which a value is encoded in binary form.
-internal enum WireFormat: UInt8 {
+package enum WireFormat: UInt8 {
     case varint = 0
     case fixed64 = 1
     case lengthDelimited = 2

+ 1 - 2
Tests/SwiftProtobufTests/Data+TestHelpers.swift

@@ -9,8 +9,7 @@
 // -----------------------------------------------------------------------------
 
 import Foundation
-
-@testable import SwiftProtobuf
+import SwiftProtobuf
 
 /// Helpers for building up wire encoding in tests.
 extension Data {

+ 1 - 2
Tests/SwiftProtobufTests/TestHelpers.swift

@@ -13,10 +13,9 @@
 // -----------------------------------------------------------------------------
 
 import Foundation
+import SwiftProtobuf
 import XCTest
 
-@testable import SwiftProtobuf
-
 typealias XCTestFileArgType = StaticString
 
 protocol PBTestHelpers {

+ 1 - 2
Tests/SwiftProtobufTests/Test_MessageSet.swift

@@ -13,10 +13,9 @@
 // -----------------------------------------------------------------------------
 
 import Foundation
+import SwiftProtobuf
 import XCTest
 
-@testable import SwiftProtobuf
-
 extension SwiftProtoTesting_RawMessageSet.Item {
     fileprivate init(typeID: Int, message: Data) {
         self.init()

+ 1 - 2
Tests/SwiftProtobufTests/Test_Reserved.swift

@@ -16,10 +16,9 @@
 // -----------------------------------------------------------------------------
 
 import Foundation
+import SwiftProtobuf
 import XCTest
 
-@testable import SwiftProtobuf
-
 final class Test_Reserved: XCTestCase {
     func testEnumNaming() {
         XCTAssertEqual(SwiftProtoTesting_SwiftReservedTest.Enum.double.rawValue, 1)

+ 1 - 2
Tests/SwiftProtobufTests/Test_SimpleExtensionMap.swift

@@ -13,10 +13,9 @@
 // -----------------------------------------------------------------------------
 
 import Foundation
+import SwiftProtobuf
 import XCTest
 
-@testable import SwiftProtobuf
-
 extension AnyMessageExtension {
     // Support equality to simplify testing of getting the correct errors.
     func isEqual(_ other: any AnyMessageExtension) -> Bool {

+ 1 - 3
Tests/SwiftProtobufTests/Test_TextFormat_Unknown.swift

@@ -13,10 +13,9 @@
 // -----------------------------------------------------------------------------
 
 import Foundation
+import SwiftProtobuf
 import XCTest
 
-@testable import SwiftProtobuf
-
 final class Test_TextFormat_Unknown: XCTestCase, PBTestHelpers {
     typealias MessageTestType = SwiftProtoTesting_TestEmptyMessage
 
@@ -333,7 +332,6 @@ final class Test_TextFormat_Unknown: XCTestCase, PBTestHelpers {
 
         // If we try to parse `data`, the binary decode recursion budget will
         // come into play, instead directly add the data into the unknown fields
-        // (via the @testable interface).
         var msg = MessageTestType()
         msg.unknownFields.append(protobufData: bytes)