|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Copyright 2018 The Bazel Authors. All rights reserved. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +# Integration tests for iOS test runner. |
| 18 | + |
| 19 | +MIN_OS_IOS="17.0.0" |
| 20 | + |
| 21 | +function set_up() { |
| 22 | + mkdir -p ios |
| 23 | +} |
| 24 | + |
| 25 | +function tear_down() { |
| 26 | + rm -rf ios |
| 27 | +} |
| 28 | + |
| 29 | +function create_sim_runners() { |
| 30 | + cat > ios/BUILD <<EOF |
| 31 | +load( |
| 32 | + "@build_bazel_rules_apple//apple:ios.bzl", |
| 33 | + "ios_application", |
| 34 | + "ios_unit_test" |
| 35 | +) |
| 36 | +load("@build_bazel_rules_swift//swift:swift.bzl", |
| 37 | + "swift_library" |
| 38 | +) |
| 39 | +load( |
| 40 | + "@build_bazel_rules_apple//apple/testing/default_runner:ios_xctestrun_runner.bzl", |
| 41 | + "ios_xctestrun_runner" |
| 42 | +) |
| 43 | +
|
| 44 | +ios_xctestrun_runner( |
| 45 | + name = "ios_x86_64_sim_runner_17", |
| 46 | + device_type = "iPhone 11", |
| 47 | + os_version = "17.2", |
| 48 | +) |
| 49 | +EOF |
| 50 | +} |
| 51 | + |
| 52 | +function create_swift_testing_tests() { |
| 53 | + cat > ios/passing_swift_testing_test.swift <<EOF |
| 54 | +import Testing |
| 55 | +import XCTest |
| 56 | +
|
| 57 | +@Suite("Simple passing swift test suite") |
| 58 | +class SimpleSwiftTestingTest { |
| 59 | + @Test |
| 60 | + func testCaseOne() { |
| 61 | + let one = 1 |
| 62 | + #expect(one == 1, "this test passes") |
| 63 | + } |
| 64 | +
|
| 65 | + @Test |
| 66 | + func testCaseTwo() { |
| 67 | + let two = 2 |
| 68 | + #expect(two == 2, "this test passes") |
| 69 | + } |
| 70 | +} |
| 71 | +EOF |
| 72 | + |
| 73 | +cat > ios/failing_swift_testing_test.swift <<EOF |
| 74 | +import Testing |
| 75 | +import XCTest |
| 76 | +
|
| 77 | +@Suite("Simple failing swift test suite") |
| 78 | +class SimpleSwiftTestingTest { |
| 79 | + @Test |
| 80 | + func testCaseOne() { |
| 81 | +
|
| 82 | + let one = 1 |
| 83 | + #expect(one == 2, "this test fails") |
| 84 | + } |
| 85 | +} |
| 86 | +EOF |
| 87 | + |
| 88 | + |
| 89 | + cat > ios/empty_swift_testing_test.swift <<EOF |
| 90 | +import Testing |
| 91 | +import XCTest |
| 92 | +
|
| 93 | +@Suite("Simple empty swift test suite") |
| 94 | +class SimpleSwiftTestingTest { |
| 95 | +
|
| 96 | +} |
| 97 | +EOF |
| 98 | + |
| 99 | + cat >> ios/BUILD <<EOF |
| 100 | +swift_library( |
| 101 | + name = "passing_swift_testing_test_lib", |
| 102 | + testonly = True, |
| 103 | + srcs = ["passing_swift_testing_test.swift"], |
| 104 | +) |
| 105 | +
|
| 106 | +swift_library( |
| 107 | + name = "failing_swift_testing_test_lib", |
| 108 | + testonly = True, |
| 109 | + srcs = ["failing_swift_testing_test.swift"], |
| 110 | +) |
| 111 | +
|
| 112 | +swift_library( |
| 113 | + name = "empty_swift_testing_test_lib", |
| 114 | + testonly = True, |
| 115 | + srcs = ["empty_swift_testing_test.swift"], |
| 116 | +) |
| 117 | +
|
| 118 | +ios_unit_test( |
| 119 | + name = "PassingSwiftTestingTest", |
| 120 | + deps = [":passing_swift_testing_test_lib"], |
| 121 | + minimum_os_version = "${MIN_OS_IOS}", |
| 122 | + runner = ":ios_x86_64_sim_runner_17", |
| 123 | +) |
| 124 | +
|
| 125 | +ios_unit_test( |
| 126 | + name = "FailingSwiftTestingTest", |
| 127 | + deps = [":failing_swift_testing_test_lib"], |
| 128 | + minimum_os_version = "${MIN_OS_IOS}", |
| 129 | + runner = ":ios_x86_64_sim_runner_17", |
| 130 | +) |
| 131 | +
|
| 132 | +ios_unit_test( |
| 133 | + name = "EmptySwiftTestingTest", |
| 134 | + deps = [":empty_swift_testing_test_lib"], |
| 135 | + minimum_os_version = "${MIN_OS_IOS}", |
| 136 | + runner = ":ios_x86_64_sim_runner_17", |
| 137 | +) |
| 138 | +EOF |
| 139 | +} |
| 140 | + |
| 141 | +function do_ios_test() { |
| 142 | + do_test ios "--test_output=all" "--spawn_strategy=local" "$@" |
| 143 | +} |
| 144 | + |
| 145 | +function test_ios_swift_testing_pass() { |
| 146 | + create_sim_runners |
| 147 | + create_swift_testing_tests |
| 148 | + do_ios_test //ios:PassingSwiftTestingTest || fail "should pass" |
| 149 | + expect_log "Suite \"Simple passing swift test suite\" passed" |
| 150 | + expect_log "Test run with 2 tests passed after" |
| 151 | +} |
| 152 | + |
| 153 | +function test_ios_swift_testing_fail() { |
| 154 | + create_sim_runners |
| 155 | + create_swift_testing_tests |
| 156 | + (! do_ios_test //ios:FailingSwiftTestingTest) || fail "should not pass" |
| 157 | + expect_log "Suite \"Simple failing swift test suite\" failed after" |
| 158 | + expect_log "Test run with 1 test failed after" |
| 159 | +} |
| 160 | + |
| 161 | +function test_ios_swift_testing_empty() { |
| 162 | + create_sim_runners |
| 163 | + create_swift_testing_tests |
| 164 | + (! do_ios_test //ios:EmptySwiftTestingTest) || fail "should not pass" |
| 165 | + expect_log "Suite \"Simple empty swift test suite\" passed" |
| 166 | + expect_log "Test run with 0 tests passed after" |
| 167 | + expect_log "error: no tests were executed, is the test bundle empty?" |
| 168 | +} |
| 169 | + |
| 170 | +run_suite "ios_unit_test with iOS 17.x test runner bundling tests" |
0 commit comments