Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190import Foundationimport ParcelTestLaneSupportimport ParcelTestSupportimport Testing
struct TestLaneTests { @Test(arguments: ["PARCEL_NATIVE_HOST", "PARCEL_E2E", "PARCEL_BENCH", "PARCEL_BENCH_SMOKE"]) func explicitOptInIsRequired(key: String) { #expect(!NativeHostPolicy.isOptedIn(environment: [:])) #expect(!NativeHostPolicy.isOptedIn(environment: [key: "0"])) #expect(!NativeHostPolicy.isOptedIn(environment: [key: "true"])) #expect(NativeHostPolicy.isOptedIn(environment: [key: "1"])) #expect(!NativeHostPolicy.isOptedIn(environment: [key: "1", "PARCEL_E2E_PREFLIGHT_ONLY": "1"])) #expect(!NativeHostPolicy.isOptedIn(environment: ["AX_TRUSTED": "1"])) }
@Test(arguments: ["native-host 42", "native-host 42\n"]) func lockRequiresAnAncestor(owner: String) { #expect(NativeHostPolicy.ownsLock(owner: owner, ancestors: [100, 42, 2])) #expect(!NativeHostPolicy.ownsLock(owner: owner, ancestors: [100, 2])) #expect(!NativeHostPolicy.ownsLock(owner: owner, ancestors: [])) }
@Test(arguments: ["", "42", "host nope", "host 0", "host -1", "host 1", "host 42 extra", "host 42\nother 99"]) func malformedLockCannotEnableNativeTests(owner: String) { #expect(!NativeHostPolicy.ownsLock(owner: owner, ancestors: [42])) }
private let discovery = """ SafeTests.Geometry/fits() SafeTests.Geometry/count(_:) SafeTests.Parser/reads() ParcelTestSupport.AppKitTestSuite/Windows/orders() """
@Test func manifestPositivelySelectsOnlyRequiredSuites() throws { let selection = try TestLaneSelection(manifest: "SafeTests.Geometry\nSafeTests.Parser", discovered: discovery) #expect(selection.identifiers.count == 3) #expect(selection.suites == ["SafeTests.Geometry", "SafeTests.Parser"]) let expression = try NSRegularExpression(pattern: selection.filter) for id in discovery.split(separator: "\n").map(String.init) { let matched = expression.firstMatch(in: id, range: NSRange(id.startIndex..., in: id)) != nil #expect(matched == selection.identifiers.contains(id)) } }
@Test(arguments: [ "", "# no suites", "SafeTests.Missing", "SafeTests.Geometry\nSafeTests.Missing", "SafeTests.Geometry\nSafeTests.Geometry", ]) func emptyDuplicateOrMissingSuitesFail(manifest: String) { #expect(throws: TestLaneSelection.SelectionFailure.self) { try TestLaneSelection(manifest: manifest, discovered: discovery) } }
@Test func emptyDiscoveryFails() { #expect(throws: TestLaneSelection.SelectionFailure.self) { try TestLaneSelection(manifest: "SafeTests.Geometry", discovered: "") } }
@Test(arguments: ["no such test", "Windows/orders", "^SafeTests.GeometryExtra"]) func focusedFilterCannotBroadenOrSelectZero(pattern: String) { #expect(throws: TestLaneSelection.SelectionFailure.self) { try TestLaneSelection(manifest: "SafeTests.Geometry", discovered: discovery, matching: pattern) } }
@Test func focusedSelectionStillRequiresTheCompleteManifest() { #expect(throws: TestLaneSelection.SelectionFailure.self) { try TestLaneSelection( manifest: "SafeTests.Geometry\nSafeTests.Missing", discovered: discovery, matching: "fits") } }
@Test func focusedFilterNarrowsTheWhitelist() throws { let selection = try TestLaneSelection( manifest: "SafeTests.Geometry\nSafeTests.Parser", discovered: discovery, matching: "fits|Windows") #expect(selection.identifiers == ["SafeTests.Geometry/fits()"]) #expect(selection.suites == ["SafeTests.Geometry"]) let expression = try NSRegularExpression(pattern: selection.filter) for id in discovery.split(separator: "\n").map(String.init) { let matched = expression.firstMatch(in: id, range: NSRange(id.startIndex..., in: id)) != nil #expect(matched == selection.identifiers.contains(id)) } }
@Test func everyDiscoveredTestNeedsExactlyOneLane() throws { let unit = try TestLaneSelection(manifest: "SafeTests.Geometry\nSafeTests.Parser", discovered: discovery) let native = try TestLaneSelection(manifest: "ParcelTestSupport.AppKitTestSuite/Windows", discovered: discovery) try TestLaneSelection.validatePartition([unit, native], discovered: discovery, excluding: []) #expect(throws: TestLaneSelection.SelectionFailure.self) { try TestLaneSelection.validatePartition([unit], discovered: discovery, excluding: []) } #expect(throws: TestLaneSelection.SelectionFailure.self) { try TestLaneSelection.validatePartition([unit, native, unit], discovered: discovery, excluding: []) } try TestLaneSelection.validatePartition( [unit], discovered: discovery, excluding: ["ParcelTestSupport.AppKitTestSuite/"]) }
@Test func topLevelDeclarationsAreSelectedAndRequiredIndividually() throws { let globals = "SafeTests.globalA()\nSafeTests.globalA(value:)\nSafeTests.globalAB()" let manifest = "SafeTests.globalA()\nSafeTests.globalA(value:)" let selection = try TestLaneSelection(manifest: manifest, discovered: globals) #expect(selection.suites.isEmpty) #expect(selection.globalTests == ["SafeTests.globalA()", "SafeTests.globalA(value:)"]) #expect(selection.identifiers.count == 2) let expression = try NSRegularExpression(pattern: selection.filter) for id in TestLaneSelection.discoveredIdentifiers(globals) { let matched = expression.firstMatch(in: id, range: NSRange(id.startIndex..., in: id)) != nil #expect(matched == selection.identifiers.contains(id)) } #expect(throws: TestLaneSelection.SelectionFailure.self) { try TestLaneSelection(manifest: "SafeTests.missing()", discovered: globals) } #expect(throws: TestLaneSelection.SelectionFailure.self) { try TestLaneSelection.validatePartition([selection], discovered: globals, excluding: []) } }
@Test func suiteSelectionCannotSilentlyDropUnclassifiedGlobals() throws { let all = discovery + "\nSafeTests.globalA()" let unit = try TestLaneSelection(manifest: "SafeTests.Geometry\nSafeTests.Parser", discovered: all) let native = try TestLaneSelection(manifest: "ParcelTestSupport.AppKitTestSuite/Windows", discovered: all) #expect(throws: TestLaneSelection.SelectionFailure.self) { try TestLaneSelection.validatePartition([unit, native], discovered: all, excluding: []) } let complete = try TestLaneSelection( manifest: "SafeTests.Geometry\nSafeTests.Parser\nSafeTests.globalA()", discovered: all) try TestLaneSelection.validatePartition([complete, native], discovered: all, excluding: []) }
@Test func focusedGlobalSelectionAcceptsRuntimeIdentitySuffixesWithoutBroadening() throws { let all = discovery + "\nSafeTests.globalA()\nSafeTests.globalA(value:)" let selection = try TestLaneSelection( manifest: "SafeTests.Geometry\nSafeTests.globalA()\nSafeTests.globalA(value:)", discovered: all, matching: #"^SafeTests\.globalA\(\)$"#) #expect(selection.identifiers == ["SafeTests.globalA()"]) let expression = try NSRegularExpression(pattern: selection.filter) for (id, expected) in [ ("SafeTests.globalA()", true), ("SafeTests/globalA()/source.swift:10", true), ("SafeTests.globalA(value:)", false), ("SafeTests.globalAB()", false), ("UnsafeTests.globalA()", false), ("SafeTests.Geometry/fits()", false), ] { let matched = expression.firstMatch(in: id, range: NSRange(id.startIndex..., in: id)) != nil #expect(matched == expected) } }
@Test func containersRequireEveryConcreteNestedSuiteToExecute() throws { let discovery = """ BenchTests.Container/First/one() BenchTests.Container/First/two() BenchTests.Container/Second/Deep/three() """ let selected = try TestLaneSelection(manifest: "BenchTests.Container", discovered: discovery) #expect(selected.suites == ["BenchTests.Container"]) #expect(selected.executionSuites == ["BenchTests.Container/First", "BenchTests.Container/Second/Deep"]) }
@Test func directTestsAndNestedTestsBothRequireExecution() throws { let discovery = "BenchTests.Container/direct()\nBenchTests.Container/Child/nested()" let selected = try TestLaneSelection(manifest: "BenchTests.Container", discovered: discovery) #expect(selected.executionSuites == ["BenchTests.Container", "BenchTests.Container/Child"]) }
@Test func focusedExecutionSuitesExcludeUnselectedChildrenAndGlobalDeclarations() throws { let discovery = """ BenchTests.Container/First/one() BenchTests.Container/Second/two() BenchTests.global() """ let selected = try TestLaneSelection( manifest: "BenchTests.Container\nBenchTests.global()", discovered: discovery, matching: "one|global") #expect(selected.executionSuites == ["BenchTests.Container/First"]) #expect(selected.globalTests == ["BenchTests.global()"]) let global = try TestLaneSelection(manifest: "BenchTests.global()", discovered: discovery) #expect(global.executionSuites.isEmpty) }
@Test func invalidFilterFailsRatherThanFallingBack() { #expect(throws: (any Error).self) { try TestLaneSelection(manifest: "SafeTests.Geometry", discovered: discovery, matching: "[") } }}