Skip to content
This repository has been archived by the owner on Apr 20, 2024. It is now read-only.

Latest commit

 

History

History
102 lines (80 loc) · 1.83 KB

how-to-build-a-package.md

File metadata and controls

102 lines (80 loc) · 1.83 KB

How to build a package

Automatically with Swift Package Manager (SPM)

This is by far the easiest way to get setup. First, create a directory:

mkdir MyPackage
cd MyPackage

Now, use SPM to init your package:

swift package init --type library

All of your files will be generated automatically and you're now ready to setup Travis and Codecov

Manually

Package manifest

Package.swift file in the root

import PackageDescription

let package = Package(
    name: "MyPackage",
    dependencies: [
        // Add dependencies
       .Package(url: "https://github.com/vapor/vapor.git", majorVersion: 1),                      
    ]
)

Source

Create and put your sources in the directory Sources/MyPackage/

Tests

Create and put your tests in the directory Tests/MyPackageTests/

In order to support Linux, add Tests/LinuxMain.swift the following file with all of your XCTestCases.

import XCTest
@testable import MyPackageTests

XCTMain([
    testCase(MyPackageTests.allTests)
])

Example of TestCase

import XCTest
@testable import NeededImport

class MyPackageTests: XCTestCase {
    static var allTests = [
        ("test", test)
    ]
    
    func test() {
        XCTAssertEqual("abc", "abc")
    }
}

Travis and Codecov

For Travis add the following file to your project root:

.travis.yml

os:
  - linux
  - osx
language: generic
sudo: required
dist: trusty
osx_image: xcode8
script:
  - eval "$(curl -sL https://swift.vapor.sh/ci)"
  - eval "$(curl -sL https://swift.vapor.sh/codecov)"

For Codecov add the following file to your project root:

.codecov.yml

coverage:
  ignore:
    - "Whatever folder"

XCode

Generate an Xcode project:

vapor xcode -y

The hotkey to build and run unit tests is cmd+u.