Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions test/fixtures/xctest_runner/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,21 @@ swift_test(
tags = FIXTURE_TAGS,
deps = [":MainLibrary"],
)

swift_test(
name = "FailingSwiftTestingTests",
srcs = ["FailingSwiftTestingTests.swift"],
tags = FIXTURE_TAGS,
)

swift_test(
name = "EmptySwiftTestingSuite",
srcs = ["EmptySwiftTestingSuite.swift"],
tags = FIXTURE_TAGS,
)

swift_test(
name = "PassingSwiftTestingTests",
srcs = ["PassingSwiftTestingTests.swift"],
tags = FIXTURE_TAGS,
)
6 changes: 6 additions & 0 deletions test/fixtures/xctest_runner/EmptySwiftTestingSuite.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Testing

@Suite("Empty test suite")
class EmptyTestSuite {

}
6 changes: 6 additions & 0 deletions test/fixtures/xctest_runner/FailingSwiftTestingTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Testing

@Test("A failing test")
func aFalingTest(){
#expect(false, "This assertion will always fail")
}
6 changes: 6 additions & 0 deletions test/fixtures/xctest_runner/PassingSwiftTestingTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Testing

@Test("A passing test")
func aPassingTest(){
#expect(true, "This assertion should pass")
}
4 changes: 2 additions & 2 deletions test/rules/swift_shell_runner.sh.template
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ set -euxo pipefail
executable="%executable%"
expected_return_code="%expected_return_code%"
expected_logs=%expected_logs%
not_expected_logs=%expected_logs%
not_expected_logs=%not_expected_logs%

# execute the target under test while recording its outputs and return code
tmp_dir=$(mktemp -d)
Expand Down Expand Up @@ -59,7 +59,7 @@ done
# verify the absence of unexpected logs
for unexpected in "${not_expected_logs[@]}"
do
if ! grep --quiet --invert-match --regexp "$unexpected" "$testlog"; then
if grep --quiet --regexp "$unexpected" "$testlog"; then
echo "Fail: found unexpected log: $unexpected"
exit 1
fi
Expand Down
39 changes: 38 additions & 1 deletion test/xctest_runner_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

load("//test/rules:swift_shell_test.bzl", "swift_shell_test")

_NO_TESTS_DISCOVERED = "ERROR: No tests were discovered"

def xctest_runner_test_suite(name, tags = []):
"""Test suite for xctest runner.

Expand All @@ -19,6 +21,7 @@ def xctest_runner_test_suite(name, tags = []):
"Test Suite 'PassingUnitTests.xctest' passed",
"Executed 3 tests, with 0 failures",
],
not_expected_logs = [_NO_TESTS_DISCOVERED],
tags = all_tags,
target_under_test = "//test/fixtures/xctest_runner:PassingUnitTests",
target_compatible_with = ["@platforms//os:macos"],
Expand All @@ -32,6 +35,7 @@ def xctest_runner_test_suite(name, tags = []):
"Test Suite 'FailingUnitTests.xctest' failed",
"Executed 1 test, with 1 failure",
],
not_expected_logs = [_NO_TESTS_DISCOVERED],
tags = all_tags,
target_under_test = "//test/fixtures/xctest_runner:FailingUnitTests",
target_compatible_with = ["@platforms//os:macos"],
Expand All @@ -42,13 +46,46 @@ def xctest_runner_test_suite(name, tags = []):
expected_return_code = 1,
expected_logs = [
"Executed 0 tests, with 0 failures",
"ERROR: No tests were discovered",
_NO_TESTS_DISCOVERED,
],
tags = all_tags,
target_under_test = "//test/fixtures/xctest_runner:EmptyUnitTests",
target_compatible_with = ["@platforms//os:macos"],
)

swift_shell_test(
name = "{}_swift_testing_no_tests".format(name),
expected_return_code = 1,
expected_logs = [
"Test run with 0 tests.* passed after",
_NO_TESTS_DISCOVERED,
],
tags = all_tags,
target_under_test = "//test/fixtures/xctest_runner:EmptySwiftTestingSuite",
)

swift_shell_test(
name = "{}_swift_testing_pass".format(name),
expected_return_code = 0,
expected_logs = [
"Test run with 1 test.* passed after",
],
not_expected_logs = [_NO_TESTS_DISCOVERED],
tags = all_tags,
target_under_test = "//test/fixtures/xctest_runner:PassingSwiftTestingTests",
)

swift_shell_test(
name = "{}_swift_testing_fail".format(name),
expected_return_code = 1,
expected_logs = [
"Test run with 1 test.* failed after",
],
not_expected_logs = [_NO_TESTS_DISCOVERED],
tags = all_tags,
target_under_test = "//test/fixtures/xctest_runner:FailingSwiftTestingTests",
)

native.test_suite(
name = name,
tags = all_tags,
Expand Down
Loading