#!/bin/bash # # Copyright 2016 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # Tests the examples provided in Bazel # # Load test environment source $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/test-setup.sh \ || { echo "test-setup.sh not found!" >&2; exit 1; } if [ "${PLATFORM}" != "darwin" ]; then echo "This test suite requires running on OS X" >&2 exit 0 fi function set_up() { copy_examples setup_objc_test_support # Allow access to //external:xcrunwrapper. rm WORKSPACE ln -sv ${workspace_file} WORKSPACE } function make_app() { rm -rf ios mkdir -p ios touch ios/dummy.swift cat >ios/app.swift < Bool { NSLog("Hello, world") return true } } EOF cat >ios/App-Info.plist < CFBundleExecutable app CFBundleName app CFBundleDisplayName app CFBundlePackageType APPL CFBundleIdentifier com.google.app CFBundleSignature ???? CFBundleVersion 1.0 LSRequiresIPhoneOS EOF cat >ios/BUILD <$TEST_log 2>&1 || fail "should pass" ls bazel-bin/ios/app.ipa || fail "should generate app.ipa" } function test_objc_depends_on_swift() { rm -rf ios mkdir -p ios touch ios/dummy.swift cat >ios/main.swift < Int { return 42; } } EOF cat >ios/app.m < #import "ios/SwiftMain-Swift.h" int main(int argc, char *argv[]) { @autoreleasepool { NSLog(@"%d", [[[Foo alloc] init] bar]); return UIApplicationMain(argc, argv, nil, nil); } } EOF cat >ios/BUILD <$TEST_log 2>&1 || fail "should build" } function test_swift_imports_objc() { rm -rf ios mkdir -p ios cat >ios/main.swift < String { return ObjcClass().foo() } } EOF cat >ios/ObjcClass.h < @interface ObjcClass : NSObject - (NSString *)foo; @end EOF cat >ios/ObjcClass.m <ios/BUILD <$TEST_log 2>&1 || fail "should build" } function test_swift_import_objc_framework() { rm -rf ios mkdir -p ios # Copy the prebuilt framework into app's directory. cp -RL "${BAZEL_RUNFILES}/tools/build_defs/apple/test/testdata/BlazeFramework.framework" ios touch ios/dummy.swift cat >ios/main.swift < Bool { NSLog("\(Multiplier().foo())") return true } } EOF cat >ios/BUILD <$TEST_log 2>&1 || fail "should build" } function test_swift_imports_swift() { rm -rf ios mkdir -p ios cat >ios/main.swift < String { return Utility().foo() } } EOF cat >ios/Utility.swift < String { return "foo" } } EOF cat >ios/BUILD <$TEST_log 2>&1 || fail "should build" } run_suite "apple_tests"