Adds swift demo.
This commit is contained in:
5
demos/swift/.gitignore
vendored
Normal file
5
demos/swift/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
.DS_Store
|
||||
/.build
|
||||
/Packages
|
||||
/*.xcodeproj
|
||||
xcuserdata/
|
||||
16
demos/swift/.vscode/launch.json
vendored
Normal file
16
demos/swift/.vscode/launch.json
vendored
Normal 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
6
demos/swift/.vscode/settings.json
vendored
Normal 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
23
demos/swift/.vscode/tasks.json
vendored
Normal 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
22
demos/swift/Package.swift
Normal 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"]),
|
||||
]
|
||||
)
|
||||
5
demos/swift/Sources/swiftDemo/main.swift
Normal file
5
demos/swift/Sources/swiftDemo/main.swift
Normal file
@@ -0,0 +1,5 @@
|
||||
let s = "{\"kind\":{\"graph\":true},"
|
||||
+ "\"nodes\":[{\"id\":\"1\"},{\"id\":\"2\"}],"
|
||||
+ "\"edges\":[{\"from\":\"1\",\"to\":\"2\"}]}";
|
||||
|
||||
print(s)
|
||||
7
demos/swift/Tests/LinuxMain.swift
Normal file
7
demos/swift/Tests/LinuxMain.swift
Normal file
@@ -0,0 +1,7 @@
|
||||
import XCTest
|
||||
|
||||
import swiftTests
|
||||
|
||||
var tests = [XCTestCaseEntry]()
|
||||
tests += swiftTests.allTests()
|
||||
XCTMain(tests)
|
||||
9
demos/swift/Tests/swiftDemoTests/XCTestManifests.swift
Normal file
9
demos/swift/Tests/swiftDemoTests/XCTestManifests.swift
Normal file
@@ -0,0 +1,9 @@
|
||||
import XCTest
|
||||
|
||||
#if !canImport(ObjectiveC)
|
||||
public func allTests() -> [XCTestCaseEntry] {
|
||||
return [
|
||||
testCase(swiftTests.allTests),
|
||||
]
|
||||
}
|
||||
#endif
|
||||
47
demos/swift/Tests/swiftDemoTests/swiftDemoTests.swift
Normal file
47
demos/swift/Tests/swiftDemoTests/swiftDemoTests.swift
Normal 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
2
demos/swift/main.swift
Normal file
@@ -0,0 +1,2 @@
|
||||
import Swift
|
||||
print("Hello, World!")
|
||||
Reference in New Issue
Block a user