Skip to content

Commit 76fb35d

Browse files
committed
Merge pull request #433 from jberkel/cocoapods-tests
[CocoaPods] integration tests
2 parents c82f986 + aacdde0 commit 76fb35d

File tree

8 files changed

+207
-2
lines changed

8 files changed

+207
-2
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ before_install:
66
- gem install xcpretty --no-document
77
script:
88
- make test
9+
- cd CocoaPodsTests && make test
910
osx_image: xcode7.3

CocoaPodsTests/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
gems/

CocoaPodsTests/Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'cocoapods'
4+
gem 'minitest'

CocoaPodsTests/Gemfile.lock

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
activesupport (4.2.6)
5+
i18n (~> 0.7)
6+
json (~> 1.7, >= 1.7.7)
7+
minitest (~> 5.1)
8+
thread_safe (~> 0.3, >= 0.3.4)
9+
tzinfo (~> 1.1)
10+
claide (1.0.0)
11+
cocoapods (1.0.0)
12+
activesupport (>= 4.0.2)
13+
claide (>= 1.0.0, < 2.0)
14+
cocoapods-core (= 1.0.0)
15+
cocoapods-deintegrate (>= 1.0.0, < 2.0)
16+
cocoapods-downloader (>= 1.0.0, < 2.0)
17+
cocoapods-plugins (>= 1.0.0, < 2.0)
18+
cocoapods-search (>= 1.0.0, < 2.0)
19+
cocoapods-stats (>= 1.0.0, < 2.0)
20+
cocoapods-trunk (>= 1.0.0, < 2.0)
21+
cocoapods-try (>= 1.0.0, < 2.0)
22+
colored (~> 1.2)
23+
escape (~> 0.0.4)
24+
fourflusher (~> 0.3.0)
25+
molinillo (~> 0.4.5)
26+
nap (~> 1.0)
27+
xcodeproj (>= 1.0.0, < 2.0)
28+
cocoapods-core (1.0.0)
29+
activesupport (>= 4.0.2)
30+
fuzzy_match (~> 2.0.4)
31+
nap (~> 1.0)
32+
cocoapods-deintegrate (1.0.0)
33+
cocoapods-downloader (1.0.0)
34+
cocoapods-plugins (1.0.0)
35+
nap
36+
cocoapods-search (1.0.0)
37+
cocoapods-stats (1.0.0)
38+
cocoapods-trunk (1.0.0)
39+
nap (>= 0.8, < 2.0)
40+
netrc (= 0.7.8)
41+
cocoapods-try (1.0.0)
42+
colored (1.2)
43+
escape (0.0.4)
44+
fourflusher (0.3.0)
45+
fuzzy_match (2.0.4)
46+
i18n (0.7.0)
47+
json (1.8.3)
48+
minitest (5.8.4)
49+
molinillo (0.4.5)
50+
nap (1.1.0)
51+
netrc (0.7.8)
52+
thread_safe (0.3.5)
53+
tzinfo (1.2.2)
54+
thread_safe (~> 0.1)
55+
xcodeproj (1.0.0)
56+
activesupport (>= 3)
57+
claide (>= 1.0.0, < 2.0)
58+
colored (~> 1.2)
59+
60+
PLATFORMS
61+
ruby
62+
63+
DEPENDENCIES
64+
cocoapods
65+
minitest

CocoaPodsTests/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
test: install
2+
@set -e; \
3+
for test in *_test.rb; do \
4+
bundle exec ./$$test; \
5+
done
6+
7+
install:
8+
@bundle install --path gems
9+
10+
.PHONY: test install

CocoaPodsTests/integration_test.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'minitest/autorun'
4+
require_relative 'test_running_validator'
5+
6+
class IntegrationTest < Minitest::Test
7+
8+
def test_validate_project
9+
assert validator.validate, "validation failed: #{validator.failure_reason}"
10+
end
11+
12+
private
13+
14+
def validator
15+
@validator ||= TestRunningValidator.new(podspec, []).tap do |validator|
16+
validator.test_files = Dir["#{project_test_dir}/*.swift"]
17+
validator.config.verbose = true
18+
validator.no_clean = true
19+
validator.use_frameworks = true
20+
validator.fail_fast = true
21+
validator.local = true
22+
validator.allow_warnings = true
23+
end
24+
end
25+
26+
def podspec
27+
File.expand_path(File.dirname(__FILE__) + '/../SQLite.swift.podspec')
28+
end
29+
30+
def project_test_dir
31+
File.expand_path(File.dirname(__FILE__) + '/../SQLiteTests')
32+
end
33+
end
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
require 'cocoapods'
2+
require 'cocoapods/validator'
3+
require 'fileutils'
4+
5+
class TestRunningValidator < Pod::Validator
6+
APP_TARGET = 'App'
7+
TEST_TARGET = 'Tests'
8+
9+
attr_accessor :test_files
10+
11+
def create_app_project
12+
super.tap do
13+
project = Xcodeproj::Project.open(validation_dir + "#{APP_TARGET}.xcodeproj")
14+
create_test_target(project)
15+
end
16+
end
17+
18+
def install_pod
19+
super.tap do
20+
if local?
21+
FileUtils.ln_s file.dirname, validation_dir + "Pods/#{spec.name}"
22+
end
23+
end
24+
end
25+
26+
def podfile_from_spec(*args)
27+
super(*args).tap do |pod_file|
28+
add_test_target(pod_file)
29+
end
30+
end
31+
32+
def build_pod
33+
super
34+
Pod::UI.message "\Testing with xcodebuild.\n".yellow do
35+
run_tests
36+
end
37+
end
38+
39+
private
40+
def create_test_target(project)
41+
test_target = project.new_target(:unit_test_bundle, TEST_TARGET, consumer.platform_name, deployment_target)
42+
group = project.new_group(TEST_TARGET)
43+
test_target.add_file_references(test_files.map { |file| group.new_file(file) })
44+
project.save
45+
create_test_scheme(project, test_target)
46+
project
47+
end
48+
49+
def create_test_scheme(project, test_target)
50+
project.recreate_user_schemes
51+
test_scheme = Xcodeproj::XCScheme.new(test_scheme_path(project))
52+
test_scheme.add_test_target(test_target)
53+
test_scheme.save!
54+
end
55+
56+
def test_scheme_path(project)
57+
Xcodeproj::XCScheme.user_data_dir(project.path) + "#{TEST_TARGET}.xcscheme"
58+
end
59+
60+
def add_test_target(pod_file)
61+
app_target = pod_file.target_definitions[APP_TARGET]
62+
Pod::Podfile::TargetDefinition.new(TEST_TARGET, app_target)
63+
end
64+
65+
def run_tests
66+
command = %W(clean test -workspace #{APP_TARGET}.xcworkspace -scheme #{TEST_TARGET} -configuration Debug)
67+
case consumer.platform_name
68+
when :ios
69+
command += %w(CODE_SIGN_IDENTITY=- -sdk iphonesimulator)
70+
command += Fourflusher::SimControl.new.destination('iPhone 4s', deployment_target)
71+
when :osx
72+
command += %w(LD_RUNPATH_SEARCH_PATHS=@loader_path/../Frameworks)
73+
when :tvos
74+
command += %w(CODE_SIGN_IDENTITY=- -sdk appletvsimulator)
75+
command += Fourflusher::SimControl.new.destination('Apple TV 1080p', deployment_target)
76+
else
77+
return # skip watchos
78+
end
79+
80+
output, status = Dir.chdir(validation_dir) { _xcodebuild(command) }
81+
unless status.success?
82+
message = 'Returned an unsuccessful exit code.'
83+
if config.verbose?
84+
message += "\nXcode output: \n#{output}\n"
85+
else
86+
message += ' You can use `--verbose` for more information.'
87+
end
88+
error('xcodebuild', message)
89+
end
90+
end
91+
end

SQLiteTests/FTS4Tests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class FTS4Tests : XCTestCase {
4545
}
4646

4747
class FTS4IntegrationTests : SQLiteTestCase {
48-
48+
#if !SQLITE_SWIFT_STANDALONE
4949
func test_registerTokenizer_registersTokenizer() {
5050
let emails = VirtualTable("emails")
5151
let subject = Expression<String?>("subject")
@@ -73,5 +73,5 @@ class FTS4IntegrationTests : SQLiteTestCase {
7373
try! db.run(emails.insert(subject <- "Aún más cáfe!"))
7474
XCTAssertEqual(1, db.scalar(emails.filter(emails.match("aun")).count))
7575
}
76-
76+
#endif
7777
}

0 commit comments

Comments
 (0)