Skip to content

Commit

Permalink
Refactor tests to use throw XCTSkip() for non-available APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Naumov committed Dec 29, 2021
1 parent 3ea0d8a commit 91fb3d0
Show file tree
Hide file tree
Showing 46 changed files with 392 additions and 260 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ final class ComposedGestureExampleTests: XCTestCase {
}

func testNotAComposedGestureError() throws {
guard #available(iOS 14.0, *) else { return }
guard #available(iOS 14.0, *) else { throw XCTSkip() }
let sut = TestGestureView1()
let rectangle = try sut.inspect().shape(0)
let tapGesture = try rectangle.gesture(TapGesture.self)
Expand Down
16 changes: 8 additions & 8 deletions Tests/ViewInspectorTests/Gestures/GestureExampleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,35 @@ import Combine
final class GestureExampleTests: XCTestCase {

func testGestureModifier() throws {
guard #available(iOS 14.0, *) else { return }
guard #available(iOS 14.0, *) else { throw XCTSkip() }
let sut = TestGestureView1()
let rectangle = try sut.inspect().shape(0)
XCTAssertNoThrow(try rectangle.gesture(TapGesture.self))
}

func testHighPriorityGestureModifier() throws {
guard #available(iOS 14.0, *) else { return }
guard #available(iOS 14.0, *) else { throw XCTSkip() }
let sut = TestGestureView2()
let rectangle = try sut.inspect().shape(0)
XCTAssertNoThrow(try rectangle.highPriorityGesture(TapGesture.self))
}

func testSimultaneousGestureModifier() throws {
guard #available(iOS 14.0, *) else { return }
guard #available(iOS 14.0, *) else { throw XCTSkip() }
let sut = TestGestureView3()
let rectangle = try sut.inspect().shape(0)
XCTAssertNoThrow(try rectangle.simultaneousGesture(TapGesture.self))
}

func testGestureMask() throws {
guard #available(iOS 14.0, *) else { return }
guard #available(iOS 14.0, *) else { throw XCTSkip() }
let sut = TestGestureView9()
let gesture = try sut.inspect().shape(0).gesture(TapGesture.self)
XCTAssertEqual(try gesture.gestureMask(), .gesture)
}

func testGestureProperties() throws {
guard #available(iOS 14.0, *) else { return }
guard #available(iOS 14.0, *) else { throw XCTSkip() }
let sut = TestGestureView4()
let rectangle = try sut.inspect().shape(0)
let gesture = try rectangle.gesture(DragGesture.self).actualGesture()
Expand All @@ -45,7 +45,7 @@ final class GestureExampleTests: XCTestCase {
}

func testTestGestureUpdating() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
let sut = TestGestureView5()
let exp1 = sut.inspection.inspect { view in
XCTAssertEqual(try view.actualView().isDetectingLongPress, false)
Expand All @@ -67,7 +67,7 @@ final class GestureExampleTests: XCTestCase {
}

func testTestGestureChanged() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
let sut = TestGestureView6()
let exp1 = sut.inspection.inspect { view in
XCTAssertEqual(try view.actualView().totalNumberOfTaps, 0)
Expand All @@ -88,7 +88,7 @@ final class GestureExampleTests: XCTestCase {
}

func testTestGestureEnded() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
let sut = TestGestureView7()
let exp1 = sut.inspection.inspect { view in
XCTAssertEqual(try view.actualView().doneCounting, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class GestureModifierTests: XCTestCase {
}

func testGestureInspectionFailureDueToTypeMismatch() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
let sut = EmptyView()
.gesture(LongPressGesture())
XCTAssertThrows(
Expand All @@ -43,7 +43,7 @@ final class GestureModifierTests: XCTestCase {
}

func testGestureInspectionWithIndex1() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
let sut = EmptyView()
.gesture(DragGesture())
.gesture(LongPressGesture())
Expand All @@ -52,7 +52,7 @@ final class GestureModifierTests: XCTestCase {
}

func testGestureInspectionWithIndex2() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
let sut = EmptyView()
.gesture(DragGesture())
.highPriorityGesture(TapGesture())
Expand All @@ -62,7 +62,7 @@ final class GestureModifierTests: XCTestCase {
}

func testGestureInspectionWithIndexFailureDueToNoModifier() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
let sut = EmptyView()
.gesture(DragGesture())
.gesture(LongPressGesture())
Expand All @@ -72,7 +72,7 @@ final class GestureModifierTests: XCTestCase {
}

func testGestureInspectionWithIndexFailureDueToTypeMismatch() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
let sut = EmptyView()
.gesture(DragGesture())
.gesture(LongPressGesture())
Expand All @@ -91,7 +91,7 @@ final class GestureModifierTests: XCTestCase {
}

func testGestureInspectionWithIndexPathToRoot() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
let sut = EmptyView()
.padding(100)
.gesture(DragGesture())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class HighPriorityGestureModifierTests: XCTestCase {
}

func testHighPriorityGestureInspectionFailureDueToTypeMismatch() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
let sut = EmptyView()
.highPriorityGesture(LongPressGesture())
XCTAssertThrows(
Expand All @@ -46,7 +46,7 @@ final class HighPriorityGestureModifierTests: XCTestCase {
}

func testHighPriorityGestureInspectionWithIndex1() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
let sut = EmptyView()
.highPriorityGesture(DragGesture())
.highPriorityGesture(LongPressGesture())
Expand All @@ -55,7 +55,7 @@ final class HighPriorityGestureModifierTests: XCTestCase {
}

func testHighPriorityGestureInspectionWithIndex2() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
let sut = EmptyView()
.highPriorityGesture(DragGesture())
.gesture(TapGesture())
Expand All @@ -65,7 +65,7 @@ final class HighPriorityGestureModifierTests: XCTestCase {
}

func testHighPriorityGestureInspectionWithIndexFailureDueToNoModifier() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
let sut = EmptyView()
.highPriorityGesture(DragGesture())
.highPriorityGesture(LongPressGesture())
Expand All @@ -75,7 +75,7 @@ final class HighPriorityGestureModifierTests: XCTestCase {
}

func testHighPriorityGestureInspectionWithIndexFailureDueToTypeMismatch() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
let sut = EmptyView()
.highPriorityGesture(DragGesture())
.highPriorityGesture(LongPressGesture())
Expand All @@ -93,7 +93,7 @@ final class HighPriorityGestureModifierTests: XCTestCase {
}

func testHighPriorityGestureInspectionWithIndexPathToRoot() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
let sut = EmptyView()
.padding(100)
.highPriorityGesture(DragGesture())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class SimultaneousGestureModifierTests: XCTestCase {
}

func testSimultaneousGestureInspectionFailureDueToTypeMismatch() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
let sut = EmptyView()
.simultaneousGesture(LongPressGesture())
XCTAssertThrows(
Expand All @@ -46,7 +46,7 @@ final class SimultaneousGestureModifierTests: XCTestCase {
}

func testSimultaneousGestureInspectionWithIndex1() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
let sut = EmptyView()
.simultaneousGesture(DragGesture())
.simultaneousGesture(LongPressGesture())
Expand All @@ -55,7 +55,7 @@ final class SimultaneousGestureModifierTests: XCTestCase {
}

func testSimultaneousGestureInspectionWithIndex2() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
let sut = EmptyView()
.simultaneousGesture(DragGesture())
.gesture(TapGesture())
Expand All @@ -65,7 +65,7 @@ final class SimultaneousGestureModifierTests: XCTestCase {
}

func testSimultaneousGestureInspectionWithIndexFailureDueToNoModifier() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
let sut = EmptyView()
.simultaneousGesture(DragGesture())
.simultaneousGesture(LongPressGesture())
Expand All @@ -75,7 +75,7 @@ final class SimultaneousGestureModifierTests: XCTestCase {
}

func testSimultaneousGestureInspectionWithIndexFailureDueToTypeMismatch() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
let sut = EmptyView()
.simultaneousGesture(DragGesture())
.simultaneousGesture(LongPressGesture())
Expand All @@ -93,7 +93,7 @@ final class SimultaneousGestureModifierTests: XCTestCase {
}

func testSimultaneousGestureInspectionWithIndexPathToRoot() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
let sut = EmptyView()
.padding(100)
.simultaneousGesture(DragGesture())
Expand Down
38 changes: 19 additions & 19 deletions Tests/ViewInspectorTests/Gestures/LongPressGestureTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class LongPressGestureTests: XCTestCase {
}

override func setUpWithError() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
longPressFinished = false
_longPressValue = LongPressGesture.Value(finished: longPressFinished!)

Expand All @@ -40,14 +40,14 @@ final class LongPressGestureTests: XCTestCase {
}

func testCreateLongPressGestureValue() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
XCTAssertNotNil(longPressFinished)
let value = try longPressValue()
assertLongPressValue(value)
}

func testLongPressGestureMask() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
try gestureTests().maskTest()
}

Expand All @@ -62,17 +62,17 @@ final class LongPressGestureTests: XCTestCase {
#endif

func testLongPressGestureWithUpdatingModifier() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
try gestureTests().propertiesWithUpdatingModifierTest()
}

func testLongPressGestureWithOnChangedModifier() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
try gestureTests().propertiesWithOnChangedModifierTest()
}

func testLongPressGestureWithOnEndedModifier() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
try gestureTests().propertiesWithOnEndedModifierTest()
}

Expand All @@ -83,67 +83,67 @@ final class LongPressGestureTests: XCTestCase {
#endif

func testLongPressGestureFailure() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
try gestureTests().propertiesFailureTest("LongPressGesture")
}

func testLongPressGestureCallUpdating() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
try gestureTests().callUpdatingTest()
}

func testLongPressGestureCallUpdatingNotFirst() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
try gestureTests().callUpdatingNotFirstTest()
}

func testLongPressGestureCallUpdatingMultiple() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
try gestureTests().callUpdatingMultipleTest()
}

func testLongPressGestureCallUpdatingFailure() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
try gestureTests().callUpdatingFailureTest()
}

func testLongPressGestureCallOnChanged() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
try gestureTests().callOnChangedTest()
}

func testLongPressGestureCallOnChangedNotFirst() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
try gestureTests().callOnChangedNotFirstTest()
}

func testLongPressGestureCallOnChangedMultiple() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
try gestureTests().callOnChangedMultipleTest()
}

func testLongPressGestureCallOnChangedFailure() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
try gestureTests().callOnChangedFailureTest()
}

func testLongPressGestureCallOnEnded() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
try gestureTests().callOnEndedTest()
}

func testLongPressGestureCallOnEndedNotFirst() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
try gestureTests().callOnEndedNotFirstTest()
}

func testLongPressGestureCallOnEndedMultiple() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
try gestureTests().callOnEndedMultipleTest()
}

func testLongPressGestureCallOnEndedFailure() throws {
guard #available(tvOS 14.0, *) else { return }
guard #available(tvOS 14.0, *) else { throw XCTSkip() }
try gestureTests().callOnEndedFailureTest()
}

Expand Down
3 changes: 2 additions & 1 deletion Tests/ViewInspectorTests/SwiftUI/AlertTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ final class AlertIOS15Tests: XCTestCase {
}

func testAlertInspectioniOS15() throws {
guard #available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) else { return }
guard #available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
else { throw XCTSkip() }
let binding = Binding(wrappedValue: true)
let sut = sutIOS15(binding: binding)
let alert = try sut.inspect().alert()
Expand Down
6 changes: 4 additions & 2 deletions Tests/ViewInspectorTests/SwiftUI/ButtonTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ final class ButtonTests: XCTestCase {
}

func testButtonRole() throws {
guard #available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) else { return }
guard #available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
else { throw XCTSkip() }
let sut1 = Button(role: .cancel, action: { }, label: { Text("") })
let sut2 = Button(role: .destructive, action: { }, label: { Text("") })
let sut3 = Button(action: { }, label: { Text("") })
Expand Down Expand Up @@ -132,7 +133,8 @@ final class ButtonStyleInspectionTests: XCTestCase {

#if !os(tvOS)
func testPrimitiveButtonStyleExtraction() throws {
guard #available(iOS 13.1, macOS 10.16, tvOS 13.1, *) else { return }
guard #available(iOS 13.1, macOS 10.16, tvOS 13.1, *)
else { throw XCTSkip() }
let style = TestPrimitiveButtonStyle()
let button = try style.inspect().group().view(TestPrimitiveButtonStyle.TestButton.self, 0)
XCTAssertNoThrow(try button.anyView().styleConfigurationLabel().blur())
Expand Down
Loading

0 comments on commit 91fb3d0

Please sign in to comment.