Skip to content

Commit 28f7305

Browse files
committed
[tests] Use XCTMain() for Linux tests
`XCTMain()` is the canonical entry point for XCTest on Linux. The continued development of swift-corelibs-xctest would be made simpler if each consumer used this entry point to run their unit tests. - Split XCTestCaseProvider out into its own package, which the tests depend upon. Each test makes explicit reference to XCTestCaseProvider, which means it must be defined on both (1) Linux and (2) OS X, and it must be defined on OS X whether running the tests via (2a) `Utilities/bootstrap` or via (2b) the Xcode project. Test dependencies defined in `Utilities/bootstrap` take care of 1, 2, and 2a. - Add an XCTestCaseProvider target to the Xcode project, which takes care of item 2b from the bullet point above. - Also define XCTMain() on OS X in XCTestCaseProvider. This is because `Utilities/bootstrap` compiles test packages' main.swift files, regardless of whether they are ever executed. These files refer to `XCTMain()` (so we need to define it), but it is never run (so its implementation raises a fatal error).
1 parent c42b02d commit 28f7305

24 files changed

+294
-81
lines changed

Support/swiftpm.xcodeproj/project.pbxproj

Lines changed: 170 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919
637E98DA1BD95D0A0044B53E /* Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 637E98D91BD95D0A0044B53E /* Utilities.swift */; };
2020
63ACA7EC1BED42160095510D /* PackageDescriptionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63ACA7EB1BED42160095510D /* PackageDescriptionTests.swift */; };
2121
63D2BC181BFD6287006E395C /* PackageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63D2BC171BFD6287006E395C /* PackageTests.swift */; };
22-
63DC25221BF413BA00EDCFBF /* XCTestCaseProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63DC25211BF413BA00EDCFBF /* XCTestCaseProvider.swift */; };
23-
63DC25371BF413BF00EDCFBF /* XCTestCaseProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63DC25211BF413BA00EDCFBF /* XCTestCaseProvider.swift */; };
24-
63DC25381BF413C200EDCFBF /* XCTestCaseProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63DC25211BF413BA00EDCFBF /* XCTestCaseProvider.swift */; };
2522
B464B5F11BE41DE400086CE0 /* FunctionalBuildTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B464B5F01BE41DE400086CE0 /* FunctionalBuildTests.swift */; };
23+
DA3C2B1C1C1B4D7600893759 /* XCTestCaseProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA3C2AE11C1B48C700893759 /* XCTestCaseProvider.swift */; };
2624
E136D9421BD5F3DD000DFCE6 /* TOMLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E136D9411BD5F35D000DFCE6 /* TOMLTests.swift */; };
2725
E1E286BA1BD72D700015F0C5 /* ManifestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1E286B91BD72D700015F0C5 /* ManifestTests.swift */; };
2826
E1E286D61BD83BE40015F0C5 /* ResourcesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1E286D51BD83BE40015F0C5 /* ResourcesTests.swift */; };
@@ -155,6 +153,27 @@
155153
remoteGlobalIDString = E1D191BE1B47232B000C4E95;
156154
remoteInfo = "llbuild-framework";
157155
};
156+
DA3C2B1F1C1B4E2000893759 /* PBXContainerItemProxy */ = {
157+
isa = PBXContainerItemProxy;
158+
containerPortal = 63344F981BB0806700460D40 /* Project object */;
159+
proxyType = 1;
160+
remoteGlobalIDString = DA3C2B131C1B4D4A00893759;
161+
remoteInfo = XCTestCaseProvider;
162+
};
163+
DA3C2B211C1B4E2900893759 /* PBXContainerItemProxy */ = {
164+
isa = PBXContainerItemProxy;
165+
containerPortal = 63344F981BB0806700460D40 /* Project object */;
166+
proxyType = 1;
167+
remoteGlobalIDString = DA3C2B131C1B4D4A00893759;
168+
remoteInfo = XCTestCaseProvider;
169+
};
170+
DA3C2B231C1B4E2D00893759 /* PBXContainerItemProxy */ = {
171+
isa = PBXContainerItemProxy;
172+
containerPortal = 63344F981BB0806700460D40 /* Project object */;
173+
proxyType = 1;
174+
remoteGlobalIDString = DA3C2B131C1B4D4A00893759;
175+
remoteInfo = XCTestCaseProvider;
176+
};
158177
E1066BEF1BC5A3DA00B892CE /* PBXContainerItemProxy */ = {
159178
isa = PBXContainerItemProxy;
160179
containerPortal = 63344F981BB0806700460D40 /* Project object */;
@@ -194,8 +213,9 @@
194213
637E98D91BD95D0A0044B53E /* Utilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Utilities.swift; path = ../Tests/dep/Utilities.swift; sourceTree = "<group>"; };
195214
63ACA7EB1BED42160095510D /* PackageDescriptionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PackageDescriptionTests.swift; path = ../Tests/PackageDescription/PackageDescriptionTests.swift; sourceTree = "<group>"; };
196215
63D2BC171BFD6287006E395C /* PackageTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PackageTests.swift; path = ../Tests/dep/PackageTests.swift; sourceTree = "<group>"; };
197-
63DC25211BF413BA00EDCFBF /* XCTestCaseProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = XCTestCaseProvider.swift; path = ../Tests/XCTestCaseProvider.swift; sourceTree = "<group>"; };
198216
B464B5F01BE41DE400086CE0 /* FunctionalBuildTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FunctionalBuildTests.swift; path = ../Tests/dep/FunctionalBuildTests.swift; sourceTree = "<group>"; };
217+
DA3C2AE11C1B48C700893759 /* XCTestCaseProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XCTestCaseProvider.swift; sourceTree = "<group>"; };
218+
DA3C2B141C1B4D4A00893759 /* XCTestCaseProvider.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = XCTestCaseProvider.framework; sourceTree = BUILT_PRODUCTS_DIR; };
199219
E1066B6E1BC5931C00B892CE /* llbuild.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = llbuild.xcodeproj; path = ../../llbuild/llbuild.xcodeproj; sourceTree = "<group>"; };
200220
E136D9411BD5F35D000DFCE6 /* TOMLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TOMLTests.swift; path = ../Tests/sys/TOMLTests.swift; sourceTree = "<group>"; };
201221
E1E286B91BD72D700015F0C5 /* ManifestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ManifestTests.swift; path = ../Tests/dep/ManifestTests.swift; sourceTree = "<group>"; };
@@ -218,6 +238,13 @@
218238
);
219239
runOnlyForDeploymentPostprocessing = 0;
220240
};
241+
DA3C2B101C1B4D4A00893759 /* Frameworks */ = {
242+
isa = PBXFrameworksBuildPhase;
243+
buildActionMask = 2147483647;
244+
files = (
245+
);
246+
runOnlyForDeploymentPostprocessing = 0;
247+
};
221248
E1FD7B7D1BD6D6A0006D9417 /* Frameworks */ = {
222249
isa = PBXFrameworksBuildPhase;
223250
buildActionMask = 2147483647;
@@ -244,17 +271,18 @@
244271
63353A3E1BB4C40E00D6C4B0 /* sys-tests.xctest */,
245272
63353A4B1BB4C46200D6C4B0 /* dep-tests.xctest */,
246273
E1FD7B821BD6D6A0006D9417 /* PackageDescription-tests.xctest */,
274+
DA3C2B141C1B4D4A00893759 /* XCTestCaseProvider.framework */,
247275
);
248276
name = Products;
249277
sourceTree = "<group>";
250278
};
251279
63353A571BB4C4A900D6C4B0 /* Tests */ = {
252280
isa = PBXGroup;
253281
children = (
254-
63DC25211BF413BA00EDCFBF /* XCTestCaseProvider.swift */,
255282
63CF91C31BE9419500265702 /* PackageDescription */,
256283
63CF91C21BE9419100265702 /* sys */,
257284
63CF91C11BE9418D00265702 /* dep */,
285+
DA3C2AE01C1B48C700893759 /* XCTestCaseProvider */,
258286
);
259287
name = Tests;
260288
sourceTree = "<group>";
@@ -320,8 +348,27 @@
320348
name = PackageDescription;
321349
sourceTree = "<group>";
322350
};
351+
DA3C2AE01C1B48C700893759 /* XCTestCaseProvider */ = {
352+
isa = PBXGroup;
353+
children = (
354+
DA3C2AE11C1B48C700893759 /* XCTestCaseProvider.swift */,
355+
);
356+
name = XCTestCaseProvider;
357+
path = ../Tests/XCTestCaseProvider;
358+
sourceTree = "<group>";
359+
};
323360
/* End PBXGroup section */
324361

362+
/* Begin PBXHeadersBuildPhase section */
363+
DA3C2B111C1B4D4A00893759 /* Headers */ = {
364+
isa = PBXHeadersBuildPhase;
365+
buildActionMask = 2147483647;
366+
files = (
367+
);
368+
runOnlyForDeploymentPostprocessing = 0;
369+
};
370+
/* End PBXHeadersBuildPhase section */
371+
325372
/* Begin PBXLegacyTarget section */
326373
63344F9C1BB0806700460D40 /* swiftpm */ = {
327374
isa = PBXLegacyTarget;
@@ -352,6 +399,7 @@
352399
buildRules = (
353400
);
354401
dependencies = (
402+
DA3C2B221C1B4E2900893759 /* PBXTargetDependency */,
355403
E1066BF01BC5A3DA00B892CE /* PBXTargetDependency */,
356404
);
357405
name = "sys-tests";
@@ -366,18 +414,37 @@
366414
63353A471BB4C46200D6C4B0 /* Sources */,
367415
63353A481BB4C46200D6C4B0 /* Frameworks */,
368416
63353A491BB4C46200D6C4B0 /* Resources */,
369-
63D5E8AC1C120CDD000A7AAE /* ShellScript */,
417+
63D5E8AC1C120CDD000A7AAE /* Run Script */,
370418
);
371419
buildRules = (
372420
);
373421
dependencies = (
422+
DA3C2B241C1B4E2D00893759 /* PBXTargetDependency */,
374423
E1066C061BC5A3DC00B892CE /* PBXTargetDependency */,
375424
);
376425
name = "dep-tests";
377426
productName = "dep-tests";
378427
productReference = 63353A4B1BB4C46200D6C4B0 /* dep-tests.xctest */;
379428
productType = "com.apple.product-type.bundle.unit-test";
380429
};
430+
DA3C2B131C1B4D4A00893759 /* XCTestCaseProvider */ = {
431+
isa = PBXNativeTarget;
432+
buildConfigurationList = DA3C2B191C1B4D4A00893759 /* Build configuration list for PBXNativeTarget "XCTestCaseProvider" */;
433+
buildPhases = (
434+
DA3C2B0F1C1B4D4A00893759 /* Sources */,
435+
DA3C2B101C1B4D4A00893759 /* Frameworks */,
436+
DA3C2B111C1B4D4A00893759 /* Headers */,
437+
DA3C2B121C1B4D4A00893759 /* Resources */,
438+
);
439+
buildRules = (
440+
);
441+
dependencies = (
442+
);
443+
name = XCTestCaseProvider;
444+
productName = XCTestCaseProvider;
445+
productReference = DA3C2B141C1B4D4A00893759 /* XCTestCaseProvider.framework */;
446+
productType = "com.apple.product-type.framework";
447+
};
381448
E1FD7B761BD6D6A0006D9417 /* PackageDescription-tests */ = {
382449
isa = PBXNativeTarget;
383450
buildConfigurationList = E1FD7B7F1BD6D6A0006D9417 /* Build configuration list for PBXNativeTarget "PackageDescription-tests" */;
@@ -389,6 +456,7 @@
389456
buildRules = (
390457
);
391458
dependencies = (
459+
DA3C2B201C1B4E2000893759 /* PBXTargetDependency */,
392460
E1FD7B771BD6D6A0006D9417 /* PBXTargetDependency */,
393461
);
394462
name = "PackageDescription-tests";
@@ -415,6 +483,9 @@
415483
63353A4A1BB4C46200D6C4B0 = {
416484
CreatedOnToolsVersion = 7.1;
417485
};
486+
DA3C2B131C1B4D4A00893759 = {
487+
CreatedOnToolsVersion = 7.2;
488+
};
418489
};
419490
};
420491
buildConfigurationList = 63344F9B1BB0806700460D40 /* Build configuration list for PBXProject "swiftpm" */;
@@ -436,6 +507,7 @@
436507
projectRoot = "";
437508
targets = (
438509
63344F9C1BB0806700460D40 /* swiftpm */,
510+
DA3C2B131C1B4D4A00893759 /* XCTestCaseProvider */,
439511
E1FD7B761BD6D6A0006D9417 /* PackageDescription-tests */,
440512
63353A3D1BB4C40E00D6C4B0 /* sys-tests */,
441513
63353A4A1BB4C46200D6C4B0 /* dep-tests */,
@@ -580,6 +652,13 @@
580652
);
581653
runOnlyForDeploymentPostprocessing = 0;
582654
};
655+
DA3C2B121C1B4D4A00893759 /* Resources */ = {
656+
isa = PBXResourcesBuildPhase;
657+
buildActionMask = 2147483647;
658+
files = (
659+
);
660+
runOnlyForDeploymentPostprocessing = 0;
661+
};
583662
E1FD7B7E1BD6D6A0006D9417 /* Resources */ = {
584663
isa = PBXResourcesBuildPhase;
585664
buildActionMask = 2147483647;
@@ -590,13 +669,14 @@
590669
/* End PBXResourcesBuildPhase section */
591670

592671
/* Begin PBXShellScriptBuildPhase section */
593-
63D5E8AC1C120CDD000A7AAE /* ShellScript */ = {
672+
63D5E8AC1C120CDD000A7AAE /* Run Script */ = {
594673
isa = PBXShellScriptBuildPhase;
595674
buildActionMask = 2147483647;
596675
files = (
597676
);
598677
inputPaths = (
599678
);
679+
name = "Run Script";
600680
outputPaths = (
601681
);
602682
runOnlyForDeploymentPostprocessing = 0;
@@ -614,7 +694,6 @@
614694
E136D9421BD5F3DD000DFCE6 /* TOMLTests.swift in Sources */,
615695
63353A611BB4C4CD00D6C4B0 /* ShellTests.swift in Sources */,
616696
E1E286D61BD83BE40015F0C5 /* ResourcesTests.swift in Sources */,
617-
63DC25371BF413BF00EDCFBF /* XCTestCaseProvider.swift in Sources */,
618697
4BAA4BAC1C16CABE0074DA44 /* FileTests.swift in Sources */,
619698
636EF11A1C0D0F1E00626610 /* MiscTests.swift in Sources */,
620699
63353A621BB4C4CD00D6C4B0 /* StringTests.swift in Sources */,
@@ -632,17 +711,23 @@
632711
63353A5B1BB4C4BC00D6C4B0 /* VersionTests.swift in Sources */,
633712
637E98DA1BD95D0A0044B53E /* Utilities.swift in Sources */,
634713
63D2BC181BFD6287006E395C /* PackageTests.swift in Sources */,
635-
63DC25221BF413BA00EDCFBF /* XCTestCaseProvider.swift in Sources */,
636714
635C147D1BCDA0A900D4C4A9 /* TargetTests.swift in Sources */,
637715
);
638716
runOnlyForDeploymentPostprocessing = 0;
639717
};
718+
DA3C2B0F1C1B4D4A00893759 /* Sources */ = {
719+
isa = PBXSourcesBuildPhase;
720+
buildActionMask = 2147483647;
721+
files = (
722+
DA3C2B1C1C1B4D7600893759 /* XCTestCaseProvider.swift in Sources */,
723+
);
724+
runOnlyForDeploymentPostprocessing = 0;
725+
};
640726
E1FD7B791BD6D6A0006D9417 /* Sources */ = {
641727
isa = PBXSourcesBuildPhase;
642728
buildActionMask = 2147483647;
643729
files = (
644730
63ACA7EC1BED42160095510D /* PackageDescriptionTests.swift in Sources */,
645-
63DC25381BF413C200EDCFBF /* XCTestCaseProvider.swift in Sources */,
646731
);
647732
runOnlyForDeploymentPostprocessing = 0;
648733
};
@@ -654,6 +739,21 @@
654739
name = "swift-build-tool";
655740
targetProxy = 637021321BED46CE0005C5D5 /* PBXContainerItemProxy */;
656741
};
742+
DA3C2B201C1B4E2000893759 /* PBXTargetDependency */ = {
743+
isa = PBXTargetDependency;
744+
target = DA3C2B131C1B4D4A00893759 /* XCTestCaseProvider */;
745+
targetProxy = DA3C2B1F1C1B4E2000893759 /* PBXContainerItemProxy */;
746+
};
747+
DA3C2B221C1B4E2900893759 /* PBXTargetDependency */ = {
748+
isa = PBXTargetDependency;
749+
target = DA3C2B131C1B4D4A00893759 /* XCTestCaseProvider */;
750+
targetProxy = DA3C2B211C1B4E2900893759 /* PBXContainerItemProxy */;
751+
};
752+
DA3C2B241C1B4E2D00893759 /* PBXTargetDependency */ = {
753+
isa = PBXTargetDependency;
754+
target = DA3C2B131C1B4D4A00893759 /* XCTestCaseProvider */;
755+
targetProxy = DA3C2B231C1B4E2D00893759 /* PBXContainerItemProxy */;
756+
};
657757
E1066BF01BC5A3DA00B892CE /* PBXTargetDependency */ = {
658758
isa = PBXTargetDependency;
659759
target = 63344F9C1BB0806700460D40 /* swiftpm */;
@@ -857,6 +957,57 @@
857957
};
858958
name = Release;
859959
};
960+
DA3C2B1A1C1B4D4A00893759 /* Debug */ = {
961+
isa = XCBuildConfiguration;
962+
buildSettings = {
963+
CODE_SIGN_IDENTITY = "-";
964+
COMBINE_HIDPI_IMAGES = YES;
965+
CURRENT_PROJECT_VERSION = 1;
966+
DEFINES_MODULE = YES;
967+
DYLIB_COMPATIBILITY_VERSION = 1;
968+
DYLIB_CURRENT_VERSION = 1;
969+
DYLIB_INSTALL_NAME_BASE = "@rpath";
970+
FRAMEWORK_VERSION = A;
971+
INFOPLIST_FILE = "$(SRCROOT)/../Tests/XCTestCaseProvider/Info.plist";
972+
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
973+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
974+
MACOSX_DEPLOYMENT_TARGET = 10.11;
975+
PRODUCT_BUNDLE_IDENTIFIER = com.apple.XCTestCaseProvider;
976+
PRODUCT_NAME = "$(TARGET_NAME)";
977+
SDKROOT = macosx;
978+
SKIP_INSTALL = YES;
979+
SWIFT_INCLUDE_PATHS = "";
980+
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
981+
VERSIONING_SYSTEM = "apple-generic";
982+
VERSION_INFO_PREFIX = "";
983+
};
984+
name = Debug;
985+
};
986+
DA3C2B1B1C1B4D4A00893759 /* Release */ = {
987+
isa = XCBuildConfiguration;
988+
buildSettings = {
989+
CODE_SIGN_IDENTITY = "-";
990+
COMBINE_HIDPI_IMAGES = YES;
991+
CURRENT_PROJECT_VERSION = 1;
992+
DEFINES_MODULE = YES;
993+
DYLIB_COMPATIBILITY_VERSION = 1;
994+
DYLIB_CURRENT_VERSION = 1;
995+
DYLIB_INSTALL_NAME_BASE = "@rpath";
996+
FRAMEWORK_VERSION = A;
997+
INFOPLIST_FILE = "$(SRCROOT)/../Tests/XCTestCaseProvider/Info.plist";
998+
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
999+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
1000+
MACOSX_DEPLOYMENT_TARGET = 10.11;
1001+
PRODUCT_BUNDLE_IDENTIFIER = com.apple.XCTestCaseProvider;
1002+
PRODUCT_NAME = "$(TARGET_NAME)";
1003+
SDKROOT = macosx;
1004+
SKIP_INSTALL = YES;
1005+
SWIFT_INCLUDE_PATHS = "";
1006+
VERSIONING_SYSTEM = "apple-generic";
1007+
VERSION_INFO_PREFIX = "";
1008+
};
1009+
name = Release;
1010+
};
8601011
E1FD7B801BD6D6A0006D9417 /* Debug */ = {
8611012
isa = XCBuildConfiguration;
8621013
buildSettings = {
@@ -937,6 +1088,15 @@
9371088
defaultConfigurationIsVisible = 0;
9381089
defaultConfigurationName = Debug;
9391090
};
1091+
DA3C2B191C1B4D4A00893759 /* Build configuration list for PBXNativeTarget "XCTestCaseProvider" */ = {
1092+
isa = XCConfigurationList;
1093+
buildConfigurations = (
1094+
DA3C2B1A1C1B4D4A00893759 /* Debug */,
1095+
DA3C2B1B1C1B4D4A00893759 /* Release */,
1096+
);
1097+
defaultConfigurationIsVisible = 0;
1098+
defaultConfigurationName = Debug;
1099+
};
9401100
E1FD7B7F1BD6D6A0006D9417 /* Build configuration list for PBXNativeTarget "PackageDescription-tests" */ = {
9411101
isa = XCConfigurationList;
9421102
buildConfigurations = (

Tests/PackageDescription/PackageDescriptionTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
import XCTest
12+
import XCTestCaseProvider
1213
import PackageDescription
1314
import sys
1415
@testable import dep

Tests/PackageDescription/main.swift

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import XCTest
2+
import XCTestCaseProvider
23

3-
#if !os(Linux)
4-
public protocol XCTestCaseProvider {
5-
var allTests : [(String, () -> ())] { get }
6-
}
7-
#endif
8-
9-
// PackageDescriptionTests.swift
10-
PackageTests().invokeTest()
4+
XCTMain([
5+
// PackageDescriptionTests.swift
6+
PackageTests(),
7+
])

Tests/XCTestCaseProvider.swift

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)