Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
version: 2

jobs:
macos:
environment:
TEST_REPORTS: /tmp/test-results
LANG: en_US.UTF-8
macos:
xcode: 10.1.0
steps:
- checkout
- run:
name: Create Test Result Directory
command: mkdir -p $TEST_REPORTS
- run:
name: Run Unit Test - macOS
command: |
cd XCode
set -o pipefail && xcodebuild test -scheme SwifterMac -sdk macosx -destination "arch=x86_64" | xcpretty -c -r html --output $TEST_REPORTS/macOS.html
- run:
name: Run Unit Test - iOS
command: |
cd XCode
set -o pipefail && xcodebuild test -scheme SwifteriOS -sdk iphonesimulator -destination "name=iPhone 8" | xcpretty -c -r html --output $TEST_REPORTS/iOS.html
- run:
name: Run Unit Test - tvOS
command: |
cd XCode
set -o pipefail && xcodebuild test -scheme SwiftertvOS -sdk appletvsimulator -destination "name=Apple TV 4K (at 1080p)" | xcpretty -c -r html --output $TEST_REPORTS/tvOS.html
- run:
name: Run Unit Test - Swift Package Manager
command: |
cd XCode
swift build && swift test
- store_artifacts:
path: /tmp/test-results

linux:
docker:
- image: swift:4.2
steps:
- checkout
- run:
name: Compile code
command: swift build
- run:
name: Run Unit Tests
command: swift test

workflows:
version: 2
tests:
jobs:
- linux
- macos
26 changes: 10 additions & 16 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,17 @@ import PackageDescription

let package = Package(
name: "Swifter",

products: [
.library(
name: "Swifter",
targets: ["Swifter"]),
.executable(
name: "Example",
targets: ["Example"])
.library(name: "Swifter", targets: ["Swifter"]),
.executable(name: "Example", targets: ["Example"])
],

dependencies: [],

targets: [
.target(
name: "Swifter",
dependencies: [],
path: "./Sources"),
.target(
name: "Example",
dependencies: ["Swifter"],
path: "./Example"),
]
)
.target(name: "Swifter", dependencies: [], path: "Sources"),
.target(name: "Example", dependencies: ["Swifter"], path: "Example"),
.testTarget(name: "SwifterTests", dependencies: ["Swifter"], path: "XCode/Tests")
]
)
16 changes: 13 additions & 3 deletions Sources/Socket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import Foundation


public enum SocketError: Error {
case socketCreationFailed(String)
case socketSettingReUseAddrFailed(String)
Expand Down Expand Up @@ -120,7 +119,13 @@ open class Socket: Hashable, Equatable {
/// - Throws: SocketError.recvFailed if unable to read from the socket
open func read() throws -> UInt8 {
var byte: UInt8 = 0
let count = Darwin.read(self.socketFileDescriptor as Int32, &byte, 1)

#if os(Linux)
let count = Glibc.read(self.socketFileDescriptor as Int32, &byte, 1)
#else
let count = Darwin.read(self.socketFileDescriptor as Int32, &byte, 1)
#endif

guard count > 0 else {
throw SocketError.recvFailed(Errno.description())
}
Expand Down Expand Up @@ -158,7 +163,12 @@ open class Socket: Hashable, Equatable {
// Compute next read length in bytes. The bytes read is never more than kBufferLength at once.
let readLength = offset + Socket.kBufferLength < length ? Socket.kBufferLength : length - offset

let bytesRead = Darwin.read(self.socketFileDescriptor as Int32, baseAddress + offset, readLength)
#if os(Linux)
let bytesRead = Glibc.read(self.socketFileDescriptor as Int32, baseAddress + offset, readLength)
#else
let bytesRead = Darwin.read(self.socketFileDescriptor as Int32, baseAddress + offset, readLength)
#endif

guard bytesRead > 0 else {
throw SocketError.recvFailed(Errno.description())
}
Expand Down
7 changes: 7 additions & 0 deletions XCode/LinuxMain.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import XCTest
import SwifterTests

var tests = [XCTestCaseEntry]()
tests += SwifterTests.__allTests()

XCTMain(tests)
469 changes: 312 additions & 157 deletions XCode/Swifter.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions XCode/Swifter.xcodeproj/xcshareddata/xcschemes/SwifterMac.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,26 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "043660C121FED34100497989"
BuildableName = "SwiftermacOSTests.xctest"
BlueprintName = "SwiftermacOSTests"
ReferencedContainer = "container:Swifter.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7AE893FA1C0512C400A29F63"
BuildableName = "Swifter.framework"
BlueprintName = "SwifterMac"
ReferencedContainer = "container:Swifter.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
Expand Down
19 changes: 19 additions & 0 deletions XCode/Swifter.xcodeproj/xcshareddata/xcschemes/SwifteriOS.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,26 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7CCD875B1C66099B0068099B"
BuildableName = "SwifteriOSTests.xctest"
BlueprintName = "SwifteriOSTests"
ReferencedContainer = "container:Swifter.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7AE893E61C05127900A29F63"
BuildableName = "Swifter.framework"
BlueprintName = "SwifteriOS"
ReferencedContainer = "container:Swifter.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1010"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7CCD875B1C66099B0068099B"
BuildableName = "SwifteriOSTests.xctest"
BlueprintName = "SwifteriOSTests"
ReferencedContainer = "container:Swifter.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1010"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "043660C121FED34100497989"
BuildableName = "SwiftermacOSTests.xctest"
BlueprintName = "SwiftermacOSTests"
ReferencedContainer = "container:Swifter.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,26 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "043660D921FED3A300497989"
BuildableName = "SwiftertvOSTests.xctest"
BlueprintName = "SwiftertvOSTests"
ReferencedContainer = "container:Swifter.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "269B47861D3AAAE20042D137"
BuildableName = "Swifter.framework"
BlueprintName = "SwiftertvOS"
ReferencedContainer = "container:Swifter.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1010"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "043660D921FED3A300497989"
BuildableName = "SwiftertvOSTests.xctest"
BlueprintName = "SwiftertvOSTests"
ReferencedContainer = "container:Swifter.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Loading