Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.
Open
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
4 changes: 2 additions & 2 deletions Sources/Core/Process+Execute.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !os(iOS)
#if !os(iOS) && !os(tvOS) && !os(watchOS)
import NIO

/// Different types of process output.
Expand Down Expand Up @@ -97,7 +97,7 @@ extension Process {

// will be set to false when the program is done
var running = true

// readabilityHandler doesn't work on linux, so we are left with this hack
DispatchQueue.global().async {
while running {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Core/Thread+Async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ extension Thread {
/// - parameters:
/// - work: Closure to be called on new thread.
public static func async(_ work: @escaping () -> Void) {
if #available(macOS 10.12, iOS 10.0, *) {
if #available(macOS 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *) {
Thread.detachNewThread(work)
} else {
fatalError("macOS 10.12/iOS 10.0 or later required to call Thread.async(_:)")
fatalError("macOS 10.12/iOS 10.0/tvOS 10.0/watchOS 3.0 or later required to call Thread.async(_:)")
}
}
}
8 changes: 8 additions & 0 deletions Tests/CoreTests/CoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ import XCTest

class CoreTests: XCTestCase {
func testProcessExecute() throws {
#if !os(iOS) && !os(tvOS) && !os(watchOS)
try XCTAssertEqual(Process.execute("/bin/echo", "hi"), "hi")
#endif
}

func testProcessExecuteCurl() throws {
#if !os(iOS) && !os(tvOS) && !os(watchOS)
let res = try Process.execute("/usr/bin/curl", "--verbose", "https://vapor.codes")
XCTAssertEqual(res.contains("<title>Vapor"), true)
#endif
}

func testProcessAsyncExecute() throws {
#if !os(iOS) && !os(tvOS) && !os(watchOS)
let eventLoop = MultiThreadedEventLoopGroup(numberOfThreads: 1)
var lastOutput: ProcessOutput?
let status = try Process.asyncExecute("/bin/echo", "hi", on: eventLoop) { output in
Expand All @@ -26,10 +31,13 @@ class CoreTests: XCTestCase {
} else {
XCTFail("no output")
}
#endif
}

func testProcessExecuteMissing() throws {
#if !os(iOS) && !os(tvOS) && !os(watchOS)
XCTAssertThrowsError(try Process.execute("foo", "hi"), "hi")
#endif
}

func testBase64() {
Expand Down