Skip to content

[CocoaPods] integration tests #433

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

Merged
merged 1 commit into from
May 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ before_install:
- gem install xcpretty --no-document
script:
- make test
- cd CocoaPodsTests && make test
osx_image: xcode7.3
1 change: 1 addition & 0 deletions CocoaPodsTests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gems/
4 changes: 4 additions & 0 deletions CocoaPodsTests/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

gem 'cocoapods'
gem 'minitest'
65 changes: 65 additions & 0 deletions CocoaPodsTests/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (4.2.6)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
claide (1.0.0)
cocoapods (1.0.0)
activesupport (>= 4.0.2)
claide (>= 1.0.0, < 2.0)
cocoapods-core (= 1.0.0)
cocoapods-deintegrate (>= 1.0.0, < 2.0)
cocoapods-downloader (>= 1.0.0, < 2.0)
cocoapods-plugins (>= 1.0.0, < 2.0)
cocoapods-search (>= 1.0.0, < 2.0)
cocoapods-stats (>= 1.0.0, < 2.0)
cocoapods-trunk (>= 1.0.0, < 2.0)
cocoapods-try (>= 1.0.0, < 2.0)
colored (~> 1.2)
escape (~> 0.0.4)
fourflusher (~> 0.3.0)
molinillo (~> 0.4.5)
nap (~> 1.0)
xcodeproj (>= 1.0.0, < 2.0)
cocoapods-core (1.0.0)
activesupport (>= 4.0.2)
fuzzy_match (~> 2.0.4)
nap (~> 1.0)
cocoapods-deintegrate (1.0.0)
cocoapods-downloader (1.0.0)
cocoapods-plugins (1.0.0)
nap
cocoapods-search (1.0.0)
cocoapods-stats (1.0.0)
cocoapods-trunk (1.0.0)
nap (>= 0.8, < 2.0)
netrc (= 0.7.8)
cocoapods-try (1.0.0)
colored (1.2)
escape (0.0.4)
fourflusher (0.3.0)
fuzzy_match (2.0.4)
i18n (0.7.0)
json (1.8.3)
minitest (5.8.4)
molinillo (0.4.5)
nap (1.1.0)
netrc (0.7.8)
thread_safe (0.3.5)
tzinfo (1.2.2)
thread_safe (~> 0.1)
xcodeproj (1.0.0)
activesupport (>= 3)
claide (>= 1.0.0, < 2.0)
colored (~> 1.2)

PLATFORMS
ruby

DEPENDENCIES
cocoapods
minitest
10 changes: 10 additions & 0 deletions CocoaPodsTests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
test: install
@set -e; \
for test in *_test.rb; do \
bundle exec ./$$test; \
done

install:
@bundle install --path gems

.PHONY: test install
33 changes: 33 additions & 0 deletions CocoaPodsTests/integration_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env ruby

require 'minitest/autorun'
require_relative 'test_running_validator'

class IntegrationTest < Minitest::Test

def test_validate_project
assert validator.validate, "validation failed: #{validator.failure_reason}"
end

private

def validator
@validator ||= TestRunningValidator.new(podspec, []).tap do |validator|
validator.test_files = Dir["#{project_test_dir}/*.swift"]
validator.config.verbose = true
validator.no_clean = true
validator.use_frameworks = true
validator.fail_fast = true
validator.local = true
validator.allow_warnings = true
end
end

def podspec
File.expand_path(File.dirname(__FILE__) + '/../SQLite.swift.podspec')
end

def project_test_dir
File.expand_path(File.dirname(__FILE__) + '/../SQLiteTests')
end
end
91 changes: 91 additions & 0 deletions CocoaPodsTests/test_running_validator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
require 'cocoapods'
require 'cocoapods/validator'
require 'fileutils'

class TestRunningValidator < Pod::Validator
APP_TARGET = 'App'
TEST_TARGET = 'Tests'

attr_accessor :test_files

def create_app_project
super.tap do
project = Xcodeproj::Project.open(validation_dir + "#{APP_TARGET}.xcodeproj")
create_test_target(project)
end
end

def install_pod
super.tap do
if local?
FileUtils.ln_s file.dirname, validation_dir + "Pods/#{spec.name}"
end
end
end

def podfile_from_spec(*args)
super(*args).tap do |pod_file|
add_test_target(pod_file)
end
end

def build_pod
super
Pod::UI.message "\Testing with xcodebuild.\n".yellow do
run_tests
end
end

private
def create_test_target(project)
test_target = project.new_target(:unit_test_bundle, TEST_TARGET, consumer.platform_name, deployment_target)
group = project.new_group(TEST_TARGET)
test_target.add_file_references(test_files.map { |file| group.new_file(file) })
project.save
create_test_scheme(project, test_target)
project
end

def create_test_scheme(project, test_target)
project.recreate_user_schemes
test_scheme = Xcodeproj::XCScheme.new(test_scheme_path(project))
test_scheme.add_test_target(test_target)
test_scheme.save!
end

def test_scheme_path(project)
Xcodeproj::XCScheme.user_data_dir(project.path) + "#{TEST_TARGET}.xcscheme"
end

def add_test_target(pod_file)
app_target = pod_file.target_definitions[APP_TARGET]
Pod::Podfile::TargetDefinition.new(TEST_TARGET, app_target)
end

def run_tests
command = %W(clean test -workspace #{APP_TARGET}.xcworkspace -scheme #{TEST_TARGET} -configuration Debug)
case consumer.platform_name
when :ios
command += %w(CODE_SIGN_IDENTITY=- -sdk iphonesimulator)
command += Fourflusher::SimControl.new.destination('iPhone 4s', deployment_target)
when :osx
command += %w(LD_RUNPATH_SEARCH_PATHS=@loader_path/../Frameworks)
when :tvos
command += %w(CODE_SIGN_IDENTITY=- -sdk appletvsimulator)
command += Fourflusher::SimControl.new.destination('Apple TV 1080p', deployment_target)
else
return # skip watchos
end

output, status = Dir.chdir(validation_dir) { _xcodebuild(command) }
unless status.success?
message = 'Returned an unsuccessful exit code.'
if config.verbose?
message += "\nXcode output: \n#{output}\n"
else
message += ' You can use `--verbose` for more information.'
end
error('xcodebuild', message)
end
end
end
4 changes: 2 additions & 2 deletions SQLiteTests/FTS4Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class FTS4Tests : XCTestCase {
}

class FTS4IntegrationTests : SQLiteTestCase {

#if !SQLITE_SWIFT_STANDALONE
func test_registerTokenizer_registersTokenizer() {
let emails = VirtualTable("emails")
let subject = Expression<String?>("subject")
Expand Down Expand Up @@ -73,5 +73,5 @@ class FTS4IntegrationTests : SQLiteTestCase {
try! db.run(emails.insert(subject <- "Aún más cáfe!"))
XCTAssertEqual(1, db.scalar(emails.filter(emails.match("aun")).count))
}

#endif
}