diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..02c0875 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.DS_Store +/.build +/Packages +/*.xcodeproj diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..84bbe84 --- /dev/null +++ b/Package.swift @@ -0,0 +1,22 @@ +// swift-tools-version:4.2 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "AOC2018", + 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: "AOC2018", + dependencies: []), + .testTarget( + name: "AOC2018Tests", + dependencies: ["AOC2018"]), + ] +) diff --git a/Sources/AOC2018/main.swift b/Sources/AOC2018/main.swift new file mode 100644 index 0000000..f7cf60e --- /dev/null +++ b/Sources/AOC2018/main.swift @@ -0,0 +1 @@ +print("Hello, world!") diff --git a/Tests/AOC2018Tests/AOC2018Tests.swift b/Tests/AOC2018Tests/AOC2018Tests.swift new file mode 100644 index 0000000..32904f8 --- /dev/null +++ b/Tests/AOC2018Tests/AOC2018Tests.swift @@ -0,0 +1,47 @@ +import XCTest +import class Foundation.Bundle + +final class AOC2018Tests: 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("AOC2018") + + 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), + ] +} diff --git a/Tests/AOC2018Tests/XCTestManifests.swift b/Tests/AOC2018Tests/XCTestManifests.swift new file mode 100644 index 0000000..b6b57bb --- /dev/null +++ b/Tests/AOC2018Tests/XCTestManifests.swift @@ -0,0 +1,9 @@ +import XCTest + +#if !os(macOS) +public func allTests() -> [XCTestCaseEntry] { + return [ + testCase(AOC2018Tests.allTests), + ] +} +#endif \ No newline at end of file diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift new file mode 100644 index 0000000..19c25a2 --- /dev/null +++ b/Tests/LinuxMain.swift @@ -0,0 +1,7 @@ +import XCTest + +import AOC2018Tests + +var tests = [XCTestCaseEntry]() +tests += AOC2018Tests.allTests() +XCTMain(tests) \ No newline at end of file