Skip to content

Commit

Permalink
Add Wasm CI. (#219)
Browse files Browse the repository at this point in the history
* Add Wasm CI.

* wip

* wip

* fixes

* wip

* wip

* wip

* move things around

* wip

* fix

* wip

* wip

* wip

* tvos fixes

* fixes

* wip

* wip

* wip

* wip

* Update .github/workflows/ci.yml

Co-authored-by: Stephen Celis <[email protected]>

* wip

* wip

---------

Co-authored-by: Stephen Celis <[email protected]>
  • Loading branch information
mbrandonw and stephencelis authored Sep 3, 2024
1 parent 253847c commit 9a17e1d
Show file tree
Hide file tree
Showing 12 changed files with 207 additions and 174 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,32 @@ jobs:
- name: Run tests
run: make test-${{ matrix.variation }}

wasm:
name: SwiftWasm
runs-on: ubuntu-latest
strategy:
matrix:
include:
- toolchain: swift-DEVELOPMENT-SNAPSHOT-2024-07-08-a
swift-sdk: swift-wasm-DEVELOPMENT-SNAPSHOT-2024-07-09-a
steps:
- uses: actions/checkout@v4
- uses: bytecodealliance/actions/wasmtime/setup@v1
- name: Install Swift and Swift SDK for WebAssembly
run: |
PREFIX=/opt/swift
SWIFT_TOOLCHAIN_TAG="${{ matrix.toolchain }}"
SWIFT_SDK_TAG="${{ matrix.swift-sdk }}"
set -ex
curl -f -o /tmp/swift.tar.gz "https://download.swift.org/development/ubuntu2204/$SWIFT_TOOLCHAIN_TAG/$SWIFT_TOOLCHAIN_TAG-ubuntu22.04.tar.gz"
sudo mkdir -p $PREFIX; sudo tar -xzf /tmp/swift.tar.gz -C $PREFIX --strip-component 1
$PREFIX/usr/bin/swift experimental-sdk install "https://github.com/swiftwasm/swift/releases/download/$SWIFT_SDK_TAG/$SWIFT_SDK_TAG-wasm32-unknown-wasi.artifactbundle.zip"
echo "$PREFIX/usr/bin" >> $GITHUB_PATH
- name: Build tests
run: swift build --swift-sdk wasm32-unknown-wasi --build-tests -Xlinker -z -Xlinker stack-size=$((1024 * 1024))
- name: Run tests
run: wasmtime --dir . .build/debug/swift-navigationPackageTests.wasm

windows:
name: Windows
strategy:
Expand Down
29 changes: 15 additions & 14 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
{
"originHash" : "f10d2f6e9f8c467a6984b87f3aba67d2119452577271115a38ed7d5e7ada2444",
"pins" : [
{
"identity" : "swift-case-paths",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-case-paths",
"state" : {
"revision" : "71344dd930fde41e8f3adafe260adcbb2fc2a3dc",
"version" : "1.5.4"
"revision" : "642e6aab8e03e5f992d9c83e38c5be98cfad5078",
"version" : "1.5.5"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections",
"state" : {
"revision" : "3d2dc41a01f9e49d84f0a3925fb858bed64f702d",
"version" : "1.1.2"
"revision" : "9bf03ff58ce34478e66aaee630e491823326fd06",
"version" : "1.1.3"
}
},
{
Expand All @@ -41,14 +42,14 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/swiftlang/swift-docc-plugin",
"state" : {
"revision" : "26ac5758409154cc448d7ab82389c520fa8a8247",
"version" : "1.3.0"
"revision" : "2eb22993b3dfd0c0d32729b357c8dabb6cd44680",
"version" : "1.4.2"
}
},
{
"identity" : "swift-docc-symbolkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-docc-symbolkit",
"location" : "https://github.com/swiftlang/swift-docc-symbolkit",
"state" : {
"revision" : "b45d1f2ed151d057b54504d653e0da5552844e34",
"version" : "1.0.0"
Expand All @@ -59,28 +60,28 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-perception",
"state" : {
"revision" : "1552c8f722ac256cc0b8daaf1a7073217d4fcdfb",
"version" : "1.3.4"
"revision" : "bc67aa8e461351c97282c2419153757a446ae1c9",
"version" : "1.3.5"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swiftlang/swift-syntax",
"state" : {
"revision" : "06b5cdc432e93b60e3bdf53aff2857c6b312991a",
"version" : "600.0.0-prerelease-2024-07-30"
"revision" : "515f79b522918f83483068d99c68daeb5116342d",
"version" : "600.0.0-prerelease-2024-08-20"
}
},
{
"identity" : "xctest-dynamic-overlay",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
"state" : {
"revision" : "357ca1e5dd31f613a1d43320870ebc219386a495",
"version" : "1.2.2"
"revision" : "96beb108a57f24c8476ae1f309239270772b2940",
"version" : "1.2.5"
}
}
],
"version" : 2
"version" : 3
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#if canImport(SwiftUI) && canImport(Testing)
#if canImport(Testing)
import CustomDump
import SwiftUI
import SwiftUINavigation
import SwiftNavigation
import Testing

struct ButtonStateTests {
Expand Down Expand Up @@ -31,4 +30,4 @@
}
}
}
#endif // canImport(SwiftUI)
#endif
52 changes: 28 additions & 24 deletions Tests/SwiftNavigationTests/IsolationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,38 @@
import XCTest

class IsolationTests: XCTestCase {
@MainActor
func testIsolationOnMinActor() async {
let model = MainActorModel()
let expectation = expectation(description: "observation")
expectation.expectedFulfillmentCount = 2
let token = SwiftNavigation.observe {
_ = model.count
MainActor.assertIsolated()
expectation.fulfill()
func testIsolationOnMainActor() async throws {
try await Task { @MainActor in
let model = MainActorModel()
var didObserve = false
let token = SwiftNavigation.observe {
_ = model.count
MainActor.assertIsolated()
didObserve = true
}
model.count += 1
try await Task.sleep(nanoseconds: 300_000_000)
XCTAssertEqual(didObserve, true)
_ = token
}
model.count += 1
await fulfillment(of: [expectation], timeout: 1)
_ = token
.value
}

@GlobalActorIsolated
func testIsolationOnGlobalActor() async {
let model = GlobalActorModel()
let expectation = expectation(description: "observation")
expectation.expectedFulfillmentCount = 2
let token = SwiftNavigation.observe {
_ = model.count
GlobalActorIsolated.assertIsolated()
expectation.fulfill()
func testIsolationOnGlobalActor() async throws {
try await Task { @GlobalActorIsolated in
let model = GlobalActorModel()
var didObserve = false
let token = SwiftNavigation.observe {
_ = model.count
GlobalActorIsolated.assertIsolated()
didObserve = true
}
model.count += 1
try await Task.sleep(nanoseconds: 300_000_000)
XCTAssertEqual(didObserve, true)
_ = token
}
model.count += 1
await fulfillment(of: [expectation], timeout: 1)
_ = token
.value
}
}

Expand Down
36 changes: 19 additions & 17 deletions Tests/SwiftNavigationTests/LifetimeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,29 @@
import XCTest

final class LifetimeTests: XCTestCase {
@MainActor
func testObserveToken() async {
let model = Model()
var counts = [Int]()
var token: ObserveToken?
do {
token = SwiftNavigation.observe {
counts.append(model.count)
await Task { @MainActor in
let model = Model()
var counts = [Int]()
var token: ObserveToken?
do {
token = SwiftNavigation.observe {
counts.append(model.count)
}
}
}
XCTAssertEqual(counts, [0])
model.count += 1
await Task.yield()
XCTAssertEqual(counts, [0, 1])
XCTAssertEqual(counts, [0])
model.count += 1
await Task.yield()
XCTAssertEqual(counts, [0, 1])

_ = token
token = nil
_ = token
token = nil

model.count += 1
await Task.yield()
XCTAssertEqual(counts, [0, 1])
model.count += 1
await Task.yield()
XCTAssertEqual(counts, [0, 1])
}
.value
}
}

Expand Down
40 changes: 23 additions & 17 deletions Tests/SwiftNavigationTests/ObserveTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,32 @@ import XCTest

class ObserveTests: XCTestCase {
#if swift(>=6)
@MainActor
func testIsolation() {
var count = 0
let token = SwiftNavigation.observe {
count = 1
func testIsolation() async {
await MainActor.run {
var count = 0
let token = SwiftNavigation.observe {
count = 1
}
XCTAssertEqual(count, 1)
_ = token
}
XCTAssertEqual(count, 1)
_ = token
}
#endif

@MainActor
func testTokenStorage() {
var count = 0
observe {
count += 1
}
observe {
count += 1
#if !os(WASI)
@MainActor
func testTokenStorage() async {
var count = 0
var tokens: Set<ObserveToken> = []
observe {
count += 1
}
.store(in: &tokens)
observe {
count += 1
}
.store(in: &tokens)
XCTAssertEqual(count, 2)
}
XCTAssertEqual(count, 2)
}
#endif
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#if canImport(SwiftUI)
import CustomDump
import SwiftUINavigation
import XCTest
import CustomDump
import SwiftNavigation
import XCTest

final class TextStateTests: XCTestCase {
final class TextStateTests: XCTestCase {
#if !os(WASI)
func testTextState() {
var dump = ""
customDump(TextState("Hello, world!"), to: &dump)
Expand Down Expand Up @@ -72,5 +72,5 @@
"""#
)
}
}
#endif // canImport(SwiftUI)
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ private final class Model {
}

final class UIBindableTests: XCTestCase {
@MainActor
func testDynamicMemberLookupBindable() throws {
func testDynamicMemberLookupBindable() {
@UIBindable var model = Model()
let textBinding = $model.text
XCTAssert(type(of: textBinding) == UIBinding<String>.self)
Expand All @@ -24,8 +23,7 @@ final class UIBindableTests: XCTestCase {
XCTAssertEqual(textBinding.wrappedValue, "Blob, Jr.")
}

@MainActor
func testEquatableHashable() throws {
func testEquatableHashable() {
let model = Model()
@UIBindable var model1 = model
@UIBindable var model2 = model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import SwiftNavigation
import XCTest

final class UIBindingTests: XCTestCase {
@MainActor
func testInitProjectedValue() throws {
func testInitProjectedValue() {
@UIBinding var text = ""
let textBinding = UIBinding(projectedValue: $text)

Expand All @@ -16,7 +15,6 @@ final class UIBindingTests: XCTestCase {
XCTAssertEqual(textBinding.wrappedValue, "Blob, Jr.")
}

@MainActor
func testOperationFromOptional() throws {
@UIBinding var count: Int? = nil

Expand Down Expand Up @@ -48,7 +46,6 @@ final class UIBindingTests: XCTestCase {
XCTAssertEqual(unwrappedCountBinding.wrappedValue, 1729)
}

@MainActor
func testOperationToOptional() {
@UIBinding var count = 0

Expand All @@ -67,7 +64,6 @@ final class UIBindingTests: XCTestCase {
XCTAssertEqual(optionalCountBinding.wrappedValue, 2)
}

// @MainActor
// func testOperationToAnyHashable() {
// @UIBinding var count = 0
//
Expand All @@ -84,7 +80,6 @@ final class UIBindingTests: XCTestCase {
// XCTAssertEqual(optionalCountBinding.wrappedValue, 2)
// }

@MainActor
func testOperationConstant() {
@UIBinding var count: Int
_count = .constant(0)
Expand All @@ -93,7 +88,6 @@ final class UIBindingTests: XCTestCase {
XCTAssertEqual(count, 0)
}

@MainActor
func testDynamicMemberLookupProperty() {
struct User {
var name = ""
Expand All @@ -111,7 +105,6 @@ final class UIBindingTests: XCTestCase {
XCTAssertEqual(nameBinding.wrappedValue, "Blob, Jr.")
}

@MainActor
func testDynamicMemberLookupCase() throws {
struct Failure: Error, Equatable {}

Expand Down Expand Up @@ -144,7 +137,6 @@ final class UIBindingTests: XCTestCase {
XCTAssertEqual(countBinding.wrappedValue, 1729)
}

@MainActor
func testDynamicMemberLookupOptionalEnumCase() throws {
struct Failure: Error, Equatable {}

Expand Down
Loading

0 comments on commit 9a17e1d

Please sign in to comment.