From c3ecd9b35c6b45a02be539e2fd0696323ee43022 Mon Sep 17 00:00:00 2001 From: Sacha DSO Date: Fri, 20 Sep 2024 07:59:38 -1000 Subject: [PATCH] WIP: Fixes unit tests --- Tests/SteviaTests/BaselineTests.swift | 6 +++-- Tests/SteviaTests/CenterTests.swift | 6 ++--- Tests/SteviaTests/ContentTests.swift | 25 +++++++++++---------- Tests/SteviaTests/EquationTests.swift | 6 ++--- Tests/SteviaTests/FillTests.swift | 6 ++--- Tests/SteviaTests/FlexibleMarginTests.swift | 6 ++--- Tests/SteviaTests/FullLayoutTests.swift | 6 ++--- Tests/SteviaTests/GetConstraintsTests.swift | 22 +++++++++--------- Tests/SteviaTests/HierarchyTests.swift | 2 +- Tests/SteviaTests/LayoutTests.swift | 6 ++--- Tests/SteviaTests/PositionTests.swift | 6 ++--- Tests/SteviaTests/SizeTests.swift | 16 ++++++++++--- Tests/SteviaTests/StyleTests.swift | 2 +- 13 files changed, 64 insertions(+), 51 deletions(-) diff --git a/Tests/SteviaTests/BaselineTests.swift b/Tests/SteviaTests/BaselineTests.swift index 1213b921..35c5dcf5 100644 --- a/Tests/SteviaTests/BaselineTests.swift +++ b/Tests/SteviaTests/BaselineTests.swift @@ -9,14 +9,14 @@ import XCTest import Stevia -class BaselineTests: XCTestCase { +@MainActor class BaselineTests: XCTestCase { var win: UIWindow! var ctrler: UIViewController! var label1 = UILabel() var label2 = UILabel() - override func setUp() { + override func setUp() async throws { win = UIWindow(frame: UIScreen.main.bounds) ctrler = UIViewController() win.rootViewController = ctrler @@ -29,6 +29,8 @@ class BaselineTests: XCTestCase { } } + + func testAlignLastBaselines() { label1.top(100) align(lastBaselines: label1, label2) diff --git a/Tests/SteviaTests/CenterTests.swift b/Tests/SteviaTests/CenterTests.swift index cadf6ce4..e08537af 100644 --- a/Tests/SteviaTests/CenterTests.swift +++ b/Tests/SteviaTests/CenterTests.swift @@ -10,14 +10,14 @@ import XCTest let magicalIphoneXShift = 0.17 -class CenterTests: XCTestCase { +@MainActor class CenterTests: XCTestCase { var win: UIWindow! var ctrler: UIViewController! var v: UIView! - override func setUp() { - super.setUp() + override func setUp() async throws { +// try await super.setUp() win = UIWindow(frame: UIScreen.main.bounds) ctrler = UIViewController() win.rootViewController = ctrler diff --git a/Tests/SteviaTests/ContentTests.swift b/Tests/SteviaTests/ContentTests.swift index 5eeb8f4e..aaaebf2b 100644 --- a/Tests/SteviaTests/ContentTests.swift +++ b/Tests/SteviaTests/ContentTests.swift @@ -12,11 +12,11 @@ import Stevia let title = "TitleTest" -class UIButtonContentTests: XCTestCase { +@MainActor class UIButtonContentTests: XCTestCase { var button = UIButton() - override func setUp() { - super.setUp() + override func setUp() async throws { +// button = UIButton() } @@ -41,11 +41,12 @@ class UIButtonContentTests: XCTestCase { } } -class UILabelContentTests: XCTestCase { + +@MainActor class UILabelContentTests: XCTestCase { var label = UILabel() - override func setUp() { - super.setUp() + override func setUp() async throws { +// super.setUp() label = UILabel() } @@ -64,11 +65,11 @@ class UILabelContentTests: XCTestCase { } } -class UITextFieldContentTests: XCTestCase { +@MainActor class UITextFieldContentTests: XCTestCase { var textField = UITextField() - override func setUp() { - super.setUp() + override func setUp() async throws { +// super.setUp() textField = UITextField() } @@ -82,11 +83,11 @@ class UITextFieldContentTests: XCTestCase { } } -class UIImageViewContentTests: XCTestCase { +@MainActor class UIImageViewContentTests: XCTestCase { var imageView = UIImageView() - override func setUp() { - super.setUp() + override func setUp() async throws { +// super.setUp() imageView = UIImageView() } diff --git a/Tests/SteviaTests/EquationTests.swift b/Tests/SteviaTests/EquationTests.swift index 4c67fa67..5c1eff0d 100644 --- a/Tests/SteviaTests/EquationTests.swift +++ b/Tests/SteviaTests/EquationTests.swift @@ -9,13 +9,13 @@ import XCTest import Stevia -class EquationTests: XCTestCase { +@MainActor class EquationTests: XCTestCase { var win: UIWindow! var ctrler: UIViewController! - override func setUp() { - super.setUp() + override func setUp() async throws { +// super.setUp() win = UIWindow(frame: UIScreen.main.bounds) ctrler = UIViewController() win.rootViewController = ctrler diff --git a/Tests/SteviaTests/FillTests.swift b/Tests/SteviaTests/FillTests.swift index ad815411..38311eba 100644 --- a/Tests/SteviaTests/FillTests.swift +++ b/Tests/SteviaTests/FillTests.swift @@ -10,12 +10,12 @@ import XCTest import Stevia -class FillTests: XCTestCase { +@MainActor class FillTests: XCTestCase { var win: UIWindow! var ctrler: UIViewController! - override func setUp() { - super.setUp() + override func setUp() async throws { +// super.setUp() win = UIWindow(frame: UIScreen.main.bounds) ctrler = UIViewController() win.rootViewController = ctrler diff --git a/Tests/SteviaTests/FlexibleMarginTests.swift b/Tests/SteviaTests/FlexibleMarginTests.swift index f3f26842..246a67bd 100644 --- a/Tests/SteviaTests/FlexibleMarginTests.swift +++ b/Tests/SteviaTests/FlexibleMarginTests.swift @@ -9,14 +9,14 @@ import XCTest import Stevia -class FlexibleMarginTests: XCTestCase { +@MainActor class FlexibleMarginTests: XCTestCase { var win: UIWindow! var ctrler: UIViewController! var v: UIView! - override func setUp() { - super.setUp() + override func setUp() async throws { +// super.setUp() win = UIWindow(frame: UIScreen.main.bounds) ctrler = UIViewController() win.rootViewController = ctrler diff --git a/Tests/SteviaTests/FullLayoutTests.swift b/Tests/SteviaTests/FullLayoutTests.swift index 26960413..006e01dd 100644 --- a/Tests/SteviaTests/FullLayoutTests.swift +++ b/Tests/SteviaTests/FullLayoutTests.swift @@ -53,14 +53,14 @@ class TestView: UIView { } } -class FullLayoutTests: XCTestCase { +@MainActor class FullLayoutTests: XCTestCase { var win: UIWindow! var vc: UIViewController! var v: TestView! - override func setUp() { - super.setUp() + override func setUp() async throws { +// super.setUp() win = UIWindow(frame: UIScreen.main.bounds) vc = UIViewController()///TestVC() win.rootViewController = vc diff --git a/Tests/SteviaTests/GetConstraintsTests.swift b/Tests/SteviaTests/GetConstraintsTests.swift index 2a33b2fa..8b594103 100644 --- a/Tests/SteviaTests/GetConstraintsTests.swift +++ b/Tests/SteviaTests/GetConstraintsTests.swift @@ -9,14 +9,14 @@ import XCTest import Stevia -class GetConstraintsTests: XCTestCase { +@MainActor class GetConstraintsTests: XCTestCase { var v: UIView! var spv: UIView! - override func setUp() { - spv = UIView() - v = UIView() + override func setUp() async throws { + spv = await UIView() + v = await UIView() spv.subviews { v! } } @@ -68,7 +68,7 @@ class GetConstraintsTests: XCTestCase { XCTAssertEqual(c?.isActive, true) } - func testCanGetBottomConstraint() { + @MainActor func testCanGetBottomConstraint() { XCTAssertNil(v.bottomConstraint) v.bottom(145) let c = v.bottomConstraint @@ -84,7 +84,7 @@ class GetConstraintsTests: XCTestCase { XCTAssertEqual(c?.isActive, true) } - func testCanGetHeightConstraint() { + @MainActor func testCanGetHeightConstraint() { XCTAssertNil(v.heightConstraint) v.height(35) let c = v.heightConstraint @@ -100,7 +100,7 @@ class GetConstraintsTests: XCTestCase { XCTAssertEqual(c?.isActive, true) } - func testCanGetWidthConstraint() { + @MainActor func testCanGetWidthConstraint() { XCTAssertNil(v.widthConstraint) v.width(51) let c = v.widthConstraint @@ -116,7 +116,7 @@ class GetConstraintsTests: XCTestCase { XCTAssertEqual(c?.isActive, true) } - func testCanGetTrailingConstraint() { + @MainActor func testCanGetTrailingConstraint() { XCTAssertNil(v.trailingConstraint) v.trailingAnchor.constraint(equalTo: spv.trailingAnchor, constant: 104).isActive = true let c = v.trailingConstraint @@ -132,7 +132,7 @@ class GetConstraintsTests: XCTestCase { XCTAssertEqual(c?.isActive, true) } - func testCanGetLeadingonstraint() { + @MainActor func testCanGetLeadingonstraint() { XCTAssertNil(v.leadingConstraint) v.leadingAnchor.constraint(equalTo: spv.leadingAnchor, constant: 73).isActive = true let c = v.leadingConstraint @@ -148,7 +148,7 @@ class GetConstraintsTests: XCTestCase { XCTAssertEqual(c?.isActive, true) } - func testCanGetCenterXConstraint() { + @MainActor func testCanGetCenterXConstraint() { XCTAssertNil(v.centerXConstraint) v.CenterX == spv.CenterX + 27 let c = v.centerXConstraint @@ -164,7 +164,7 @@ class GetConstraintsTests: XCTestCase { XCTAssertEqual(c?.isActive, true) } - func testCanGetCenterYConstraint() { + @MainActor func testCanGetCenterYConstraint() { XCTAssertNil(v.centerYConstraint) v.CenterY == spv.CenterY - 32 let c = v.centerYConstraint diff --git a/Tests/SteviaTests/HierarchyTests.swift b/Tests/SteviaTests/HierarchyTests.swift index 38fbd0fd..db0573e8 100644 --- a/Tests/SteviaTests/HierarchyTests.swift +++ b/Tests/SteviaTests/HierarchyTests.swift @@ -9,7 +9,7 @@ import XCTest import Stevia -class HierarchyTests: XCTestCase { +@MainActor class HierarchyTests: XCTestCase { override func setUp() { super.setUp() diff --git a/Tests/SteviaTests/LayoutTests.swift b/Tests/SteviaTests/LayoutTests.swift index 77a0628f..2a3bf424 100644 --- a/Tests/SteviaTests/LayoutTests.swift +++ b/Tests/SteviaTests/LayoutTests.swift @@ -9,14 +9,14 @@ import XCTest import Stevia -class LayoutTests: XCTestCase { +@MainActor class LayoutTests: XCTestCase { var win: UIWindow! var ctrler: UIViewController! var v: UIView! - override func setUp() { - super.setUp() + override func setUp() async throws { +// super.setUp() win = UIWindow(frame: UIScreen.main.bounds) ctrler = UIViewController() win.rootViewController = ctrler diff --git a/Tests/SteviaTests/PositionTests.swift b/Tests/SteviaTests/PositionTests.swift index e20af419..a98aaf97 100644 --- a/Tests/SteviaTests/PositionTests.swift +++ b/Tests/SteviaTests/PositionTests.swift @@ -9,14 +9,14 @@ import XCTest import Stevia -class PositionTests: XCTestCase { +@MainActor class PositionTests: XCTestCase { var win: UIWindow! var ctrler: UIViewController! var v: UIView! - override func setUp() { - super.setUp() + override func setUp() async throws { +// super.setUp() win = UIWindow(frame: UIScreen.main.bounds) ctrler = UIViewController() win.rootViewController = ctrler diff --git a/Tests/SteviaTests/SizeTests.swift b/Tests/SteviaTests/SizeTests.swift index b1b6fef1..0ad681d0 100644 --- a/Tests/SteviaTests/SizeTests.swift +++ b/Tests/SteviaTests/SizeTests.swift @@ -9,14 +9,24 @@ import XCTest import Stevia -class SizeTests: XCTestCase { +@MainActor class SizeTests: XCTestCase { var win: UIWindow! var ctrler: UIViewController! var v: UIView! - override func setUp() { - super.setUp() + override func setUp() async throws { +// try await super.setUp() + win = UIWindow(frame: UIScreen.main.bounds) + ctrler = UIViewController() + win.rootViewController = ctrler + v = UIView() + ctrler.view.subviews { + v! + } + } + + func uiSetUp() { win = UIWindow(frame: UIScreen.main.bounds) ctrler = UIViewController() win.rootViewController = ctrler diff --git a/Tests/SteviaTests/StyleTests.swift b/Tests/SteviaTests/StyleTests.swift index 326b2ecc..6c7a173a 100644 --- a/Tests/SteviaTests/StyleTests.swift +++ b/Tests/SteviaTests/StyleTests.swift @@ -9,7 +9,7 @@ import XCTest import Stevia -class StyleTests: XCTestCase { +@MainActor class StyleTests: XCTestCase { func styleView(_ view: UIView) { view.backgroundColor = UIColor.yellow