File tree 4 files changed +76
-0
lines changed
Tests/ScriptingHelpersTests
4 files changed +76
-0
lines changed Original file line number Diff line number Diff line change
1
+ .DS_Store
2
+ /.build
3
+ /Packages
4
+ /* .xcodeproj
5
+ xcuserdata /
6
+ DerivedData /
7
+ .swiftpm /config /registries.json
8
+ .swiftpm /xcode /package.xcworkspace /contents.xcworkspacedata
9
+ .netrc
Original file line number Diff line number Diff line change
1
+ // swift-tools-version: 5.8
2
+ // The swift-tools-version declares the minimum version of Swift required to build this package.
3
+
4
+ import PackageDescription
5
+
6
+ let package = Package (
7
+ name: " ScriptingHelpers " ,
8
+ products: [
9
+ . library(
10
+ name: " ScriptingHelpers " ,
11
+ targets: [ " ScriptingHelpers " ] ) ,
12
+ ] ,
13
+ targets: [
14
+ . target(
15
+ name: " ScriptingHelpers " ) ,
16
+ . testTarget(
17
+ name: " ScriptingHelpersTests " ,
18
+ dependencies: [ " ScriptingHelpers " ] ) ,
19
+ ] )
Original file line number Diff line number Diff line change
1
+ // The Swift Programming Language
2
+ // https://docs.swift.org/swift-book
3
+
4
+ import Foundation
5
+
6
+ extension String : Error { }
7
+
8
+ @discardableResult
9
+ public func shell( _ command: String ) -> Result < String , String > {
10
+ let task = Process ( )
11
+ let outputPipe = Pipe ( )
12
+ let errorPipe = Pipe ( )
13
+
14
+ task. standardOutput = outputPipe
15
+ task. standardError = errorPipe
16
+ task. arguments = [ " -c " , command]
17
+ task. launchPath = " /bin/zsh "
18
+ task. standardInput = nil
19
+ task. launch ( )
20
+
21
+ let outputData = outputPipe. fileHandleForReading. readDataToEndOfFile ( )
22
+ let errorData = errorPipe. fileHandleForReading. readDataToEndOfFile ( )
23
+ if let output = String ( data: outputData, encoding: . utf8) {
24
+ return . success( output)
25
+ } else if let error = String ( data: errorData, encoding: . utf8) {
26
+ return . failure( error)
27
+ }
28
+
29
+ return . failure( " Unexpected Error " )
30
+ }
31
+
32
+ public func print( _ message: String , verbose: Bool ) {
33
+ if verbose {
34
+ print ( message)
35
+ }
36
+ }
Original file line number Diff line number Diff line change
1
+ import XCTest
2
+ @testable import ScriptingHelpers
3
+
4
+ final class ScriptingHelpersTests : XCTestCase {
5
+ func testExample( ) throws {
6
+ // XCTest Documenation
7
+ // https://developer.apple.com/documentation/xctest
8
+
9
+ // Defining Test Cases and Test Methods
10
+ // https://developer.apple.com/documentation/xctest/defining_test_cases_and_test_methods
11
+ }
12
+ }
You can’t perform that action at this time.
0 commit comments