From 02b984de060768c983fe0ac6be4f8f3c1ded789f Mon Sep 17 00:00:00 2001 From: tsanto Date: Tue, 12 Nov 2019 20:07:33 +0000 Subject: [PATCH] Create Swift Package --- .../contents.xcworkspacedata | 7 +++++ .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++ Package.swift | 28 +++++++++++++++++++ README.md | 3 ++ Sources/Calculator/Calculator.swift | 8 ++++++ Tests/CalculatorTests/CalculatorTests.swift | 23 +++++++++++++++ Tests/CalculatorTests/XCTestManifests.swift | 9 ++++++ Tests/LinuxMain.swift | 7 +++++ 8 files changed, 93 insertions(+) create mode 100644 .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata create mode 100644 .swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 Package.swift create mode 100644 README.md create mode 100644 Sources/Calculator/Calculator.swift create mode 100644 Tests/CalculatorTests/CalculatorTests.swift create mode 100644 Tests/CalculatorTests/XCTestManifests.swift create mode 100644 Tests/LinuxMain.swift diff --git a/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..706eede --- /dev/null +++ b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..ddce500 --- /dev/null +++ b/Package.swift @@ -0,0 +1,28 @@ +// 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: "Calculator", + products: [ + // Products define the executables and libraries produced by a package, and make them visible to other packages. + .library( + name: "Calculator", + targets: ["Calculator"]), + ], + 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: "Calculator", + dependencies: []), + .testTarget( + name: "CalculatorTests", + dependencies: ["Calculator"]), + ] +) diff --git a/README.md b/README.md new file mode 100644 index 0000000..e9558a5 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Calculator + +A description of this package. diff --git a/Sources/Calculator/Calculator.swift b/Sources/Calculator/Calculator.swift new file mode 100644 index 0000000..787ff36 --- /dev/null +++ b/Sources/Calculator/Calculator.swift @@ -0,0 +1,8 @@ +public class Calculator { + + public init() {} + + public func multitply(_ valueX: Int, with valueY: Int) -> Int { + return valueX * valueY + } +} diff --git a/Tests/CalculatorTests/CalculatorTests.swift b/Tests/CalculatorTests/CalculatorTests.swift new file mode 100644 index 0000000..1eecc7c --- /dev/null +++ b/Tests/CalculatorTests/CalculatorTests.swift @@ -0,0 +1,23 @@ +import XCTest +@testable import Calculator + +final class CalculatorTests: XCTestCase { + var calculator: Calculator! + + override func setUp() { + calculator = Calculator() + } + + func test_should_return_nice_when_multiplying_three_with_three() { + let valueX = 3 + let valueY = 3 + + let result = calculator.multitply(valueX, with: valueY) + + XCTAssertEqual(result, 9) + } + + static var allTests = [ + ("test_should_return_nice_when_multiplying_three_with_three", test_should_return_nice_when_multiplying_three_with_three), + ] +} diff --git a/Tests/CalculatorTests/XCTestManifests.swift b/Tests/CalculatorTests/XCTestManifests.swift new file mode 100644 index 0000000..9c073e5 --- /dev/null +++ b/Tests/CalculatorTests/XCTestManifests.swift @@ -0,0 +1,9 @@ +import XCTest + +#if !canImport(ObjectiveC) +public func allTests() -> [XCTestCaseEntry] { + return [ + testCase(CalculatorTests.allTests), + ] +} +#endif diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift new file mode 100644 index 0000000..f4744ca --- /dev/null +++ b/Tests/LinuxMain.swift @@ -0,0 +1,7 @@ +import XCTest + +import CalculatorTests + +var tests = [XCTestCaseEntry]() +tests += CalculatorTests.allTests() +XCTMain(tests)