Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional support for Quick + Nimble testing via Cocoapods #58

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
9851af5
Added a fastlane config file that specifies a "test" lane.
KieranHarper May 1, 2017
d4502c7
Added fastlane's generated readme file to the template's gitignore
KieranHarper May 1, 2017
47fcc40
Template now has a travis CI config file that leverages fastlane
KieranHarper May 1, 2017
5153019
Added note in readme about Travis CI support via Fastlane
KieranHarper May 1, 2017
3ff9b6b
Added a podfile to the template with foundations but no actual pods d…
KieranHarper May 7, 2017
10f9aa6
Made the podfile copying be optional via a question during the script.
KieranHarper May 7, 2017
8e8cc34
Running pod install just before finishing as a convenience to set up …
KieranHarper May 7, 2017
deab13c
Moved the podfile into a folder called "optional" which is ignored wh…
KieranHarper May 7, 2017
8400257
Added podfile template that uses Quick and Nimble for the test targets.
KieranHarper May 7, 2017
c22f359
Fixed issue preventing pod installation from playing nice.
KieranHarper May 11, 2017
b77316a
Moved the podfile into a folder called "optional" which is ignored wh…
KieranHarper May 7, 2017
d7e8a91
Added podfile template that uses Quick and Nimble for the test targets.
KieranHarper May 7, 2017
a67ab97
Merge branch 'quick+nimble' of https://github.com/KieranHarper/SwiftP…
KieranHarper May 12, 2017
1059ecf
Quick+Nimble option now provides example test file instead of the def…
KieranHarper May 13, 2017
ddf67cb
Added Quick and Nimble to the SPM package file and made linux testing…
KieranHarper May 13, 2017
7de1bc0
Added note to readme about Q+N
KieranHarper May 13, 2017
702ac84
Merge pull request #1 from KieranHarper/travis+fastlane
KieranHarper Dec 9, 2017
87b67d7
Merge branch 'master' into quick+nimble
KieranHarper Dec 9, 2017
da9b4f9
Merge branch 'master' into quick+nimble
KieranHarper Dec 9, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ SwiftPlate will generate Xcode projects for you in seconds, that support:
- [x] watchOS
- [x] tvOS
- [x] Linux
- [x] Quick + Nimble testing
- [x] Travis CI (via Fastlane - Mac environment only)

Just run `swiftplate`, and you’ll be presented with a simple step-by-step guide:

Expand Down
1 change: 1 addition & 0 deletions Template/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/README.md
6 changes: 6 additions & 0 deletions Template/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: objective-c
osx_image: xcode8.3
before_install:
- gem update fastlane
script:
- fastlane test
69 changes: 69 additions & 0 deletions Template/fastlane/Fastfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Customise this file, documentation can be found here:
# https://github.com/fastlane/fastlane/tree/master/fastlane/docs
# All available actions: https://docs.fastlane.tools/actions
# can also be listed using the `fastlane actions` command

# Change the syntax highlighting to Ruby
# All lines starting with a # are ignored when running `fastlane`

# If you want to automatically update fastlane if a new version is available:
# update_fastlane

# This is the minimum version number required.
# Update this, if you use features of a newer version
fastlane_version "2.16.0"

default_platform :ios

platform :ios do

desc "Builds the framework and runs all the tests"
lane :test do

# Prevent timeout issues
ENV["FASTLANE_XCODE_LIST_TIMEOUT"] = "120"

# Just build the watchOS target (no tests)
xcodebuild(
project: "{PROJECT}.xcodeproj",
scheme: "{PROJECT}-watchOS",
clean: true,
build: true
)

# Build and test the macOS target
scan(
project: "{PROJECT}.xcodeproj",
scheme: "{PROJECT}-macOS",
devices: [
# (deliberately empty, will use the mac this is running on)
],
clean: true,
skip_slack: true
)

# Build and test the iOS target
scan(
project: "{PROJECT}.xcodeproj",
scheme: "{PROJECT}-iOS",
devices: [
"iPhone SE",
# "iPhone 6",
# "iPhone 7 Plus",
],
clean: true,
skip_slack: true
)

# Build and test the tvOS target
scan(
project: "{PROJECT}.xcodeproj",
scheme: "{PROJECT}-tvOS",
devices: [
"Apple TV 1080p",
],
clean: true,
skip_slack: true
)
end
end
40 changes: 40 additions & 0 deletions Template/optional/ExampleTests-quick+nimble.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// {PROJECT}Tests.swift
// {ORGANIZATION}
//
// Created by {AUTHOR} on {TODAY}.
// Copyright © {YEAR} {ORGANIZATION}. All rights reserved.
//

import Quick
import Nimble
import {PROJECT}

class {PROJECT}Spec: QuickSpec {

override func spec() {

// For more information about Quick and Nimble:
// https://github.com/Quick/Quick
// https://github.com/Quick/Nimble

// EXAMPLES:

describe("A bunch of numbers") {
it("should add up") {
expect(1 + 1).to(equal(2))
}
it("should behave logically") {
expect(1.2).to(beCloseTo(1.1, within: 0.1))
expect(3) > 2
}
}

describe("Some other stuff") {
it("should make sense") {
expect("seahorse").to(contain("sea"))
expect(["Atlantic", "Pacific"]).toNot(contain("Mississippi"))
}
}
}
}
7 changes: 7 additions & 0 deletions Template/optional/LinuxMain-quick+nimble.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import XCTest
import Quick
@testable import {PROJECT}Tests

Quick.QCKMain([
{PROJECT}Tests.self,
])
9 changes: 9 additions & 0 deletions Template/optional/Package-quick+nimble.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import PackageDescription

let package = Package(
name: "{PROJECT}",
dependencies: [
.Package(url: "https://github.com/Quick/Quick.git", majorVersion: 1),
.Package(url: "https://github.com/Quick/Nimble.git", majorVersion: 6)
]
)
52 changes: 52 additions & 0 deletions Template/optional/Podfile-blank
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
workspace '{PROJECT}'
inhibit_all_warnings!
use_frameworks!


# Shared declarations

def dependency_pods
# Fill in as needed
end

def testing_pods
# Fill in as needed
end


# Framework targets

target '{PROJECT}-iOS' do
platform :ios, '8.0'
dependency_pods
end

target '{PROJECT}-macOS' do
platform :osx, '10.9'
dependency_pods
end

target '{PROJECT}-tvOS' do
platform :tvos, '9.0'
dependency_pods
end

target '{PROJECT}-watchOS' do
platform :watchos, '2.0'
dependency_pods
end


# Test targets

target '{PROJECT}-iOS Tests' do
testing_pods
end

target '{PROJECT}-macOS Tests' do
testing_pods
end

target '{PROJECT}-tvOS Tests' do
testing_pods
end
53 changes: 53 additions & 0 deletions Template/optional/Podfile-quick+nimble
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
workspace '{PROJECT}'
inhibit_all_warnings!
use_frameworks!


# Shared declarations

def dependency_pods
# Fill in as needed
end

def testing_pods
pod 'Quick'
pod 'Nimble'
end


# Framework targets

target '{PROJECT}-iOS' do
platform :ios, '8.0'
dependency_pods
end

target '{PROJECT}-macOS' do
platform :osx, '10.9'
dependency_pods
end

target '{PROJECT}-tvOS' do
platform :tvos, '9.0'
dependency_pods
end

target '{PROJECT}-watchOS' do
platform :watchos, '2.0'
dependency_pods
end


# Test targets

target '{PROJECT}-iOS Tests' do
testing_pods
end

target '{PROJECT}-macOS Tests' do
testing_pods
end

target '{PROJECT}-tvOS Tests' do
testing_pods
end
1 change: 0 additions & 1 deletion Template/{PROJECT}.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,6 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
ONLY_ACTIVE_ARCH = NO;
PRODUCT_BUNDLE_IDENTIFIER = "com.{PROJECT}.{PROJECT}-iOS";
PRODUCT_NAME = {PROJECT};
SKIP_INSTALL = YES;
Expand Down
49 changes: 48 additions & 1 deletion main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ let authorName = arguments.authorName ?? askForAuthorName()
let authorEmail = arguments.authorEmail ?? askForAuthorEmail()
let gitHubURL = arguments.githubURL ?? askForGitHubURL(destination: destination)
let organizationName = arguments.organizationName ?? askForOptionalInfo(question: "🏢 What's your organization name?")
let useCocoapods = askForBooleanInfo(question: "🛠 Use Cocoapods to develop and test your project?")
let useQuickAndNimble = askForBooleanInfo(question: "🔍 Use Quick and Nimble testing frameworks? (via Cocoapods)")
let installCocoapods = useCocoapods || useQuickAndNimble

print("---------------------------------------------------------------------")
print("SwiftPlate will now generate a project with the following parameters:")
Expand All @@ -348,6 +351,14 @@ if let organizationName = organizationName {
print("🏢 Organization Name: \(organizationName)")
}

if installCocoapods {
if useQuickAndNimble {
print("🔍 Using Quick and Nimble (via Cocoapods)")
} else {
print("🛠 Using Cocoapods")
}
}

print("---------------------------------------------------------------------")

if !arguments.forceEnabled {
Expand All @@ -363,6 +374,7 @@ do {
let temporaryDirectoryPath = destination + "/swiftplate_temp"
let gitClonePath = "\(temporaryDirectoryPath)/SwiftPlate"
let templatePath = "\(gitClonePath)/Template"
let optionalItemsPath = templatePath + "/Optional"

performCommand(description: "Removing any previous temporary folder") {
try? fileManager.removeItem(atPath: temporaryDirectoryPath)
Expand All @@ -379,11 +391,12 @@ do {

try performCommand(description: "Copying template folder") {
let ignorableItems: Set<String> = ["readme.md", "license"]
let ignoredItems = try fileManager.contentsOfDirectory(atPath: destination).map {
var ignoredItems = try fileManager.contentsOfDirectory(atPath: destination).map {
$0.lowercased()
}.filter {
ignorableItems.contains($0)
}
ignoredItems.append("optional")

for itemName in try fileManager.contentsOfDirectory(atPath: templatePath) {
let originPath = templatePath + "/" + itemName
Expand All @@ -396,6 +409,34 @@ do {

try fileManager.copyItem(atPath: originPath, toPath: destinationPath)
}

if useCocoapods && !useQuickAndNimble {
let originPath = optionalItemsPath + "/" + "Podfile-blank"
let destinationPath = destination + "/" + "Podfile"
try fileManager.copyItem(atPath: originPath, toPath: destinationPath)
}

if useQuickAndNimble {

let podfileOriginPath = optionalItemsPath + "/" + "Podfile-quick+nimble"
let podfileDestinationPath = destination + "/" + "Podfile"
try fileManager.copyItem(atPath: podfileOriginPath, toPath: podfileDestinationPath)

let linuxOriginPath = optionalItemsPath + "/" + "LinuxMain-quick+nimble.swift"
let linuxDestinationPath = destination + "/Tests/" + "LinuxMain.swift"
try fileManager.removeItem(atPath: linuxDestinationPath)
try fileManager.copyItem(atPath: linuxOriginPath, toPath: linuxDestinationPath)

let testsOriginPath = optionalItemsPath + "/" + "ExampleTests-quick+nimble.swift"
let testsDestinationPath = destination + "/Tests/{PROJECT}Tests/" + "{PROJECT}Tests.swift"
try fileManager.removeItem(atPath: testsDestinationPath)
try fileManager.copyItem(atPath: testsOriginPath, toPath: testsDestinationPath)

let packageOriginPath = optionalItemsPath + "/" + "Package-quick+nimble.swift"
let packageDestinationPath = destination + "/" + "Package.swift"
try fileManager.removeItem(atPath: packageDestinationPath)
try fileManager.copyItem(atPath: packageOriginPath, toPath: packageDestinationPath)
}
}

try performCommand(description: "Removing temporary folder") {
Expand All @@ -413,6 +454,12 @@ do {

try replacer.process(filesInFolderWithPath: destination)
}

if installCocoapods {
performCommand(description: "Setting up Cocoapods (running pod install)") {
Process().launchBash(withCommand: "pod install")
}
}

print("All done! 🎉 Good luck with your project! 🚀")
} catch {
Expand Down