-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement --test_filter support (#999)
Implement `--test_filter` support, as detailed in #997. This can be engaged via a `swift_test` target like so: ``` bazel test //:Tests --test_filter=TestModuleName.TestClassName/testMethodName ``` **Note:** If `--test_filter` is not passed into the test invocation, we fallback to the original behavior (pass `All` into the xctest invocation.
- Loading branch information
Showing
8 changed files
with
113 additions
and
2 deletions.
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
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,51 @@ | ||
load( | ||
"//swift:swift.bzl", | ||
"swift_library", | ||
"swift_test", | ||
) | ||
|
||
swift_library( | ||
name = "test_filter_lib", | ||
testonly = True, | ||
srcs = [ | ||
"FailTests.swift", | ||
"PassFailTests.swift", | ||
"PassTests.swift", | ||
"TestHelper.swift", | ||
], | ||
module_name = "test_filter", | ||
target_compatible_with = ["@platforms//os:macos"], | ||
) | ||
|
||
# Verify that tests fail as expected without test filtering. | ||
swift_test( | ||
name = "test_filter__baseline", | ||
env = { | ||
"EXPECT_FAILURE": "TRUE", | ||
}, | ||
module_name = "test_filter", | ||
target_compatible_with = ["@platforms//os:macos"], | ||
deps = [":test_filter_lib"], | ||
) | ||
|
||
# Verify that test scope is filtered by TARGET.TEST_CLASS as expected. | ||
swift_test( | ||
name = "test_filter__feature__target_class", | ||
env = { | ||
"TESTBRIDGE_TEST_ONLY": "test_filter.PassTests", | ||
}, | ||
module_name = "test_filter", | ||
target_compatible_with = ["@platforms//os:macos"], | ||
deps = [":test_filter_lib"], | ||
) | ||
|
||
# Verify that test scope is filtered by TARGET.TEST_CLASS.TEST_METHOD as expected. | ||
swift_test( | ||
name = "test_filter__feature__target_class_method", | ||
env = { | ||
"TESTBRIDGE_TEST_ONLY": "test_filter.PassFailTests/test_pass", | ||
}, | ||
module_name = "test_filter", | ||
target_compatible_with = ["@platforms//os:macos"], | ||
deps = [":test_filter_lib"], | ||
) |
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,8 @@ | ||
import XCTest | ||
|
||
class FailTests: XCTestCase { | ||
|
||
func test_fail() { | ||
TestHelper.ExpectFailureIfNeeded() | ||
} | ||
} |
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,12 @@ | ||
import XCTest | ||
|
||
class PassFailTests: XCTestCase { | ||
|
||
func test_pass() { | ||
TestHelper.Pass() | ||
} | ||
|
||
func test_fail() { | ||
TestHelper.ExpectFailureIfNeeded() | ||
} | ||
} |
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,8 @@ | ||
import XCTest | ||
|
||
class PassTests: XCTestCase { | ||
|
||
func test_pass() { | ||
TestHelper.Pass() | ||
} | ||
} |
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,20 @@ | ||
import XCTest | ||
|
||
enum TestHelper { | ||
|
||
static func ExpectFailureIfNeeded() { | ||
let options: XCTExpectedFailure.Options = .init() | ||
options.isEnabled = ProcessInfo.processInfo.environment["EXPECT_FAILURE"] == "TRUE" | ||
XCTExpectFailure("Expected failure", options: options) { | ||
Fail() | ||
} | ||
} | ||
|
||
static func Pass() { | ||
XCTAssertTrue(true) | ||
} | ||
|
||
private static func Fail() { | ||
XCTFail("Fail") | ||
} | ||
} |
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