From aacdde0778264c652048dffbf01598dfbcac8e82 Mon Sep 17 00:00:00 2001 From: Jan Berkel Date: Fri, 13 May 2016 19:30:15 +0100 Subject: [PATCH] [CocoaPods] integration tests --- .travis.yml | 1 + CocoaPodsTests/.gitignore | 1 + CocoaPodsTests/Gemfile | 4 ++ CocoaPodsTests/Gemfile.lock | 65 +++++++++++++++++ CocoaPodsTests/Makefile | 10 +++ CocoaPodsTests/integration_test.rb | 33 +++++++++ CocoaPodsTests/test_running_validator.rb | 91 ++++++++++++++++++++++++ SQLiteTests/FTS4Tests.swift | 4 +- 8 files changed, 207 insertions(+), 2 deletions(-) create mode 100644 CocoaPodsTests/.gitignore create mode 100644 CocoaPodsTests/Gemfile create mode 100644 CocoaPodsTests/Gemfile.lock create mode 100644 CocoaPodsTests/Makefile create mode 100755 CocoaPodsTests/integration_test.rb create mode 100644 CocoaPodsTests/test_running_validator.rb diff --git a/.travis.yml b/.travis.yml index 1964faf9..ad0f18b9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,4 +6,5 @@ before_install: - gem install xcpretty --no-document script: - make test + - cd CocoaPodsTests && make test osx_image: xcode7.3 diff --git a/CocoaPodsTests/.gitignore b/CocoaPodsTests/.gitignore new file mode 100644 index 00000000..4cf24de2 --- /dev/null +++ b/CocoaPodsTests/.gitignore @@ -0,0 +1 @@ +gems/ diff --git a/CocoaPodsTests/Gemfile b/CocoaPodsTests/Gemfile new file mode 100644 index 00000000..0a6af5c8 --- /dev/null +++ b/CocoaPodsTests/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +gem 'cocoapods' +gem 'minitest' diff --git a/CocoaPodsTests/Gemfile.lock b/CocoaPodsTests/Gemfile.lock new file mode 100644 index 00000000..7173e2c4 --- /dev/null +++ b/CocoaPodsTests/Gemfile.lock @@ -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 diff --git a/CocoaPodsTests/Makefile b/CocoaPodsTests/Makefile new file mode 100644 index 00000000..c9a3182e --- /dev/null +++ b/CocoaPodsTests/Makefile @@ -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 diff --git a/CocoaPodsTests/integration_test.rb b/CocoaPodsTests/integration_test.rb new file mode 100755 index 00000000..325b8493 --- /dev/null +++ b/CocoaPodsTests/integration_test.rb @@ -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 diff --git a/CocoaPodsTests/test_running_validator.rb b/CocoaPodsTests/test_running_validator.rb new file mode 100644 index 00000000..10f4db61 --- /dev/null +++ b/CocoaPodsTests/test_running_validator.rb @@ -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 diff --git a/SQLiteTests/FTS4Tests.swift b/SQLiteTests/FTS4Tests.swift index a94d9073..7f889955 100644 --- a/SQLiteTests/FTS4Tests.swift +++ b/SQLiteTests/FTS4Tests.swift @@ -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("subject") @@ -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 }