Adds swift demo.

This commit is contained in:
Henning Dieterichs
2020-03-22 16:34:43 +01:00
parent 0030047df3
commit aac78db2f6
10 changed files with 142 additions and 0 deletions

5
demos/swift/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/

16
demos/swift/.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,16 @@
// .vscode/launch.json
{
"version": "0.2.0",
"configurations": [
// Running executables
{
"type": "lldb",
"request": "launch",
"name": "Run your Executable",
"program": "${workspaceFolder}/.build/debug/swiftDemo",
"args": [],
"cwd": "${workspaceFolder}",
"preLaunchTask": "swift-build"
}
]
}

6
demos/swift/.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,6 @@
{
// You need to adapt this path to your swift installation.
// See here for more info:
// https://github.com/vadimcn/vscode-lldb/issues/234
"lldb.library": "/home/hediet/swift-5.1.5-RELEASE-ubuntu14.04/usr/lib/liblldb.so"
}

23
demos/swift/.vscode/tasks.json vendored Normal file
View File

@@ -0,0 +1,23 @@
{
"version": "2.0.0",
"tasks": [
// compile your SPM project
{
"label": "swift-build",
"type": "shell",
"command": "swift build" // for TensorFlow add -Xlinker -ltensorflow
},
// compile your SPM tests
{
"label": "swift-build-tests",
"type": "process",
"command": "swift",
"group": "build",
"args": [
"build",
"--build-tests"
// for TensorFlow add "-Xlinker", "-ltensorflow"
]
}
]
}

22
demos/swift/Package.swift Normal file
View File

@@ -0,0 +1,22 @@
// swift-tools-version:5.1
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "swiftDemo",
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "swiftDemo",
dependencies: []),
.testTarget(
name: "swiftDemoTests",
dependencies: ["swiftDemo"]),
]
)

View File

@@ -0,0 +1,5 @@
let s = "{\"kind\":{\"graph\":true},"
+ "\"nodes\":[{\"id\":\"1\"},{\"id\":\"2\"}],"
+ "\"edges\":[{\"from\":\"1\",\"to\":\"2\"}]}";
print(s)

View File

@@ -0,0 +1,7 @@
import XCTest
import swiftTests
var tests = [XCTestCaseEntry]()
tests += swiftTests.allTests()
XCTMain(tests)

View File

@@ -0,0 +1,9 @@
import XCTest
#if !canImport(ObjectiveC)
public func allTests() -> [XCTestCaseEntry] {
return [
testCase(swiftTests.allTests),
]
}
#endif

View File

@@ -0,0 +1,47 @@
import XCTest
import class Foundation.Bundle
final class swiftTests: XCTestCase {
func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct
// results.
// Some of the APIs that we use below are available in macOS 10.13 and above.
guard #available(macOS 10.13, *) else {
return
}
let fooBinary = productsDirectory.appendingPathComponent("swift")
let process = Process()
process.executableURL = fooBinary
let pipe = Pipe()
process.standardOutput = pipe
try process.run()
process.waitUntilExit()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = String(data: data, encoding: .utf8)
XCTAssertEqual(output, "Hello, world!\n")
}
/// Returns path to the built products directory.
var productsDirectory: URL {
#if os(macOS)
for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") {
return bundle.bundleURL.deletingLastPathComponent()
}
fatalError("couldn't find the products directory")
#else
return Bundle.main.bundleURL
#endif
}
static var allTests = [
("testExample", testExample),
]
}

2
demos/swift/main.swift Normal file
View File

@@ -0,0 +1,2 @@
import Swift
print("Hello, World!")