Skip to content

Commit

Permalink
Add reconciler stress tests for elaborate testing (#381)
Browse files Browse the repository at this point in the history
Most of the changes are related to the use of OpenCombineShim (available in upstream OpenCombine now) instead of CombineShim. But there is also a new test added during the investigation of #367, where an app is rendered end-to end, which is a good way to expand our test suite I think.

* Use immediate scheduler in TestRenderer

This allows running our test suite on WASI too, which doesn't have Dispatch and also can't wait on XCTest expectations. Previously none of our tests (especially runtime reflection tests) ran on WASI.

* Run `carton test` and `carton bundle` in separate jobs

* Bump year in the `LICENSE` file

* Add reconciler stress tests for elaborate testing

* Move default App implementation to TestRenderer

* Use OpenCombineShim instead of CombineShim
  • Loading branch information
MaxDesiatov committed Jun 15, 2021
1 parent 3302a51 commit ac69bbc
Show file tree
Hide file tree
Showing 29 changed files with 165 additions and 64 deletions.
30 changes: 18 additions & 12 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,14 @@ let package = Package(
// a module or a test suite.
// Targets can depend on other targets in this package, and on products
// in packages which this package depends on.
.target(
name: "CombineShim",
dependencies: [.product(
name: "OpenCombine",
package: "OpenCombine",
condition: .when(platforms: [.wasi, .linux])
)]
),
.target(
name: "TokamakCore",
dependencies: ["CombineShim"]
dependencies: [
.product(
name: "OpenCombineShim",
package: "OpenCombine"
),
]
),
.target(
name: "TokamakShim",
Expand Down Expand Up @@ -105,7 +102,13 @@ let package = Package(
),
.target(
name: "TokamakGTK",
dependencies: ["TokamakCore", "CGTK", "CGDK", "TokamakGTKCHelpers", "CombineShim"]
dependencies: [
"TokamakCore", "CGTK", "CGDK", "TokamakGTKCHelpers",
.product(
name: "OpenCombineShim",
package: "OpenCombine"
),
]
),
.target(
name: "TokamakGTKDemo",
Expand Down Expand Up @@ -135,15 +138,18 @@ let package = Package(
.target(
name: "TokamakDOM",
dependencies: [
"CombineShim",
"OpenCombineJS",
"TokamakCore",
"TokamakStaticHTML",
.product(
name: "OpenCombineShim",
package: "OpenCombine"
),
.product(
name: "JavaScriptKit",
package: "JavaScriptKit",
condition: .when(platforms: [.wasi])
),
"OpenCombineJS",
]
),
.target(
Expand Down
2 changes: 1 addition & 1 deletion Sources/TokamakCore/App/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// Created by Carson Katri on 7/16/20.
//

import CombineShim
import OpenCombineShim

/// Provides the ability to set the title of the Scene.
public protocol _TitledApp {
Expand Down
4 changes: 2 additions & 2 deletions Sources/TokamakCore/App/AppStorage.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Tokamak contributors
// Copyright 2020-2021 Tokamak contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,7 @@
// Created by Carson Katri on 7/16/20.
//

import CombineShim
import OpenCombineShim

@propertyWrapper public struct AppStorage<Value>: DynamicProperty {
let provider: _StorageProvider?
Expand Down
4 changes: 2 additions & 2 deletions Sources/TokamakCore/App/Scenes/SceneStorage.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Tokamak contributors
// Copyright 2020-2021 Tokamak contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,7 @@
// Created by Carson Katri on 7/17/20.
//

import CombineShim
import OpenCombineShim

/// The renderer must specify a default `_StorageProvider` before any `SceneStorage`
/// values are accessed.
Expand Down
4 changes: 2 additions & 2 deletions Sources/TokamakCore/App/_AnyApp.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Tokamak contributors
// Copyright 2020-2021 Tokamak contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,7 @@
// Created by Carson Katri on 7/19/20.
//

import CombineShim
import OpenCombineShim

public struct _AnyApp: App {
var app: Any
Expand Down
4 changes: 2 additions & 2 deletions Sources/TokamakCore/App/_StorageProvider.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Tokamak contributors
// Copyright 2020-2021 Tokamak contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,7 @@
// Created by Carson Katri on 7/22/20.
//

import CombineShim
import OpenCombineShim

public protocol _StorageProvider {
func store(key: String, value: Bool?)
Expand Down
4 changes: 2 additions & 2 deletions Sources/TokamakCore/Environment/EnvironmentObject.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Tokamak contributors
// Copyright 2020-2021 Tokamak contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,7 @@
// Created by Carson Katri on 7/7/20.
//

import CombineShim
import OpenCombineShim

@propertyWrapper public struct EnvironmentObject<ObjectType>: DynamicProperty
where ObjectType: ObservableObject
Expand Down
4 changes: 2 additions & 2 deletions Sources/TokamakCore/Environment/EnvironmentValues.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Tokamak contributors
// Copyright 2020-2021 Tokamak contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import CombineShim
import OpenCombineShim

public struct EnvironmentValues: CustomStringConvertible {
public var description: String {
Expand Down
2 changes: 1 addition & 1 deletion Sources/TokamakCore/MountedViews/MountedApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// Created by Carson Katri on 7/19/20.
//

import CombineShim
import OpenCombineShim

// This is very similar to `MountedCompositeView`. However, the `mountedBody`
// is the computed content of the specified `Scene`, instead of having child
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018-2020 Tokamak contributors
// Copyright 2018-2021 Tokamak contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,7 @@
// Created by Carson Katri on 7/19/20.
//

import CombineShim
import OpenCombineShim

class MountedCompositeElement<R: Renderer>: MountedElement<R> {
let parentTarget: R.TargetType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// Created by Max Desiatov on 03/12/2018.
//

import CombineShim
import OpenCombineShim

final class MountedCompositeView<R: Renderer>: MountedCompositeElement<R> {
override func mount(
Expand Down
3 changes: 1 addition & 2 deletions Sources/TokamakCore/Reflection/Layouts/FieldDescriptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ func _getTypeByMangledNameInContext(
_ nameLength: UInt,
_ genericContext: UnsafeRawPointer?,
_ genericArguments: UnsafeRawPointer?
)
-> Any.Type?
) -> Any.Type?

/// https://github.com/apple/swift/blob/f2c42509628bed66bf5b8ee02fae778a2ba747a1/include/swift/Reflection/Records.h#L160
struct FieldDescriptor {
Expand Down
2 changes: 1 addition & 1 deletion Sources/TokamakCore/StackReconciler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// Created by Max Desiatov on 28/11/2018.
//

import CombineShim
import OpenCombineShim

/** A class that reconciles a "raw" tree of element values (such as `App`, `Scene` and `View`,
all coming from `body` or `renderedBody` properties) with a tree of mounted element instances
Expand Down
8 changes: 4 additions & 4 deletions Sources/TokamakCore/State/ObservedObject.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Tokamak contributors
// Copyright 2020-2021 Tokamak contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import CombineShim
import OpenCombineShim

public typealias ObservableObject = CombineShim.ObservableObject
public typealias Published = CombineShim.Published
public typealias ObservableObject = OpenCombineShim.ObservableObject
public typealias Published = OpenCombineShim.Published

protocol ObservedProperty: DynamicProperty {
var objectWillChange: AnyPublisher<(), Never> { get }
Expand Down
4 changes: 2 additions & 2 deletions Sources/TokamakCore/State/StateObject.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Tokamak contributors
// Copyright 2020-2021 Tokamak contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import CombineShim
import OpenCombineShim

@propertyWrapper
public struct StateObject<ObjectType: ObservableObject>: DynamicProperty {
Expand Down
1 change: 0 additions & 1 deletion Sources/TokamakCore/Views/Containers/List/List+Init.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public extension List {

init<Data, ID, RowContent>(
_ data: Data,

id: KeyPath<Data.Element, ID>,
selection: Binding<Set<SelectionValue>>?,
@ViewBuilder rowContent: @escaping (Data.Element) -> RowContent
Expand Down
4 changes: 2 additions & 2 deletions Sources/TokamakDOM/App/App.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Tokamak contributors
// Copyright 2020-2021 Tokamak contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,8 +15,8 @@
// Created by Carson Katri on 7/16/20.
//

import CombineShim
import JavaScriptKit
import OpenCombineShim
import TokamakCore
import TokamakStaticHTML

Expand Down
4 changes: 2 additions & 2 deletions Sources/TokamakDOM/App/ColorSchemeObserver.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Tokamak contributors
// Copyright 2020-2021 Tokamak contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import CombineShim
import JavaScriptKit
import OpenCombineShim

enum ColorSchemeObserver {
static var publisher = CurrentValueSubject<ColorScheme, Never>(
Expand Down
4 changes: 2 additions & 2 deletions Sources/TokamakDOM/App/ScenePhaseObserver.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Tokamak contributors
// Copyright 2020-2021 Tokamak contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import CombineShim
import JavaScriptKit
import OpenCombineShim

enum ScenePhaseObserver {
static var publisher = CurrentValueSubject<ScenePhase, Never>(.active)
Expand Down
4 changes: 2 additions & 2 deletions Sources/TokamakDOM/Storage/LocalStorage.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Tokamak contributors
// Copyright 2020-2021 Tokamak contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,8 +15,8 @@
// Created by Carson Katri on 7/20/20.
//

import CombineShim
import JavaScriptKit
import OpenCombineShim
import TokamakCore

private let rootPublisher = ObservableObjectPublisher()
Expand Down
4 changes: 2 additions & 2 deletions Sources/TokamakDOM/Storage/SessionStorage.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Tokamak contributors
// Copyright 2020-2021 Tokamak contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,8 +15,8 @@
// Created by Carson Katri on 7/20/20.
//

import CombineShim
import JavaScriptKit
import OpenCombineShim
import TokamakCore

private let sessionStorage = JSObject.global.sessionStorage.object!
Expand Down
4 changes: 2 additions & 2 deletions Sources/TokamakDOM/Storage/WebStorage.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Tokamak contributors
// Copyright 2020-2021 Tokamak contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,8 +15,8 @@
// Created by Carson Katri on 7/21/20.
//

import CombineShim
import JavaScriptKit
import OpenCombineShim
import TokamakCore

protocol WebStorage {
Expand Down
6 changes: 3 additions & 3 deletions Sources/TokamakDemo/ButtonStyleDemo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public struct ButtonStyleDemo: View {
Text("Label").padding(.leading, 5)
}
})
.buttonStyle(
PressedButtonStyle(pressedColor: Color.red)
)
.buttonStyle(
PressedButtonStyle(pressedColor: Color.red)
)
}
}
}
4 changes: 2 additions & 2 deletions Sources/TokamakGTK/App/App.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Tokamak contributors
// Copyright 2020-2021 Tokamak contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -16,8 +16,8 @@
//

import CGTK
import CombineShim
import Dispatch
import OpenCombineShim
import TokamakCore

public extension App {
Expand Down
4 changes: 2 additions & 2 deletions Sources/TokamakStaticHTML/App.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Tokamak contributors
// Copyright 2020-2021 Tokamak contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,7 @@
// Created by Carson Katri on 7/31/20.
//

import CombineShim
import OpenCombineShim
import TokamakCore

public extension App {
Expand Down
Loading

0 comments on commit ac69bbc

Please sign in to comment.