-
Notifications
You must be signed in to change notification settings - Fork 273
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
Add swift-testing support to the xctest runner #2554
Open
ed-irl
wants to merge
2
commits into
bazelbuild:master
Choose a base branch
from
ed-irl:add-swift-testing-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -544,8 +544,15 @@ if [[ $parallel_testing_enabled == true ]]; then | |
else | ||
# Assume the final 'Executed N tests' or 'Executed 1 test' is the | ||
# total execution count for the test bundle. | ||
test_target_execution_count=$(grep -e "Executed [[:digit:]]\{1,\} tests*," "$testlog" | tail -n1) | ||
if echo "$test_target_execution_count" | grep -q -e "Executed 0 tests, with 0 failures"; then | ||
xctest_target_execution_count=$(grep -e "Executed [[:digit:]]\{1,\} tests*," "$testlog" | tail -n1) | ||
swift_testing_target_execution_count=$(grep -e "Test run with [[:digit:]]\{1,\} test" "$testlog" | tail -n1 || true) | ||
if echo "$xctest_target_execution_count" | grep -q -e "Executed 0 tests, with 0 failures" && \ | ||
[ -z "$swift_testing_target_execution_count" ] ; then | ||
no_tests_ran=true | ||
fi | ||
|
||
if echo "$xctest_target_execution_count" | grep -q -e "Executed 0 tests, with 0 failures" && \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can it be the case that only Testing targets ran with zero tests? |
||
echo "$swift_testing_target_execution_count" | grep -q -e "Test run with 0 tests" ; then | ||
no_tests_ran=true | ||
fi | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
#!/bin/bash | ||
|
||
# Copyright 2018 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. | ||
|
||
# Integration tests for iOS test runner. | ||
|
||
MIN_OS_IOS="17.0.0" | ||
|
||
function set_up() { | ||
mkdir -p ios | ||
} | ||
|
||
function tear_down() { | ||
rm -rf ios | ||
} | ||
|
||
function create_sim_runners() { | ||
cat > ios/BUILD <<EOF | ||
load( | ||
"@build_bazel_rules_apple//apple:ios.bzl", | ||
"ios_application", | ||
"ios_unit_test" | ||
) | ||
load("@build_bazel_rules_swift//swift:swift.bzl", | ||
"swift_library" | ||
) | ||
load( | ||
"@build_bazel_rules_apple//apple/testing/default_runner:ios_xctestrun_runner.bzl", | ||
"ios_xctestrun_runner" | ||
) | ||
|
||
ios_xctestrun_runner( | ||
name = "ios_x86_64_sim_runner_17", | ||
device_type = "iPhone 11", | ||
os_version = "17.2", | ||
) | ||
EOF | ||
} | ||
|
||
function create_swift_testing_tests() { | ||
cat > ios/passing_swift_testing_test.swift <<EOF | ||
import Testing | ||
import XCTest | ||
|
||
@Suite("Simple passing swift test suite") | ||
class SimpleSwiftTestingTest { | ||
@Test | ||
func testCaseOne() { | ||
let one = 1 | ||
#expect(one == 1, "this test passes") | ||
} | ||
|
||
@Test | ||
func testCaseTwo() { | ||
let two = 2 | ||
#expect(two == 2, "this test passes") | ||
} | ||
} | ||
EOF | ||
|
||
cat > ios/failing_swift_testing_test.swift <<EOF | ||
import Testing | ||
import XCTest | ||
|
||
@Suite("Simple failing swift test suite") | ||
class SimpleSwiftTestingTest { | ||
@Test | ||
func testCaseOne() { | ||
|
||
let one = 1 | ||
#expect(one == 2, "this test fails") | ||
} | ||
} | ||
EOF | ||
|
||
|
||
cat > ios/empty_swift_testing_test.swift <<EOF | ||
import Testing | ||
import XCTest | ||
|
||
@Suite("Simple empty swift test suite") | ||
class SimpleSwiftTestingTest { | ||
|
||
} | ||
EOF | ||
|
||
cat >> ios/BUILD <<EOF | ||
swift_library( | ||
name = "passing_swift_testing_test_lib", | ||
testonly = True, | ||
srcs = ["passing_swift_testing_test.swift"], | ||
) | ||
|
||
swift_library( | ||
name = "failing_swift_testing_test_lib", | ||
testonly = True, | ||
srcs = ["failing_swift_testing_test.swift"], | ||
) | ||
|
||
swift_library( | ||
name = "empty_swift_testing_test_lib", | ||
testonly = True, | ||
srcs = ["empty_swift_testing_test.swift"], | ||
) | ||
|
||
ios_unit_test( | ||
name = "PassingSwiftTestingTest", | ||
deps = [":passing_swift_testing_test_lib"], | ||
minimum_os_version = "${MIN_OS_IOS}", | ||
runner = ":ios_x86_64_sim_runner_17", | ||
) | ||
|
||
ios_unit_test( | ||
name = "FailingSwiftTestingTest", | ||
deps = [":failing_swift_testing_test_lib"], | ||
minimum_os_version = "${MIN_OS_IOS}", | ||
runner = ":ios_x86_64_sim_runner_17", | ||
) | ||
|
||
ios_unit_test( | ||
name = "EmptySwiftTestingTest", | ||
deps = [":empty_swift_testing_test_lib"], | ||
minimum_os_version = "${MIN_OS_IOS}", | ||
runner = ":ios_x86_64_sim_runner_17", | ||
) | ||
EOF | ||
} | ||
|
||
function do_ios_test() { | ||
do_test ios "--test_output=all" "--spawn_strategy=local" "$@" | ||
} | ||
|
||
function test_ios_swift_testing_pass() { | ||
create_sim_runners | ||
create_swift_testing_tests | ||
do_ios_test //ios:PassingSwiftTestingTest || fail "should pass" | ||
expect_log "Suite \"Simple passing swift test suite\" passed" | ||
expect_log "Test run with 2 tests passed after" | ||
} | ||
|
||
function test_ios_swift_testing_fail() { | ||
create_sim_runners | ||
create_swift_testing_tests | ||
(! do_ios_test //ios:FailingSwiftTestingTest) || fail "should not pass" | ||
expect_log "Suite \"Simple failing swift test suite\" failed after" | ||
expect_log "Test run with 1 test failed after" | ||
} | ||
|
||
function test_ios_swift_testing_empty() { | ||
create_sim_runners | ||
create_swift_testing_tests | ||
(! do_ios_test //ios:EmptySwiftTestingTest) || fail "should not pass" | ||
expect_log "Suite \"Simple empty swift test suite\" passed" | ||
expect_log "Test run with 0 tests passed after" | ||
expect_log "error: no tests were executed, is the test bundle empty?" | ||
} | ||
|
||
run_suite "ios_unit_test with iOS 17.x test runner bundling tests" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.